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 CBA822AC4B for ; Tue, 26 Mar 2019 06:59:33 -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 o6rPTUic_ZU0 for ; Tue, 26 Mar 2019 06:59:33 -0400 (EDT) Received: from smtp33.i.mail.ru (smtp33.i.mail.ru [94.100.177.93]) (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 89AF62AC24 for ; Tue, 26 Mar 2019 06:59:33 -0400 (EDT) Subject: [tarantool-patches] Re: [PATCH v2 6/9] sql: disallow use of TYPEOF in Check References: <1ca353f2acec30ae27d59684a08005f25fbd5228.1548838034.git.kshcherbatov@tarantool.org> From: Kirill Shcherbatov Message-ID: Date: Tue, 26 Mar 2019 13:59:31 +0300 MIME-Version: 1.0 In-Reply-To: <1ca353f2acec30ae27d59684a08005f25fbd5228.1548838034.git.kshcherbatov@tarantool.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit 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, korablev@tarantool.org Due to the fact that we are going to perform CHECKs validations on the server side, checks are performed on the fields with affinity already applied that may differ with type of original data. After the introduction of static types, the need for type checks based on the CHECKs disappeared. Needed for #3691 --- src/box/sql/resolve.c | 7 +++++ src/box/sql/sqlInt.h | 3 ++ test/sql-tap/check.test.lua | 60 ++----------------------------------- 3 files changed, 13 insertions(+), 57 deletions(-) diff --git a/src/box/sql/resolve.c b/src/box/sql/resolve.c index 94bb0affc..6e181647d 100644 --- a/src/box/sql/resolve.c +++ b/src/box/sql/resolve.c @@ -715,6 +715,9 @@ resolveExprStep(Walker * pWalker, Expr * pExpr) nId, zId); pNC->nErr++; } + if (pDef != NULL && + (pDef->funcFlags & SQL_FUNC_TYPEOF) != 0) + pNC->ncFlags |= NC_HasTypeofFunction; if (is_agg) pNC->ncFlags &= ~NC_AllowAgg; sqlWalkExprList(pWalker, pList); @@ -1621,4 +1624,8 @@ sql_resolve_self_reference(struct Parse *parser, struct space_def *def, return; if (expr_list != NULL) sqlResolveExprListNames(&sNC, expr_list); + if (type == NC_IsCheck && sNC.ncFlags & NC_HasTypeofFunction) { + sqlErrorMsg(parser, "TYPEOF prohibited in check constraints"); + parser->is_aborted = true; + } } diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h index 3c58ac649..9fef9ea2e 100644 --- a/src/box/sql/sqlInt.h +++ b/src/box/sql/sqlInt.h @@ -2403,6 +2403,9 @@ struct NameContext { #define NC_MinMaxAgg 0x1000 /* min/max aggregates seen. See note above */ /** One or more identifiers are out of aggregate function. */ #define NC_HasUnaggregatedId 0x2000 +/** One or more identifiers are in TYPEOF function. */ +#define NC_HasTypeofFunction 0x4000 + /* * An instance of the following structure contains all information * needed to generate code for a single SELECT statement. diff --git a/test/sql-tap/check.test.lua b/test/sql-tap/check.test.lua index c2c0b6a80..e68cdba04 100755 --- a/test/sql-tap/check.test.lua +++ b/test/sql-tap/check.test.lua @@ -1,6 +1,6 @@ #!/usr/bin/env tarantool test = require("sqltester") -test:plan(61) +test:plan(56) --!./tcltestrunner.lua -- 2005 November 2 @@ -201,7 +201,7 @@ test:do_execsql_test( -- }) -test:do_execsql_test( +test:do_catchsql_test( "check-2.1", [[ CREATE TABLE t2( @@ -212,64 +212,10 @@ test:do_execsql_test( ); ]], { -- - + 1, "Failed to create check constraint 'THREE': TYPEOF prohibited in check constraints" -- }) -test:do_execsql_test( - "check-2.2", - [[ - INSERT INTO t2 VALUES(1, 1,2.2,'three'); - SELECT x, y, z FROM t2; - ]], { - -- - 1, 2.2, "three" - -- - }) - ---db("close") ---sql("db", "test.db") -test:do_execsql_test( - "check-2.3", - [[ - INSERT INTO t2 VALUES(2, NULL, NULL, NULL); - SELECT x, y, z FROM t2; - ]], { - -- - 1, 2.2, "three", "", "", "" - -- - }) - -test:do_catchsql_test( - "check-2.4", - [[ - INSERT INTO t2 VALUES(3, 1.1, NULL, NULL); - ]], { - -- - 1, "Check constraint failed: ONE" - -- - }) - -test:do_catchsql_test( - "check-2.5", - [[ - INSERT INTO t2 VALUES(4, NULL, 5, NULL); - ]], { - -- - 1, "Check constraint failed: TWO" - -- - }) - -test:do_catchsql_test( - "check-2.6", - [[ - INSERT INTO t2 VALUES(5, NULL, NULL, 3.14159); - ]], { - -- - 1, "Check constraint failed: THREE" - -- - }) - -- gh-3504: Check the CONSTRAINT name clause can't follow a constraint. test:do_catchsql_test( -- 2.21.0