Commit Graph

110 Commits

Author SHA1 Message Date
Lunny Xiao 2a4161d7a5 Fix mssql get indexes bug when collation is not default with collation test for mssql (#2387)
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2387
2023-12-31 14:07:15 +00:00
Lunny Xiao a4f9c21c17 Some refactors (#2361)
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2361
2023-10-28 11:59:16 +00:00
Lunny Xiao 4cde28ca21 Use any instead of interface{} (#2360)
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2360
2023-10-28 10:59:32 +00:00
Lunny Xiao 607f715634 Move convert internal (#2355)
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2355
2023-10-28 03:30:11 +00:00
Lunny Xiao af9edecff1 Move core internal (#2354)
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2354
2023-10-27 16:27:33 +00:00
Lunny Xiao 82faf6c301 start v2 (#2350)
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2350
2023-10-27 14:27:46 +00:00
Lunny Xiao 05a8643056 Remove mymysql driver since it's unmaintained for a long time (#2349)
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2349
2023-10-27 09:21:35 +00:00
lng2020 dbe499091a Revert "Fix deleted tag attribute zeroTime is not DatabaseTZ (#2299)" (#2341)
Related #2339

Reviewed-on: https://gitea.com/xorm/xorm/pulls/2341
Co-authored-by: lng2020 <nanguanlin6@gmail.com>
Co-committed-by: lng2020 <nanguanlin6@gmail.com>
2023-10-17 09:41:42 +00:00
zzdboy 3eda0f7805 fix KingbaseES version (#2335)
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2335
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: zzdboy <28206697@qq.com>
Co-committed-by: zzdboy <28206697@qq.com>
2023-09-24 03:52:50 +00:00
FlyingOnion 551de3767c modify limit offset implement (#2188)
Oracle and SQLServer specific: When `LIMIT OFFSET` function is needed, use `OFFSET <offset> ROWS FETCH NEXT <limit> ROWS ONLY` to replace legacy subquery.

SQLServer specific: When `ORDER BY` is not set and `OFFSET FETCH` is set, set `statement.orderStr` to `1` (`ORDER BY 1`). See [here](https://learn.microsoft.com/zh-cn/sql/t-sql/queries/select-order-by-clause-transact-sql?view=sql-server-ver16).

MySQL specific: When limit is 0 and offset > 0, use `LIMIT 9223372036854775807` ($2^{63}-1$). See comments [here](15d171ea55/internal/statements/query.go (L314)).

Reviewed-on: https://gitea.com/xorm/xorm/pulls/2188
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: FlyingOnion <731677080@qq.com>
Co-committed-by: FlyingOnion <731677080@qq.com>
2023-09-20 02:07:03 +00:00
Ryan Liu ac88a5705a fix the error in mysql: unknown colType UNSIGNED FLOAT (#2143)
Error: unknown colType UNSIGNED FLOAT
in mysql 5.6.27 or 5.7.32

Fix #2123

Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2143
Co-authored-by: Ryan Liu <azhai@126.com>
Co-committed-by: Ryan Liu <azhai@126.com>
2023-09-16 15:43:12 +00:00
zzdboy 2885c88b77 fix PostgreSQL version (#2332)
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2332
Co-authored-by: zzdboy <28206697@qq.com>
Co-committed-by: zzdboy <28206697@qq.com>
2023-09-16 13:49:19 +00:00
CyJaySong 94882e39df Fix deleted tag attribute zeroTime is not DatabaseTZ (#2299)
Co-authored-by: CyJay <cyjay@MacBook-Pro.lan>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2299
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: CyJaySong <CyJaySong@gmail.com>
Co-committed-by: CyJaySong <CyJaySong@gmail.com>
2023-08-07 04:28:55 +00:00
takumin 1572367155 Add dialects/time_test.go (#2169)
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2169
Co-authored-by: takumin <takumiiinn@gmail.com>
Co-committed-by: takumin <takumiiinn@gmail.com>
2023-07-26 00:57:40 +00:00
Lunny Xiao f33221df74 Fix question mark replacement on postgres (#2202)
Fix #2112

Reviewed-on: https://gitea.com/xorm/xorm/pulls/2202
2023-07-12 13:22:32 +00:00
martinvigg 55d9407390 mysql: add CHAIN, RANK to reserved word list (#2282)
Reference: https://dev.mysql.com/doc/refman/8.0/en/keywords.html
Co-authored-by: Martin Viggiano <martin.viggiano@stonebranch.com>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2282
Co-authored-by: martinvigg <martinvigg@noreply.gitea.com>
Co-committed-by: martinvigg <martinvigg@noreply.gitea.com>
2023-07-12 08:52:23 +00:00
Lunny Xiao f1f5e7cd1a Some refactor (#2292)
replace #2285

Reviewed-on: https://gitea.com/xorm/xorm/pulls/2292
2023-07-12 07:53:25 +00:00
brookechen 486c344ba3 In SQLite3, Sync doesn't support Modify Column:Error: near MODIFY: syntax error (#2267)
rebase

Co-authored-by: brookechen <brookechen@noreply.gitea.io>
Co-authored-by: brookechen <brookechen@tencent.com>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2267
Co-authored-by: brookechen <brookechen@noreply.gitea.com>
Co-committed-by: brookechen <brookechen@noreply.gitea.com>
2023-07-11 17:10:36 +00:00
flyingpigge 52b01ce67f chore: ignore unnecessary char type cast in GetColumns (#2278)
PostgreSQL有两种char类型:`character`和`"char"`: https://www.postgresql.org/docs/current/datatype-character.html.

`pg_class`里的`relkind`是`"char"`类型,所以`GetColumns`这里应该转成`::"char"`或者和本PR里请求的一样去掉转换。这样对于PostgreSQL以及其他兼容PostgreSQL的数据库容错性更好,在做比较时它们通常都会被隐式转换。
```sql
postgres=# select pg_typeof(relkind), pg_typeof('a'::char), pg_typeof('a'::"char") from pg_class limit 1;
 pg_typeof | pg_typeof | pg_typeof
-----------+-----------+-----------
 "char"    | character | "char"
(1 row)
```

Co-authored-by: August <pin@singularity-data.com>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2278
Co-authored-by: flyingpigge <flyingpigge@noreply.gitea.com>
Co-committed-by: flyingpigge <flyingpigge@noreply.gitea.com>
2023-07-03 09:15:45 +00:00
Lunny Xiao d29fe49933 Mysql support a new tag Collate (#2283)
Fix #237
Fix #2179

Reviewed-on: https://gitea.com/xorm/xorm/pulls/2283
2023-07-01 03:40:09 +00:00
Lunny Xiao caa8a029c6 some optimzation (#2272)
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2272
2023-06-02 14:16:30 +00:00
LinkinStars cb851a2f95 Filter support passing context (#2200) (#2270)
```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>
2023-05-31 01:43:24 +00:00
Martin Viggiano e6907e9a62 oracle: Fix quotes on DropTableSQL function, add IsSequenceExist function. (#2265)
- 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>
2023-05-17 09:04:00 +08:00
fanshengshuai 914f2db9ea mysql字段为UNSIGNED时,会导致字段类型无法识别,返回RawBytes,JSON 字段映射为String (#2225)
如题

Reviewed-on: https://gitea.com/xorm/xorm/pulls/2225
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: fanshengshuai <fanshengshuai@noreply.gitea.io>
Co-committed-by: fanshengshuai <fanshengshuai@noreply.gitea.io>
2023-02-28 23:42:42 +08:00
jamlacey 0c9963c637 Add support for go-ora driver (#2215)
Co-authored-by: James Lacey <jamlacey@gmail.com>
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2215
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: jamlacey <jamlacey@noreply.gitea.io>
Co-committed-by: jamlacey <jamlacey@noreply.gitea.io>
2023-02-04 21:24:29 +08:00
Dmitry Narizhnykh 71270edfcc add delimiters between COMMENT ON COLUMN... for Postgres (#2156)
Fix bug: CreateTableSQL func generates invalid SQL without ";" delimiters.

Reviewed-on: https://gitea.com/xorm/xorm/pulls/2156
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: Dmitry Narizhnykh <slotix@noreply.gitea.io>
Co-committed-by: Dmitry Narizhnykh <slotix@noreply.gitea.io>
2022-12-12 18:35:40 +08:00
stevefan1999 3acabdaf26 Fix Oracle Table creation default value (#2190)
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2190
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: stevefan1999 <stevefan1999@noreply.gitea.io>
Co-committed-by: stevefan1999 <stevefan1999@noreply.gitea.io>
2022-10-24 11:29:54 +08:00
Andrew Thornton c900ecc87f Prevent Sync failure with non-regular indexes on Postgres (#2174)
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>
2022-09-03 10:12:17 +08:00
Andrew Thornton c3bce55620 Change schemas.Column to use int64 (#2160)
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2160
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: Andrew Thornton <art27@cantab.net>
Co-committed-by: Andrew Thornton <art27@cantab.net>
2022-07-14 13:55:24 +08:00
Lunny Xiao c98930f8f2 Fix oid index for postgres (#2154)
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2154
2022-06-03 15:24:24 +08:00
Lunny Xiao f9a6990ecb Refactor orderby and support arguments (#2150)
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2150
2022-05-31 11:00:28 +08:00
Andrew Thornton eeb7fcf22c Add ORDER BY SEQ_IN_INDEX to MySQL GetIndexes to Fix IndexTests (#2152)
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2152
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: Andrew Thornton <art27@cantab.net>
Co-committed-by: Andrew Thornton <art27@cantab.net>
2022-05-30 18:36:23 +08:00
Pierre-Louis Bonicoli e1d4365667 MySQL/MariaDB: return max length for text columns (#2133)
MySQL/MariaDB: return max length for text columns using `CHARACTER_MAXIMUM_LENGTH`.

 Tests:
 * add an integration test: `TestGetColumnsLength`
 * update `TestSyncTable3` since `TableInfo` isn't able to provide the column size

Co-authored-by: Pierre-Louis Bonicoli <pierre-louis.bonicoli@libregerbil.fr>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2133
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: Pierre-Louis Bonicoli <pilou@noreply.gitea.io>
Co-committed-by: Pierre-Louis Bonicoli <pilou@noreply.gitea.io>
2022-04-22 10:48:53 +08:00
Pierre-Louis Bonicoli ea9bba0d14 PostgreSQL: enable comment on column (#2131)
The [oldest unsupported version documentation](https://www.postgresql.org/docs/7.1/sql-comment.html) states that comment on a column is supported.

Update `TestGetColumnsComment` in order to check both MySQL/MariaDB and PostgreSQL.

Co-authored-by: Pierre-Louis Bonicoli <pierre-louis.bonicoli@libregerbil.fr>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2131
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: Pierre-Louis Bonicoli <pilou@noreply.gitea.io>
Co-committed-by: Pierre-Louis Bonicoli <pilou@noreply.gitea.io>
2022-04-17 18:03:29 +08:00
getsu b3f9c53d8a oracle数据库不再拼接AS (#2109)
修复 #2108

Co-authored-by: chendy <acrhwfy@gmail.com>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2109
Co-authored-by: getsu <getsu@noreply.gitea.io>
Co-committed-by: getsu <getsu@noreply.gitea.io>
2022-03-31 23:57:40 +08:00
fuge 3180c418c2 bugfix :Oid It's a special index. You can't put it in (#2105)
Co-authored-by: fuge <8342337@qq.com>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2105
Co-authored-by: fuge <fuge@noreply.gitea.io>
Co-committed-by: fuge <fuge@noreply.gitea.io>
2022-01-25 13:28:46 +08:00
Lunny Xiao a2d3669edf Add README and fix some lints (#2079)
as title.

Reviewed-on: https://gitea.com/xorm/xorm/pulls/2079
2021-12-14 09:00:35 +08:00
fanybook aea91cc7de add table & column comment for postgres(add table comment for mysql) (#2067)
让 postgres 支持字段注释,只在 v1.2.5 上测试过(不知道怎么 import master)

发现 master 分支好像大改了?模式表名带 schema 了

使用方式和 mysql 相同
```go
	type User struct {
		Id int64	`xorm:"pk autoincr"`
		Name string `json:"name" xorm:"not null default '' varchar(50) index(name_age) comment('用户 (it''s) 1; 名')"`
		Salt string
		Age int		`json:"age" xorm:"not null default 0 int(10) index(name_age) comment('年龄')"`
		Passwd string `xorm:"varchar(200)"`
		CreatedAt time.Time `xorm:"created"`
		UpdatedAt time.Time `xorm:"updated"`
	}

	_ = engine.Sync(new(User))

    func (model User) TableComment() string {
    	return "表注释"
    }
```

Co-authored-by: fanybook <fanybook@gmail.com>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2067
Co-authored-by: fanybook <fanybook@noreply.gitea.io>
Co-committed-by: fanybook <fanybook@noreply.gitea.io>
2021-11-12 20:58:05 +08:00
Lunny Xiao b350c289f8 Fix missing quote on modifycolumnSQL (#2058)
Fix #2054

Reviewed-on: https://gitea.com/xorm/xorm/pulls/2058
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-committed-by: Lunny Xiao <xiaolunwen@gmail.com>
2021-09-29 20:07:55 +08:00
Lunny Xiao bd5cd8cab7 Fix bug of dameng scan (#2056)
Fix #2055

Reviewed-on: https://gitea.com/xorm/xorm/pulls/2056
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-committed-by: Lunny Xiao <xiaolunwen@gmail.com>
2021-09-24 21:45:47 +08:00
Lunny Xiao c29b9649a9 Add dameng support (#2007)
driver: https://gitee.com/travelliu/dm
docker: https://download.dameng.com/eco/dm8/dm8_docker.tar

fix #1837

Reviewed-on: https://gitea.com/xorm/xorm/pulls/2007
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-committed-by: Lunny Xiao <xiaolunwen@gmail.com>
2021-08-24 13:46:08 +08:00
Lunny Xiao 7d458b4fcf refactor create table for postgres (#2034)
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2034
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-committed-by: Lunny Xiao <xiaolunwen@gmail.com>
2021-08-14 10:57:47 +08:00
Lunny Xiao 0b3cc25a10 Add pgx driver support (#1795)
Fix #858

Reviewed-on: https://gitea.com/xorm/xorm/pulls/1795
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-committed-by: Lunny Xiao <xiaolunwen@gmail.com>
2021-08-05 14:04:11 +08:00
Lunny Xiao 42c2f158e8 Fix timesatmp (#2021)
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>
2021-08-04 16:12:10 +08:00
Lunny Xiao 4383669bcd Fix DBMetas returned unsigned tinyint (#2017)
Fix #2011

Reviewed-on: https://gitea.com/xorm/xorm/pulls/2017
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-committed-by: Lunny Xiao <xiaolunwen@gmail.com>
2021-07-29 11:04:43 +08:00
Lunny Xiao c02a1bf00c Fix postgres driver datasource name parse (#2012)
Fix #2010

Reviewed-on: https://gitea.com/xorm/xorm/pulls/2012
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-committed-by: Lunny Xiao <xiaolunwen@gmail.com>
2021-07-28 10:03:09 +08:00
Andrew Thornton ad4830f531 Remove default length of 50 for Blob (#1959)
There is an odd inconsistency with default blob sizes - this PR only sets the
default size for bytea and binary.

Signed-off-by: Andrew Thornton <art27@cantab.net>

Reviewed-on: https://gitea.com/xorm/xorm/pulls/1959
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: Andrew Thornton <art27@cantab.net>
Co-committed-by: Andrew Thornton <art27@cantab.net>
2021-07-23 08:59:53 +08:00
Lunny Xiao e323971011 refactor some code (#2000)
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2000
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-committed-by: Lunny Xiao <xiaolunwen@gmail.com>
2021-07-21 00:12:20 +08:00
Lunny Xiao a7e010df2d refactor insert condition generation (#1998)
Reviewed-on: https://gitea.com/xorm/xorm/pulls/1998
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-committed-by: Lunny Xiao <xiaolunwen@gmail.com>
2021-07-20 13:46:24 +08:00
Lunny Xiao 86775af2ec refactor and add setjson function (#1997)
Fix #1992

Reviewed-on: https://gitea.com/xorm/xorm/pulls/1997
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-committed-by: Lunny Xiao <xiaolunwen@gmail.com>
2021-07-19 13:43:53 +08:00