Commit Graph

1700 Commits

Author SHA1 Message Date
Andrew Thornton 67b5c85f85
disable conds/exprs in upsert
Signed-off-by: Andrew Thornton <art27@cantab.net>
2023-03-15 17:30:37 +00:00
Andrew Thornton d7eb965a92
handle weird update n by mysql
Signed-off-by: Andrew Thornton <art27@cantab.net>
2023-03-15 13:56:37 +00:00
Andrew Thornton 344985f6bd
adjust name
Signed-off-by: Andrew Thornton <art27@cantab.net>
2023-03-15 12:55:45 +00:00
Andrew Thornton 2715e0de59
add tests for map
Signed-off-by: Andrew Thornton <art27@cantab.net>
2023-03-15 12:26:47 +00:00
Andrew Thornton 625167ded5
More cleanly handle primary keys as unique constraints
Signed-off-by: Andrew Thornton <art27@cantab.net>
2023-03-15 11:47:44 +00:00
Andrew Thornton 4bf706dd0c
allow upsert on primary key
Signed-off-by: Andrew Thornton <art27@cantab.net>
2023-03-14 22:52:53 +00:00
Andrew Thornton 4bf7c4d738
fix tidb
Signed-off-by: Andrew Thornton <art27@cantab.net>
2023-03-14 21:03:48 +00:00
Andrew Thornton b4467b717a
Try getting the LastInsertID before the rows affected
Signed-off-by: Andrew Thornton <art27@cantab.net>
2023-03-14 16:48:54 +00:00
Andrew Thornton 5a188e58d1
oops
Signed-off-by: Andrew Thornton <art27@cantab.net>
2023-03-13 20:24:07 +00:00
Andrew Thornton e88ca1d017
only permit upsert if there is only one unique constraint
Signed-off-by: Andrew Thornton <art27@cantab.net>
2023-03-13 18:42:34 +00:00
Andrew Thornton 5b92ebc141
fix postgres
Signed-off-by: Andrew Thornton <art27@cantab.net>
2023-03-13 12:59:19 +00:00
Andrew Thornton 1e50bd8705
more test changes
Signed-off-by: Andrew Thornton <art27@cantab.net>
2023-03-13 11:03:02 +00:00
Andrew Thornton 3708430ebf
slight adjustment
Signed-off-by: Andrew Thornton <art27@cantab.net>
2023-03-13 10:44:56 +00:00
Andrew Thornton c7802f9737
fix mssql
Signed-off-by: Andrew Thornton <art27@cantab.net>
2023-03-13 10:30:03 +00:00
Andrew Thornton 643636c3b8
add an upsert test and fix mysql
Signed-off-by: Andrew Thornton <art27@cantab.net>
2023-03-13 09:35:33 +00:00
Andrew Thornton 9dafb36a44
no returning on sqlite
Signed-off-by: Andrew Thornton <art27@cantab.net>
2023-03-13 06:44:23 +00:00
Andrew Thornton c55adf1c26
mostly complete
Signed-off-by: Andrew Thornton <art27@cantab.net>
2023-03-13 06:34:31 +00:00
Andrew Thornton 3a4fbeaa6f
Add InsertOnConflictDoNothing and Upsert functionality
This PR adds functionality for xorm to perform InsertOnConflictDoNothing
and Upserts.

