Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sql: ban multiple ON CONFLICT REPLACE
Ban an opportunity for user to create table with multiple constraints with ON CONFLICT REPLACE option. For #2963
- Loading branch information
1 parent
583865b
commit 11bed56
Showing
4 changed files
with
140 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#!/usr/bin/env tarantool | ||
-- In SQLite multiple ON CONFLICT REPLACE were allowed in CREATE TABLE statement. | ||
-- However, we decided that we should have only one constraint with ON CONFLICT | ||
-- REPLACE action. This tests check that proper error message will be raised | ||
-- if user makes multiple columns with ON CONFLICT REPLACE. | ||
|
||
test = require("sqltester") | ||
test:plan(5) | ||
|
||
test:do_execsql_test( | ||
"replace-1.1", | ||
[[ | ||
CREATE TABLE t1(a INT PRIMARY KEY, | ||
b INT UNIQUE ON CONFLICT REPLACE, | ||
c INT UNIQUE | ||
); | ||
]], { | ||
|
||
}) | ||
|
||
test:do_catchsql_test( | ||
"replace-1.2", | ||
[[ | ||
DROP TABLE IF EXISTS t1; | ||
CREATE TABLE t1(a INT PRIMARY KEY, | ||
b INT UNIQUE ON CONFLICT REPLACE, | ||
c INT UNIQUE ON CONFLICT REPLACE | ||
); | ||
]], { | ||
1, "in table T1 - only one ON CONFLICT REPLACE is allowed" | ||
}) | ||
|
||
test:do_catchsql_test( | ||
"replace-1.3", | ||
[[ | ||
DROP TABLE IF EXISTS t1; | ||
CREATE TABLE t1(a INT PRIMARY KEY, | ||
b INT UNIQUE ON CONFLICT REPLACE, | ||
c INT NOT NULL ON CONFLICT REPLACE | ||
); | ||
]], { | ||
1, "in table T1 - only one ON CONFLICT REPLACE is allowed" | ||
}) | ||
|
||
test:do_catchsql_test( | ||
"replace-1.4", | ||
[[ | ||
DROP TABLE IF EXISTS t1; | ||
CREATE TABLE t1(a INT PRIMARY KEY, | ||
b INT NOT NULL ON CONFLICT REPLACE, | ||
c INT UNIQUE ON CONFLICT REPLACE | ||
); | ||
]], { | ||
1, "in table T1 - only one ON CONFLICT REPLACE is allowed" | ||
}) | ||
|
||
test:do_catchsql_test( | ||
"replace-1.5", | ||
[[ | ||
DROP TABLE IF EXISTS t1; | ||
CREATE TABLE t1(a INT PRIMARY KEY, | ||
b INT NOT NULL ON CONFLICT REPLACE, | ||
c INT NOT NULL ON CONFLICT REPLACE | ||
); | ||
]], { | ||
1, "in table T1 - only one ON CONFLICT REPLACE is allowed" | ||
}) | ||
|
||
test:finish_test() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
-- gh-2963 - this test is a part of that ticket | ||
-- The purpose is to ban an opportunity for user to create table with multiple | ||
-- ON CONFLICT clauses for columns, user should be able to point it only to one | ||
-- column. This test checks it. | ||
test_run = require('test_run').new() | ||
--- | ||
... | ||
box.sql.execute('CREATE TABLE t1(a INT PRIMARY KEY, b INT UNIQUE ON CONFLICT REPLACE, c UNIQUE)') | ||
--- | ||
... | ||
box.sql.execute('CREATE TABLE t2(a INT PRIMARY KEY, b INT UNIQUE ON CONFLICT REPLACE, c UNIQUE ON CONFLICT REPLACE)') | ||
--- | ||
- error: in table T2 - only one ON CONFLICT REPLACE is allowed | ||
... | ||
box.sql.execute('DROP TABLE t1') | ||
--- | ||
... | ||
box.sql.execute('DROP TABLE t2') | ||
--- | ||
- error: 'no such table: T2' | ||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
-- gh-2963 - this test is a part of that ticket | ||
-- The purpose is to ban an opportunity for user to create table with multiple | ||
-- ON CONFLICT clauses for columns, user should be able to point it only to one | ||
-- column. This test checks it. | ||
|
||
test_run = require('test_run').new() | ||
|
||
box.sql.execute('CREATE TABLE t1(a INT PRIMARY KEY, b INT UNIQUE ON CONFLICT REPLACE, c UNIQUE)') | ||
|
||
box.sql.execute('CREATE TABLE t2(a INT PRIMARY KEY, b INT UNIQUE ON CONFLICT REPLACE, c UNIQUE ON CONFLICT REPLACE)') | ||
|
||
box.sql.execute('DROP TABLE t1') | ||
box.sql.execute('DROP TABLE t2') |