From: Kirill Shcherbatov <kshcherbatov@tarantool.org>
To: tarantool-patches@freelists.org
Cc: korablev@tarantool.org, Kirill Shcherbatov <kshcherbatov@tarantool.org>
Subject: [tarantool-patches] [PATCH v1 1/1] sql: raise error for DELETE FROM nonexistent table
Date: Mon, 16 Jul 2018 18:09:29 +0300 [thread overview]
Message-ID: <8ea2b4731ccf9d79140d17f87a6a1ed05f9948d8.1531753721.git.kshcherbatov@tarantool.org> (raw)
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
next reply other threads:[~2018-07-16 15:09 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-16 15:09 Kirill Shcherbatov [this message]
2018-07-16 15:13 ` [tarantool-patches] " n.pettik
2018-07-19 10:48 ` Kirill Yukhin
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=8ea2b4731ccf9d79140d17f87a6a1ed05f9948d8.1531753721.git.kshcherbatov@tarantool.org \
--to=kshcherbatov@tarantool.org \
--cc=korablev@tarantool.org \
--cc=tarantool-patches@freelists.org \
--subject='Re: [tarantool-patches] [PATCH v1 1/1] sql: raise error for DELETE FROM nonexistent table' \
/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