Signed-off-by: Andrew Thornton <art27@cantab.net>
2023-03-12 22:14:44 +00:00
datbeohbbh d485abba57 add `(*Engine) SetConnMaxIdleTime` (#2229)
issue: https://gitea.com/xorm/xorm/issues/2228
Co-authored-by: datbeohbbh <phongtomfapp@gmail.com>
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2229
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: datbeohbbh <datbeohbbh@noreply.gitea.io>
Co-committed-by: datbeohbbh <datbeohbbh@noreply.gitea.io>
2023-03-06 18:55:33 +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
KN4CK3R 056cecc97e Add `Truncate` method (#2220)
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>
2023-02-20 07:17:35 +08:00
datbeohbbh 52855dae32 update go version to v1.17 in .drone.yml (#2219)
issue: #2218
Co-authored-by: datbeohbbh <phongtomfapp@gmail.com>
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2219
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: datbeohbbh <datbeohbbh@noreply.gitea.io>
Co-committed-by: datbeohbbh <datbeohbbh@noreply.gitea.io>
2023-02-12 11:16:53 +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
datbeohbbh 7dc2a18876 Bug fix: `Rows` must be closed after used (#2214)
Issue: [#2213](https://gitea.com/xorm/xorm/issues/2213#issue-132724)
Co-authored-by: datbeohbbh <phongtomfapp@gmail.com>
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2214
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: datbeohbbh <datbeohbbh@noreply.gitea.io>
Co-committed-by: datbeohbbh <datbeohbbh@noreply.gitea.io>
2023-02-03 17:24:16 +08:00
tamalsaha 5fafa00043 fix: Correctly parse jsonb column tag (#2206)
Signed-off-by: Tamal Saha <tamal@appscode.com>
Co-authored-by: Tamal Saha <tamal@appscode.com>
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2206
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: tamalsaha <tamalsaha@noreply.gitea.io>
Co-committed-by: tamalsaha <tamalsaha@noreply.gitea.io>
2023-01-09 13:19: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
Lunny Xiao f1bfc5ce98 join support condition (#2201)
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2201
2022-12-09 23:37:26 +08:00
tylerthail2019 71a5939c65 add disable version check func (#2197)
Co-authored-by: tyler <tylerthail@gmail.com>
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2197
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: tylerthail2019 <tylerthail2019@noreply.gitea.io>
Co-committed-by: tylerthail2019 <tylerthail2019@noreply.gitea.io>
2022-11-16 13:22:04 +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
Lunny Xiao bd58520020
add changelog for 1.3.2 2022-09-03 15:14:19 +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 f469d88166
Update changelog for 1.3.1 2022-06-03 17:44:49 +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
Andrew Thornton 60540cbabe Remove const insertSelectPlaceholder and associated dead code (#2151)
`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>
2022-05-30 00:29:03 +08:00
Andrew Thornton 26d291bbc3 Add interface to allow structs to provide specific index information (#2137)
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>
2022-04-24 19:34:27 +08:00
Lunny Xiao f7e9fb74ac return a clear error for set TEXT type as compare condition (#2062)
Fix #523

Reviewed-on: https://gitea.com/xorm/xorm/pulls/2062
2022-04-23 17:19:37 +08:00
Lunny Xiao 2c064b6da6 Add test for find date (#2121)
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2121
2022-04-22 14:56:26 +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
Lunny Xiao 8f2596bf64 some improvement (#2136)
Fix #2134 and replace #2135

Reviewed-on: https://gitea.com/xorm/xorm/pulls/2136
2022-04-22 10:16:35 +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
Lunny Xiao e858b75756
Update changelog for 1.3.0 2022-04-14 10:12:39 +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
finelog d195040cb9 fix session context overwrite when logSessionId not set (#2115)
ref pr https://gitea.com/xorm/xorm/pulls/2053

i think the previous fix has some issue
for example, i'm using session like this:

```go
// logSessionID == false
engine := NewEngine()

// use ctx.SessionId to distinguish uniq request id
cxt := context.WithValue(parent, log.SessionIDKey, "some unique request id")
session := engine.NewSession().Context(ctx)
```
however, with pr 2053, `session.Context` can't get SessionId from ctx.

this pr fix abrove issue, overwrite `session.Context()` only when `engine.logSessionID  == true`

please check it out,thanks!

Co-authored-by: finelog <kaicltw@gmail.com>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2115
Co-authored-by: finelog <finelog@noreply.gitea.io>
Co-committed-by: finelog <finelog@noreply.gitea.io>
2022-03-31 17:20:29 +08:00
Pierre-Louis Bonicoli 79a21b68aa replace GitHub links: xorm has been moved to gitea.com (#2126)
Co-authored-by: Pierre-Louis Bonicoli <pierre-louis.bonicoli@libregerbil.fr>
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2126
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-03-31 14:26:05 +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
finelog 7802393d01 fix reset colmap when counting distinct cols (#2096)
when using distinct cols with FindAndCount, reset statement.ColumnMap will make the counting sql an syntax error, this pr try fix this.
is this pr ok for merge?

error sql logging:
```sql
[SQL] SELECT DISTINCT `Fid` FROM `table_demo` WHERE Fkey = ? [val]

[SQL] SELECT count(DISTINCT ) FROM `table_demo` WHERE Fkey = ? [val]
```

after fix:
```sql
[SQL] SELECT DISTINCT `Fid` FROM `table_demo` WHERE Fkey = ? [val]

[SQL] SELECT count(DISTINCT `Fid`) FROM `table_demo` WHERE Fkey = ? [val]
```

Co-authored-by: finelog <kaicltw@gmail.com>
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2096
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: finelog <finelog@noreply.gitea.io>
Co-committed-by: finelog <finelog@noreply.gitea.io>
2022-01-25 11:09:41 +08:00
appleboy e4e830bc78 chore(lint): remove revive and misspell command from makefile (#2088)
replace revive and misspell with golangci lint

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>

Co-authored-by: Bo-Yi Wu <appleboy.tw@gmail.com>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2088
Co-authored-by: appleboy <appleboy.tw@gmail.com>
Co-committed-by: appleboy <appleboy.tw@gmail.com>
2022-01-16 19:04:15 +08:00