## `loadTableInfo` add context parameter
### Main change
```diff
+++ func (engine *Engine) loadTableInfo(ctx context.Context, table *schemas.Table) error
--- func (engine *Engine) loadTableInfo(table *schemas.Table) error
```
### Situation
After #2200, I built custom dialect to control the SQL. I find that everything else is fine, except when the `SYNC` method executes with an exception.
The reason is that the `loadTableInfo` method calls the `GetIndexes` and `GetColumns` methods with the dialect during execution. **The context passed to these two methods are all `engine.defaultContext` not the current session's context.** So, I think the `loadTableInfo` method should add the context parameter to ensure that the correct context is used during execution.
### Review Note
1. dialect's `GetColumns` and `GetIndexes` methods are **only** used here, if the context here is incorrect, then the context parameter is invalid.
2. `loadTableInfo` method is only used in `SYNC` and `DBMetas` methods, `SYNC` should pass the session's context, while `DBMetas` has no problem passing `engine.defaultContext`.
All in all, I think this change should not affect other function.
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2297
Co-authored-by: LinkinStars <linkinstar@foxmail.com>
Co-committed-by: LinkinStars <linkinstar@foxmail.com>
```diff
// Filter is an interface to filter SQL
type Filter interface {
--- Do(sql string) string
+++ Do(ctx context.Context, sql string) string
}
```
### Adds a `Context` parameter to the `Do` method of the Filter interface.
Developers can rewrite SQL through the `Filter` `Do` method and **need to get the necessary data from the Context** to assist.
For example, get user information through `Context`, so that different users can use different tables. Another example is to get the flags through `Context` to add annotations to the SQL, and use the annotations to let the subsequent `DB-Proxy` to achieve read/write separation.
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2270
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: LinkinStars <linkinstar@foxmail.com>
Co-committed-by: LinkinStars <linkinstar@foxmail.com>
The image has already specified the entrypoint so we don't need to call `/cockroach/cockroach` in `cmd`.

Reviewed-on: https://gitea.com/xorm/xorm/pulls/2269
Co-authored-by: Zettat123 <zettat123@gmail.com>
Co-committed-by: Zettat123 <zettat123@gmail.com>
- Fixed quotes on drop table SQL statement.
- Implemented IsSequenceExists function for oracle dialect.
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2265
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: Martin Viggiano <martinvigg@gmail.com>
Co-committed-by: Martin Viggiano <martinvigg@gmail.com>
This pr fixes a bug caused when a timestmap in TZ format with milliseconds (`2023-04-05T15:50:48.256816Z` or `2023-04-05T15:50:48.256816+08:00`) is being parsed.
- The bug is happens in the function `String2Time` in `convert/time.go`
- if the timestamp contains milliseconds a layout with the structure `2006-01-02 15:04:05.` is used to parse it
- This layout contains an space between the date and the hour, if the timestamp returned by the db contains a `T` the parser fails and an error is returned
This pr adds a check for the `T` and milliseconds in the timestamp, if both conditions are present the date is parsed using the RFC3339 layout
Added test cases to check timestamps in this format
Solves [#2244](https://gitea.com/xorm/xorm/issues/2244)
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2246
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: Alberto Garcia <agarcia@circutor.com>
Co-committed-by: Alberto Garcia <agarcia@circutor.com>
This PR adds a `Truncate` method which allows to delete all existing rows in a table. The current `Delete` implementation enforces conditions to prevent accidental data deletion.
Co-authored-by: KN4CK3R <admin@oldschoolhack.me>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2220
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: KN4CK3R <kn4ck3r@noreply.gitea.io>
Co-committed-by: KN4CK3R <kn4ck3r@noreply.gitea.io>
When dropping indexes in Postgres if the index is non-regular we
should not attempt to regularise the index name as it is already correct.
Signed-off-by: Andrew Thornton <art27@cantab.net>
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2174
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: Andrew Thornton <art27@cantab.net>
Co-committed-by: Andrew Thornton <art27@cantab.net>
`insertSelectPlaceholder` is an unexported const set at true. No code changes this nor can any build environment change it.
Therefore we should remove it and the associated dead code.
Close#2146
Signed-off-by: Andrew Thornton <art27@cantab.net>
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2151
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: Andrew Thornton <art27@cantab.net>
Co-committed-by: Andrew Thornton <art27@cantab.net>
The current mechanism for adding information about indices cannot express the ordering
of the columns in the index or add sorting information.
Here we add a new interface TableIndices which a struct would implement to provide
a slice of *schema.Index to provide additional indices to that gleaned from the tags.
Signed-off-by: Andrew Thornton <art27@cantab.net>
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2137
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: Andrew Thornton <art27@cantab.net>
Co-committed-by: Andrew Thornton <art27@cantab.net>