在SQLite3场景下,Sync不支持Modify Column:Error: near MODIFY: syntax error #2267

Merged
lunny merged 17 commits from brookechen/xorm:master into master 2023-07-11 17:10:40 +00:00
Contributor

rebase

rebase
brookechen added 4 commits 2023-05-19 08:45:39 +00:00
AutoIncrement列带ID插入数据时没有Commit
业务场景中,需要预留(1 ~ 100)的ID给系统规则使用。所以会先使用插入将AutoIncrement列的id偏移到一个特定的值(如:100),然后“带ID调用Insert插入系统规则”。 当带ID插入时,由于没有commit,会被rollback掉。
Some checks failed
continuous-integration/drone/pr Build is failing
95356ac403
format.
All checks were successful
continuous-integration/drone/pr Build is passing
bbc89e7511
format
Some checks failed
continuous-integration/drone/pr Build is failing
58c7a413a0
brookechen added 1 commit 2023-05-19 08:45:45 +00:00
Merge branch 'master' into master
Some checks failed
continuous-integration/drone/pr Build is failing
7b68be0cc3
brookechen added 1 commit 2023-05-19 09:37:36 +00:00
提交注释
All checks were successful
continuous-integration/drone/pr Build is passing
46928a07ba
brookechen changed title from master to 在SQLite3场景下,Sync不支持Modify Column:Error: near MODIFY: syntax error 2023-05-19 09:39:31 +00:00
lunny added 1 commit 2023-05-25 10:49:23 +00:00
Merge branch 'master' into master
Some checks failed
test mysql8 / test mysql8 (pull_request) Successful in 5m10s
test sqlite / unit test & test sqlite (pull_request) Successful in 8m56s
test tidb / test tidb (pull_request) Successful in 4m52s
test cockroach / test cockroach (pull_request) Failing after 5m4s
test mssql / test mssql (pull_request) Successful in 5m55s
test mysql / test mysql (pull_request) Successful in 4m35s
test mariadb / test mariadb (pull_request) Successful in 4m38s
test postgres / test postgres (pull_request) Successful in 4m4s
42bb41f142
brookechen added 1 commit 2023-05-30 02:59:04 +00:00
Merge branch 'master' into master
Some checks failed
test mysql / test mysql (pull_request) Successful in 4m50s
test sqlite / unit test & test sqlite (pull_request) Successful in 8m56s
test mysql8 / test mysql8 (pull_request) Successful in 5m8s
test mssql / test mssql (pull_request) Successful in 5m45s
test postgres / test postgres (pull_request) Successful in 5m18s
test tidb / test tidb (pull_request) Has been cancelled
test cockroach / test cockroach (pull_request) Has been cancelled
test mariadb / test mariadb (pull_request) Has been cancelled
b330b1c715
Owner

Could you give some tests?

Could you give some tests?
brookechen added 1 commit 2023-06-02 01:51:05 +00:00
Merge branch 'master' into master
All checks were successful
test mysql / test mysql (pull_request) Successful in 6m6s
test postgres / test postgres (pull_request) Successful in 7m5s
test mariadb / test mariadb (pull_request) Successful in 6m7s
test sqlite / unit test & test sqlite (pull_request) Successful in 11m5s
test mssql / test mssql (pull_request) Successful in 7m20s
test mysql8 / test mysql8 (pull_request) Successful in 6m8s
test tidb / test tidb (pull_request) Successful in 7m39s
test cockroach / test cockroach (pull_request) Successful in 15m13s
926f7f90b8
brookechen added 1 commit 2023-06-02 02:07:56 +00:00
add modify column comment testcase
Some checks failed
test mariadb / test mariadb (pull_request) Successful in 6m0s
test sqlite / unit test & test sqlite (pull_request) Successful in 10m44s
test mssql / test mssql (pull_request) Successful in 7m9s
test mysql / test mysql (pull_request) Successful in 6m4s
test mysql8 / test mysql8 (pull_request) Successful in 6m22s
test postgres / test postgres (pull_request) Successful in 6m57s
test tidb / test tidb (pull_request) Successful in 3m38s
test cockroach / test cockroach (pull_request) Failing after 6m12s
1eed9610ae
Author
Contributor

Could you give some tests?

实际这是一个功能缺失导致的bug。
目前xorm的Dialect实现中,只有postgres.ModifyColumnSQL实现了修改comment能力。

这个用例在非 postgres上执行时,只能验证多次Sync时,不出错误。而在sqlite3上,原有版本会出现如下错误:

