Tarantool development patches archive
 help / color / mirror / Atom feed
From: Nikita Pettik <korablev@tarantool.org>
To: tarantool-patches@freelists.org
Cc: kyukhin@tarantool.org, Nikita Pettik <korablev@tarantool.org>
Subject: [tarantool-patches] [PATCH] sql: disallow specifying ID in <DEFAULT> clause
Date: Wed, 19 Sep 2018 19:20:27 +0300	[thread overview]
Message-ID: <20180919162027.41595-1-korablev@tarantool.org> (raw)

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

             reply	other threads:[~2018-09-19 16:20 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-19 16:20 Nikita Pettik [this message]
2018-10-02  7:17 ` [tarantool-patches] " Kirill Yukhin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180919162027.41595-1-korablev@tarantool.org \
    --to=korablev@tarantool.org \
    --cc=kyukhin@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='Re: [tarantool-patches] [PATCH] sql: disallow specifying ID in <DEFAULT> clause' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox