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 8B29A26233 for ; Mon, 4 Feb 2019 09:44:18 -0500 (EST) 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 2vVpLqYxBl9o for ; Mon, 4 Feb 2019 09:44:18 -0500 (EST) Received: from smtpng3.m.smailru.net (smtpng3.m.smailru.net [94.100.177.149]) (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 486142622F for ; Mon, 4 Feb 2019 09:44:18 -0500 (EST) From: Ivan Koptelov Subject: [tarantool-patches] [PATCH] sql: raise err on CHECK + ON CONFLICT REPLACE Date: Mon, 4 Feb 2019 17:44:14 +0300 Message-Id: <20190204144414.91752-1-ivan.koptelov@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: korablev@tarantool.org, Ivan Koptelov Adds error raise in case of CHECK constraint declared with ON CONFLICT REPLACE action. Before the patch such option was forbidden, but if a user tried to create space with such constraint, this attempt failed silently. Closes #3345 --- Branch https://github.com/tarantool/tarantool/tree/sudobobo/gh-3345-raise-err-on-CHECK-w-ON-CONFLICT-REPLACE Issue https://github.com/tarantool/tarantool/issues/3345 src/box/sql/build.c | 12 ++++++++++++ test/sql-tap/check.test.lua | 16 +++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/box/sql/build.c b/src/box/sql/build.c index 49b90b5d0..e43694e0b 100644 --- a/src/box/sql/build.c +++ b/src/box/sql/build.c @@ -761,6 +761,18 @@ sql_add_check_constraint(struct Parse *parser, struct ExprSpan *span) { struct Expr *expr = span->pExpr; struct Table *table = parser->pNewTable; + + if (strcasestr(span->zEnd, "on conflict replace") != NULL) { + diag_set(ClientError, ER_CREATE_SPACE, table->def->name, + "ON CONFLICT REPLACE action is not allowed for " + "CHECK constraint"); + parser->rc = SQL_TARANTOOL_ERROR; + parser->nErr++; + sqlite3DbFree(parser->db, expr->u.zToken); + + goto release_expr; + } + if (table != NULL) { expr->u.zToken = sqlite3DbStrNDup(parser->db, (char *)span->zStart, diff --git a/test/sql-tap/check.test.lua b/test/sql-tap/check.test.lua index 1f369fb02..b6e17c059 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(58) +test:plan(59) --!./tcltestrunner.lua -- 2005 November 2 @@ -772,5 +772,19 @@ test:do_execsql_test( -- }) +-- gh-3345 : the test checks that ON CONFLICT REPLACE +-- is not allowed for CHECK constraint. +test:do_catchsql_test( + 9.1, + [[ + CREATE TABLE t101 (a INT primary key, b INT, CHECK(b < 10) + ON CONFLICT REPLACE) + ]], { + -- <9.1> + 1, "Failed to create space 'T101': ON CONFLICT REPLACE " .. + "action is not allowed for CHECK constraint" + -- + }) + test:finish_test() -- 2.14.3 (Apple Git-98)