[xorm] [info]  2023/06/02 10:10:46.059528 [SQL] SELECT sql FROM sqlite_master WHERE type='table' and name = ? [test_comment_struct] - 9.208µs
[xorm] [info]  2023/06/02 10:10:46.059581 [SQL] SELECT sql FROM sqlite_master WHERE type='index' and tbl_name = ? [test_comment_struct] - 7.25µs
[xorm] [info]  2023/06/02 10:10:46.059615 [SQL] ALTER TABLE `test_comment_struct` MODIFY COLUMN `has_comment` INTEGER NULL [] - 13.834µs
    engine_test.go:311: 
        	Error Trace:	engine_test.go:311
        	Error:      	Received unexpected error:
        	            	near "MODIFY": syntax error
        	Test:       	TestColumnCommentUpdate
    engine_test.go:316: 
--- FAIL: TestColumnCommentUpdate (0.00s)

> Could you give some tests? 实际这是一个功能缺失导致的bug。 目前xorm的`Dialect`实现中,只有`postgres.ModifyColumnSQL`实现了修改comment能力。 这个用例在非 postgres上执行时,只能验证多次Sync时,不出错误。而在sqlite3上,原有版本会出现如下错误: ``` [xorm] [info] 2023/06/02 10:10:46.059528 [SQL] SELECT sql FROM sqlite_master WHERE type='table' and name = ? [test_comment_struct] - 9.208µs [xorm] [info] 2023/06/02 10:10:46.059581 [SQL] SELECT sql FROM sqlite_master WHERE type='index' and tbl_name = ? [test_comment_struct] - 7.25µs [xorm] [info] 2023/06/02 10:10:46.059615 [SQL] ALTER TABLE `test_comment_struct` MODIFY COLUMN `has_comment` INTEGER NULL [] - 13.834µs engine_test.go:311: Error Trace: engine_test.go:311 Error: Received unexpected error: near "MODIFY": syntax error Test: TestColumnCommentUpdate engine_test.go:316: --- FAIL: TestColumnCommentUpdate (0.00s) ```
brookechen changed title from 在SQLite3场景下,Sync不支持Modify Column:Error: near MODIFY: syntax error to WIP: 在SQLite3场景下,Sync不支持Modify Column:Error: near MODIFY: syntax error 2023-06-02 02:12:23 +00:00
brookechen changed title from WIP: 在SQLite3场景下,Sync不支持Modify Column:Error: near MODIFY: syntax error to 在SQLite3场景下,Sync不支持Modify Column:Error: near MODIFY: syntax error 2023-06-02 02:12:39 +00:00
brookechen added 4 commits 2023-07-10 12:04:39 +00:00
Merge branch 'xorm-master'
Some checks failed
test mariadb / test mariadb (pull_request) Failing after 5m54s
test cockroach / test cockroach (pull_request) Failing after 6m30s
test mssql / test mssql (pull_request) Failing after 4m22s
test mysql / test mysql (pull_request) Failing after 4m27s
test mysql8 / test mysql8 (pull_request) Failing after 4m22s
test postgres / test postgres (pull_request) Failing after 4m13s
test sqlite / unit test & test sqlite (pull_request) Failing after 3m55s
test tidb / test tidb (pull_request) Failing after 4m5s
a678ef1c27
brookechen added 1 commit 2023-07-10 12:07:24 +00:00
merge origin master
Some checks failed
test mariadb / test mariadb (pull_request) Successful in 5m58s
test mssql / test mssql (pull_request) Successful in 5m48s
test mysql / test mysql (pull_request) Successful in 11m18s
test cockroach / test cockroach (pull_request) Failing after 25m58s
test mysql8 / test mysql8 (pull_request) Successful in 4m20s
test postgres / test postgres (pull_request) Successful in 4m46s
test tidb / test tidb (pull_request) Successful in 4m32s
test sqlite / unit test & test sqlite (pull_request) Successful in 7m16s
0b9bf4f167
Owner

I think both MySQL and postgres supports change the comment? Maybe you need to add MySQL too.

I think both MySQL and postgres supports change the comment? Maybe you need to add MySQL too.
brookechen added 1 commit 2023-07-11 08:43:04 +00:00
cockroach db create table with integer column but get from db is bigint
All checks were successful
test cockroach / test cockroach (pull_request) Successful in 5m12s
test mariadb / test mariadb (pull_request) Successful in 5m10s
test mssql / test mssql (pull_request) Successful in 6m31s
test mysql / test mysql (pull_request) Successful in 5m2s
test mysql8 / test mysql8 (pull_request) Successful in 5m12s
test postgres / test postgres (pull_request) Successful in 5m43s
test sqlite / unit test & test sqlite (pull_request) Successful in 8m27s
test tidb / test tidb (pull_request) Successful in 5m21s
604489eb38
brookechen added 1 commit 2023-07-11 09:18:49 +00:00
mysql alter column comment ready.
All checks were successful
test cockroach / test cockroach (pull_request) Successful in 4m32s
test mariadb / test mariadb (pull_request) Successful in 4m48s
test mssql / test mssql (pull_request) Successful in 5m47s
test mysql / test mysql (pull_request) Successful in 4m37s
test mysql8 / test mysql8 (pull_request) Successful in 4m54s
test postgres / test postgres (pull_request) Successful in 5m25s
test tidb / test tidb (pull_request) Successful in 5m20s
test sqlite / unit test & test sqlite (pull_request) Successful in 8m26s
a019b1ea33
Author
Contributor

