From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id E16522981A for ; Wed, 19 Sep 2018 12:20:31 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Mwe1yU-EBWD5 for ; Wed, 19 Sep 2018 12:20:31 -0400 (EDT) Received: from smtp32.i.mail.ru (smtp32.i.mail.ru [94.100.177.92]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id A0E9829804 for ; Wed, 19 Sep 2018 12:20:31 -0400 (EDT) From: Nikita Pettik Subject: [tarantool-patches] [PATCH] sql: disallow specifying ID in clause Date: Wed, 19 Sep 2018 19:20:27 +0300 Message-Id: <20180919162027.41595-1-korablev@tarantool.org> Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-help: List-unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-subscribe: List-owner: List-post: List-archive: To: tarantool-patches@freelists.org Cc: kyukhin@tarantool.org, 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 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( -- }) +-- 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)); + ]], { + -- + 1, "default value of column [B] is not constant" + -- +}) + +test:do_catchsql_test( + "default-5.2", + [[ + CREATE TABLE t6(id INTEGER PRIMARY KEY, b TEXT DEFAULT id); + ]], { + -- + 1, "near \"id\": syntax error" + -- +}) +test:do_catchsql_test( + "default-5.3", + [[ + CREATE TABLE t6(id INTEGER PRIMARY KEY, b TEXT DEFAULT "id"); + ]], { + -- + 1, "near \"\"id\"\": syntax error" + -- +}) + +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; + ]], { + -- + 1, 'id' + -- +}) test:finish_test() -- 2.15.1