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 3145020093 for ; Mon, 16 Jul 2018 11:09:37 -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 bWPcVN2ES085 for ; Mon, 16 Jul 2018 11:09:37 -0400 (EDT) Received: from smtpng2.m.smailru.net (smtpng2.m.smailru.net [94.100.179.3]) (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 E1AC82006F for ; Mon, 16 Jul 2018 11:09:36 -0400 (EDT) From: Kirill Shcherbatov Subject: [tarantool-patches] [PATCH v1 1/1] sql: raise error for DELETE FROM nonexistent table Date: Mon, 16 Jul 2018 18:09:29 +0300 Message-Id: <8ea2b4731ccf9d79140d17f87a6a1ed05f9948d8.1531753721.git.kshcherbatov@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, Kirill Shcherbatov Parser didn't raise error when DELETE FROM can't find a table specified on statement. As no error was raised, partially-prepared VDBE code seemed to be generated fine, that was not true. Closes #3535. --- Branch: https://github.com/tarantool/tarantool/compare/kshch/gh-3535-assertion-on-delete Issue: https://github.com/tarantool/tarantool/issues/3535 src/box/sql/delete.c | 6 +++++- test/sql/delete.result | 20 ++++++++++++++++++++ test/sql/delete.test.lua | 11 +++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/box/sql/delete.c b/src/box/sql/delete.c index ca1e77d..47d984c 100644 --- a/src/box/sql/delete.c +++ b/src/box/sql/delete.c @@ -103,8 +103,12 @@ sql_table_delete_from(struct Parse *parse, struct SrcList *tab_list, if (sqlite3LocateTable(parse, LOCATE_NOERR, tab_name) == NULL) { space_id = box_space_id_by_name(tab_name, strlen(tab_name)); - if (space_id == BOX_ID_NIL) + if (space_id == BOX_ID_NIL) { + diag_set(ClientError, ER_NO_SUCH_SPACE, tab_name); + parse->rc = SQL_TARANTOOL_ERROR; + parse->nErr++; goto delete_from_cleanup; + } /* * In this case space has been created via Lua * facilities, so there is no corresponding entry diff --git a/test/sql/delete.result b/test/sql/delete.result index c454c60..c33079c 100644 --- a/test/sql/delete.result +++ b/test/sql/delete.result @@ -39,3 +39,23 @@ box.sql.execute("DROP TABLE t1;"); ... -- Debug -- require("console").start() +-- +-- gh-3535: Assertion with trigger and non existent table +-- +box.sql.execute("DELETE FROM t1;") +--- +- error: Space 'T1' does not exist +... +box.sql.execute("CREATE TABLE t2 (s1 INT PRIMARY KEY);") +--- +... +box.sql.execute("CREATE TRIGGER t2 BEFORE INSERT ON t2 BEGIN DELETE FROM t1; END;") +--- +... +box.sql.execute("INSERT INTO t2 VALUES (0);") +--- +- error: Space 'T1' does not exist +... +box.sql.execute("DROP TABLE t2;") +--- +... diff --git a/test/sql/delete.test.lua b/test/sql/delete.test.lua index 2f6b625..1721989 100644 --- a/test/sql/delete.test.lua +++ b/test/sql/delete.test.lua @@ -26,3 +26,14 @@ box.sql.execute("DROP TABLE t1;"); -- Debug -- require("console").start() + +-- +-- gh-3535: Assertion with trigger and non existent table +-- +box.sql.execute("DELETE FROM t1;") + +box.sql.execute("CREATE TABLE t2 (s1 INT PRIMARY KEY);") +box.sql.execute("CREATE TRIGGER t2 BEFORE INSERT ON t2 BEGIN DELETE FROM t1; END;") +box.sql.execute("INSERT INTO t2 VALUES (0);") + +box.sql.execute("DROP TABLE t2;") -- 2.7.4