From: Kirill Shcherbatov <kshcherbatov@tarantool.org> To: tarantool-patches@freelists.org, korablev@tarantool.org Subject: [tarantool-patches] Re: [PATCH v2 6/9] sql: disallow use of TYPEOF in Check Date: Tue, 26 Mar 2019 13:59:31 +0300 [thread overview] Message-ID: <f4db8fce-0ec8-8c4e-ae0c-83b9853df621@tarantool.org> (raw) In-Reply-To: <1ca353f2acec30ae27d59684a08005f25fbd5228.1548838034.git.kshcherbatov@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( -- </check-1.17> }) -test:do_execsql_test( +test:do_catchsql_test( "check-2.1", [[ CREATE TABLE t2( @@ -212,64 +212,10 @@ test:do_execsql_test( ); ]], { -- <check-2.1> - + 1, "Failed to create check constraint 'THREE': TYPEOF prohibited in check constraints" -- </check-2.1> }) -test:do_execsql_test( - "check-2.2", - [[ - INSERT INTO t2 VALUES(1, 1,2.2,'three'); - SELECT x, y, z FROM t2; - ]], { - -- <check-2.2> - 1, 2.2, "three" - -- </check-2.2> - }) - ---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; - ]], { - -- <check-2.3> - 1, 2.2, "three", "", "", "" - -- </check-2.3> - }) - -test:do_catchsql_test( - "check-2.4", - [[ - INSERT INTO t2 VALUES(3, 1.1, NULL, NULL); - ]], { - -- <check-2.4> - 1, "Check constraint failed: ONE" - -- </check-2.4> - }) - -test:do_catchsql_test( - "check-2.5", - [[ - INSERT INTO t2 VALUES(4, NULL, 5, NULL); - ]], { - -- <check-2.5> - 1, "Check constraint failed: TWO" - -- </check-2.5> - }) - -test:do_catchsql_test( - "check-2.6", - [[ - INSERT INTO t2 VALUES(5, NULL, NULL, 3.14159); - ]], { - -- <check-2.6> - 1, "Check constraint failed: THREE" - -- </check-2.6> - }) - -- gh-3504: Check the CONSTRAINT name clause can't follow a constraint. test:do_catchsql_test( -- 2.21.0
next prev parent reply other threads:[~2019-03-26 10:59 UTC|newest] Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-01-30 8:59 [tarantool-patches] [PATCH v2 0/9] sql: Checks on server side Kirill Shcherbatov 2019-01-30 8:59 ` [tarantool-patches] [PATCH v2 1/9] box: fix upgrade script for _fk_constraint space Kirill Shcherbatov 2019-03-11 18:44 ` [tarantool-patches] " n.pettik 2019-03-13 11:36 ` Kirill Yukhin 2019-01-30 8:59 ` [tarantool-patches] [PATCH v2 2/9] box: fix _trigger and _ck_constraint access check Kirill Shcherbatov 2019-03-11 19:29 ` [tarantool-patches] " n.pettik 2019-03-22 9:29 ` Vladislav Shpilevoy 2019-03-26 10:59 ` Kirill Shcherbatov 2019-04-01 14:06 ` n.pettik 2019-03-13 11:38 ` Kirill Yukhin 2019-03-13 11:44 ` Kirill Yukhin 2019-01-30 8:59 ` [tarantool-patches] [PATCH v2 3/9] box: fix Tarantool upgrade from 2.1.0 to 2.1.1 Kirill Shcherbatov 2019-03-12 11:45 ` [tarantool-patches] " n.pettik 2019-03-20 15:12 ` n.pettik 2019-03-20 15:38 ` Kirill Shcherbatov 2019-03-21 15:23 ` n.pettik 2019-03-21 15:36 ` Vladislav Shpilevoy 2019-03-22 9:28 ` Vladislav Shpilevoy 2019-03-22 10:18 ` Kirill Shcherbatov 2019-03-22 10:21 ` Vladislav Shpilevoy 2019-03-26 9:52 ` Kirill Yukhin 2019-01-30 8:59 ` [tarantool-patches] [PATCH v2 4/9] box: fix on_replace_trigger_rollback routine Kirill Shcherbatov 2019-03-11 20:00 ` [tarantool-patches] " n.pettik 2019-03-13 11:39 ` Kirill Yukhin 2019-01-30 8:59 ` [tarantool-patches] [PATCH v2 5/9] schema: add new system space for CHECK constraints Kirill Shcherbatov 2019-03-22 9:29 ` [tarantool-patches] " Vladislav Shpilevoy 2019-03-22 9:52 ` n.pettik 2019-03-26 10:59 ` Kirill Shcherbatov 2019-04-01 19:45 ` n.pettik 2019-04-16 13:51 ` Kirill Shcherbatov 2019-01-30 8:59 ` [tarantool-patches] [PATCH v2 6/9] sql: disallow use of TYPEOF in Check Kirill Shcherbatov 2019-03-26 10:59 ` Kirill Shcherbatov [this message] 2019-04-01 19:52 ` [tarantool-patches] " n.pettik 2019-01-30 8:59 ` [tarantool-patches] [PATCH v2 7/9] sql: refactor sqlite3_reset routine Kirill Shcherbatov 2019-03-26 10:59 ` [tarantool-patches] " Kirill Shcherbatov 2019-01-30 8:59 ` [tarantool-patches] [PATCH v2 8/9] box: exported sql_bind structure and API Kirill Shcherbatov 2019-03-26 10:59 ` [tarantool-patches] " Kirill Shcherbatov 2019-01-30 8:59 ` [tarantool-patches] [PATCH v2 9/9] sql: run check constraint tests on space alter Kirill Shcherbatov 2019-03-26 10:59 ` [tarantool-patches] " Kirill Shcherbatov 2019-04-02 14:14 ` n.pettik 2019-04-16 13:51 ` Kirill Shcherbatov
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=f4db8fce-0ec8-8c4e-ae0c-83b9853df621@tarantool.org \ --to=kshcherbatov@tarantool.org \ --cc=korablev@tarantool.org \ --cc=tarantool-patches@freelists.org \ --subject='[tarantool-patches] Re: [PATCH v2 6/9] sql: disallow use of TYPEOF in Check' \ /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