[tarantool-patches] [PATCH v1 1/1] sql: raise error for DELETE FROM nonexistent table
Kirill Shcherbatov
kshcherbatov at tarantool.org
Mon Jul 16 18:09:29 MSK 2018
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
More information about the Tarantool-patches
mailing list