## Background
Currently, XORM does not yet support the [GBase 8s database by Nanda General Data Technology]. GBase 8s is a widely used domestic database in China, commonly adopted by enterprises and government systems as a backend storage solution.
## Summary of This Contribution
• Added support for the gbase8s driver
• Implemented a basic database dialect: GBase8sDialect
## Usage Instructions
```go
import _ "gitee.com/GBase8s/go-gci""
engine, err := xorm.NewEngine("gbase8s", "gbase8s://username:pwd@ip:port/dbname?param=xxx")
Co-authored-by: zhangyunfei <zhangyunfei@gbase.cn>
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2517
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: maktub <maktub@noreply.gitea.com>
Co-committed-by: maktub <maktub@noreply.gitea.com>
Fix the issue of incorrect insertion of data in non-UTC time zone zero for numeric types
Co-authored-by: CyJay <cyjay@MacBook-Pro.lan>
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2413
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: CyJaySong <CyJaySong@gmail.com>
Co-committed-by: CyJaySong <CyJaySong@gmail.com>
Function can now be passed in to allow customisation to the open database.
For example, with the Oracle database driver `sijms/go-ora` one may want to do the following:
```go
engine, err := xorm.NewEngine("oracle", connectionString, func(db *sql.DB) error {
return oracle.AddSessionParam(db, "NLS_TIMESTAMP_FORMAT", "RR-MM-DD HH24:MI:SS")
})
```
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2369
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: James Marino <james@marino.io>
Co-committed-by: James Marino <james@marino.io>
## `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>
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>
dumpTables currently badly handles BLOB and TEXT data containing control
characters:
* MySQL will interpret and unescape string literals e.g.`\r` will become
carriage return.
* Postgres will not allow string literals to contain NUL nor will
SQLite so BLOBs will not dump correctly.
* Schemas should not be set on the destination dump
* MSSQL needs the N prefix to correctly ensure that UTF-8 data is
correctly transferred.
Signed-off-by: Andrew Thornton <art27@cantab.net>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2091
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: Andrew Thornton <art27@cantab.net>
Co-committed-by: Andrew Thornton <art27@cantab.net>
When dumping booleans these need to be converted from the original DB representation
to the new db representation. In the case of most DBs this is simply to 0 or 1 but
for postgres these have to be false or true.
Signed-off-by: Andrew Thornton <art27@cantab.net>
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2089
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: Andrew Thornton <art27@cantab.net>
Co-committed-by: Andrew Thornton <art27@cantab.net>
Now the below behaviours are allowed.
```Go
var id int64
var name string
has, err := engine.Table(&user).Cols("id", "name").Get(&id, &name)
// SELECT id, name FROM user LIMIT 1
```
```Go
rows, err := engine.Cols("name", "age").Rows(&User{Name:name})
// SELECT * FROM user
defer rows.Close()
for rows.Next() {
var name string
var age int
err = rows.Scan(&name, &age)
}
```
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2029
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-committed-by: Lunny Xiao <xiaolunwen@gmail.com>
Now `Datetime` support `Datime(6)` to indicate the time scale. For different database , the max scale is not different.
`Datetime` means `Datetime(0)`.
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2021
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-committed-by: Lunny Xiao <xiaolunwen@gmail.com>
Now you can use delete like this:
```
orm.Table("my_table").Where("id=?",1).Delete()
```
Reviewed-on: https://gitea.com/xorm/xorm/pulls/1926
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-committed-by: Lunny Xiao <xiaolunwen@gmail.com>
Byte strings in postgres are actually E'\x...' not 0x...
This is part of the follow-up to #1872
Signed-off-by: Andrew Thornton <art27@cantab.net>
Reviewed-on: https://gitea.com/xorm/xorm/pulls/1906
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: Andrew Thornton <art27@cantab.net>
Co-committed-by: Andrew Thornton <art27@cantab.net>
Ensure that structs, arrays and slices are properly converted to strings.
Signed-off-by: Andrew Thornton <art27@cantab.net>
Reviewed-on: https://gitea.com/xorm/xorm/pulls/1905
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: Andrew Thornton <art27@cantab.net>
Co-committed-by: Andrew Thornton <art27@cantab.net>
There are two issues with #1872 which have become apparent
after testing on Gitea.
1. Ensure structs which are have before processors run correctly
2. Ensure structs extending other structs work
3. Ensure that numerical enums become numeric
Signed-off-by: Andrew Thornton <art27@cantab.net>
Reviewed-on: https://gitea.com/xorm/xorm/pulls/1903
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: Andrew Thornton <art27@cantab.net>
Co-committed-by: Andrew Thornton <art27@cantab.net>
When using dumptables to convert between dialects if a struct is provided we should use it to generate the SQL types rather than infer them by mapping from the sql types.
Signed-off-by: Andrew Thornton <art27@cantab.net>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Reviewed-on: https://gitea.com/xorm/xorm/pulls/1872
Co-authored-by: Andrew Thornton <art27@cantab.net>
Co-committed-by: Andrew Thornton <art27@cantab.net>
#1864 Export tag identifier so we can change that form `xorm` to others
This will be useful when in some migration scenarios such as migrate `sqlx` to `xorm`, the former uses `db` as the identifier and has a very simple rule which can be covered by xorm parser rules
Co-authored-by: clannadxr <clannadxr@hotmail.com>
Reviewed-on: https://gitea.com/xorm/xorm/pulls/1865
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: clannadxr <clannadxr@noreply.gitea.io>
Co-committed-by: clannadxr <clannadxr@noreply.gitea.io>
Merge branch 'master' into logger-priority
Merge branch 'master' into logger-priority
Merge branch 'master' into logger-priority
Merge branch 'master' into logger-priority
put ContextLogger in higher priority
SetLogger use `Logger` when give a interface which implements both
ContextLogger and Logger. Because Go's type `switch` uses prior `case`.
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: MURAOKA Taro <koron.kaoriya@gmail.com>
Reviewed-on: https://gitea.com/xorm/xorm/pulls/1656