I think both MySQL and postgres supports change the comment? Maybe you need to add MySQL too.

原来的mysql dialect 逻辑不支持 alter column comment 的,现在我加上了,请 CR

> I think both MySQL and postgres supports change the comment? Maybe you need to add MySQL too. 原来的mysql dialect 逻辑不支持 alter column comment 的,现在我加上了,请 CR
Author
Contributor

另外,发现个问题:数据库为cockroach时, 当 struct column 类型为 int 时,create 语句时是设置的 has_comment 列为 INTEGER 类型,但是再查询时,列类型为 BIGINT,导致用例失败,因此先将用例中 has_comment 列设置为 bigint。cockroach 的数据类型问题另外跟进。

相关 sql 如下:

CREATE TABLE IF NOT EXISTS "public"."test_comment_struct" ("has_comment" INTEGER NULL); COMMENT ON COLUMN "public"."test_comment_struct"."has_comment" IS 'this is a comment before update'; [] - 23.943542ms

SELECT column_name, column_default, is_nullable, data_type, character_maximum_length, description,
CASE WHEN p.contype = 'p' THEN true ELSE false END AS primarykey,
CASE WHEN p.contype = 'u' THEN true ELSE false END AS uniquekey
FROM pg_attribute f
JOIN pg_class c ON c.oid = f.attrelid JOIN pg_type t ON t.oid = f.atttypid
LEFT JOIN pg_attrdef d ON d.adrelid = c.oid AND d.adnum = f.attnum
LEFT JOIN pg_description de ON f.attrelid=de.objoid AND f.attnum=de.objsubid
LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
LEFT JOIN pg_constraint p ON p.conrelid = c.oid AND f.attnum = ANY (p.conkey)
LEFT JOIN pg_class AS g ON p.confrelid = g.oid
LEFT JOIN INFORMATION_SCHEMA.COLUMNS s ON s.column_name=f.attname AND c.relname=s.table_name
WHERE n.nspname= s.table_schema AND c.relkind = 'r' AND c.relname = $1 AND s.table_schema = $2 AND f.attnum > 0 ORDER BY f.attnum; [test_comment_struct public]

另外,发现个问题:数据库为cockroach时, 当 struct column 类型为 int 时,create 语句时是设置的 has_comment 列为 INTEGER 类型,但是再查询时,列类型为 BIGINT,导致用例失败,因此先将用例中 has_comment 列设置为 bigint。cockroach 的数据类型问题另外跟进。 相关 sql 如下: CREATE TABLE IF NOT EXISTS "public"."test_comment_struct" ("has_comment" INTEGER NULL); COMMENT ON COLUMN "public"."test_comment_struct"."has_comment" IS 'this is a comment before update'; [] - 23.943542ms SELECT column_name, column_default, is_nullable, data_type, character_maximum_length, description, CASE WHEN p.contype = 'p' THEN true ELSE false END AS primarykey, CASE WHEN p.contype = 'u' THEN true ELSE false END AS uniquekey FROM pg_attribute f JOIN pg_class c ON c.oid = f.attrelid JOIN pg_type t ON t.oid = f.atttypid LEFT JOIN pg_attrdef d ON d.adrelid = c.oid AND d.adnum = f.attnum LEFT JOIN pg_description de ON f.attrelid=de.objoid AND f.attnum=de.objsubid LEFT JOIN pg_namespace n ON n.oid = c.relnamespace LEFT JOIN pg_constraint p ON p.conrelid = c.oid AND f.attnum = ANY (p.conkey) LEFT JOIN pg_class AS g ON p.confrelid = g.oid LEFT JOIN INFORMATION_SCHEMA.COLUMNS s ON s.column_name=f.attname AND c.relname=s.table_name WHERE n.nspname= s.table_schema AND c.relkind = 'r' AND c.relname = $1 AND s.table_schema = $2 AND f.attnum > 0 ORDER BY f.attnum; [test_comment_struct public]
lunny added the
kind
bug
label 2023-07-11 09:54:46 +00:00
lunny approved these changes 2023-07-11 17:09:56 +00:00
lunny merged commit 486c344ba3 into master 2023-07-11 17:10:40 +00:00
lunny added this to the 1.3.3 milestone 2023-07-26 01:30:30 +00:00
Sign in to join this conversation.
No description provided.