* [tarantool-patches] [PATCH] sql: disallow specifying ID in <DEFAULT> clause
@ 2018-09-19 16:20 Nikita Pettik
2018-10-02 7:17 ` [tarantool-patches] " Kirill Yukhin
0 siblings, 1 reply; 2+ messages in thread
From: Nikita Pettik @ 2018-09-19 16:20 UTC (permalink / raw)
To: tarantool-patches; +Cc: kyukhin, Nikita Pettik
Each column may feature default value, but this value must be constant.
Before this patch, it was allowed to do things like:
CREATE TABLE te14 (s1 INT PRIMARY KEY, s2 INT DEFAULT s1);
Which results in assertion fault on insertion. Lets prohibit IDs
(i.e. columns' names) in <DEFAULT> clause.
Closes #3695
---
Branch: https://github.com/tarantool/tarantool/tree/np/gh-3695-disallow-ID-be-default
Issue: https://github.com/tarantool/tarantool/issues/3695
src/box/sql/parse.y | 5 -----
test/sql-tap/default.test.lua | 45 ++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 44 insertions(+), 6 deletions(-)
diff --git a/src/box/sql/parse.y b/src/box/sql/parse.y
index 60cf3f3e3..70bc026e3 100644
--- a/src/box/sql/parse.y
+++ b/src/box/sql/parse.y
@@ -264,11 +264,6 @@ ccons ::= DEFAULT MINUS(A) term(X). {
v.zEnd = X.zEnd;
sqlite3AddDefaultValue(pParse,&v);
}
-ccons ::= DEFAULT id(X). {
- ExprSpan v;
- spanExpr(&v, pParse, TK_STRING, X);
- sqlite3AddDefaultValue(pParse,&v);
-}
// In addition to the type name, we also care about the primary key and
// UNIQUE constraints.
diff --git a/test/sql-tap/default.test.lua b/test/sql-tap/default.test.lua
index 2f08a51ad..88bfa219f 100755
--- a/test/sql-tap/default.test.lua
+++ b/test/sql-tap/default.test.lua
@@ -1,6 +1,6 @@
#!/usr/bin/env tarantool
test = require("sqltester")
-test:plan(11)
+test:plan(15)
--!./tcltestrunner.lua
-- 2005 August 18
@@ -205,6 +205,49 @@ test:do_catchsql_test(
-- </default-4.4>
})
+-- gh-3695: IDs (i.e. columns' names) are not allowed as
+-- default values.
+--
+test:do_catchsql_test(
+ "default-5.1",
+ [[
+ CREATE TABLE t6(id INTEGER PRIMARY KEY, b TEXT DEFAULT(id));
+ ]], {
+ -- <default-5.1>
+ 1, "default value of column [B] is not constant"
+ -- </default-5.1>
+})
+
+test:do_catchsql_test(
+ "default-5.2",
+ [[
+ CREATE TABLE t6(id INTEGER PRIMARY KEY, b TEXT DEFAULT id);
+ ]], {
+ -- <default-5.2>
+ 1, "near \"id\": syntax error"
+ -- </default-5.2>
+})
+test:do_catchsql_test(
+ "default-5.3",
+ [[
+ CREATE TABLE t6(id INTEGER PRIMARY KEY, b TEXT DEFAULT "id");
+ ]], {
+ -- <default-5.3>
+ 1, "near \"\"id\"\": syntax error"
+ -- </default-5.3>
+})
+
+test:do_execsql_test(
+ "default-5.4",
+ [[
+ CREATE TABLE t6(id INTEGER PRIMARY KEY, b INT DEFAULT('id'));
+ INSERT INTO t6(id) VALUES(1);
+ SELECT * FROM t6;
+ ]], {
+ -- <default-5.4>
+ 1, 'id'
+ -- </default-5.4>
+})
test:finish_test()
--
2.15.1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-10-02 7:17 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-19 16:20 [tarantool-patches] [PATCH] sql: disallow specifying ID in <DEFAULT> clause Nikita Pettik
2018-10-02 7:17 ` [tarantool-patches] " Kirill Yukhin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox