Tarantool development patches archive
 help / color / mirror / Atom feed
* [tarantool-patches] [PATCH v1 1/1] sql: raise error for DELETE FROM nonexistent table
@ 2018-07-16 15:09 Kirill Shcherbatov
  2018-07-16 15:13 ` [tarantool-patches] " n.pettik
  2018-07-19 10:48 ` Kirill Yukhin
  0 siblings, 2 replies; 3+ messages in thread
From: Kirill Shcherbatov @ 2018-07-16 15:09 UTC (permalink / raw)
  To: tarantool-patches; +Cc: korablev, 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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [tarantool-patches] Re: [PATCH v1 1/1] sql: raise error for DELETE FROM nonexistent table
  2018-07-16 15:09 [tarantool-patches] [PATCH v1 1/1] sql: raise error for DELETE FROM nonexistent table Kirill Shcherbatov
@ 2018-07-16 15:13 ` n.pettik
  2018-07-19 10:48 ` Kirill Yukhin
  1 sibling, 0 replies; 3+ messages in thread
From: n.pettik @ 2018-07-16 15:13 UTC (permalink / raw)
  To: tarantool-patches; +Cc: Kirill Shcherbatov


> On 16 Jul 2018, at 18:09, Kirill Shcherbatov <kshcherbatov@tarantool.org> wrote:
> 
> 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.
> —

LGTM. It seems that your patch also closes #3511 issue.
If so, add also test for that case and ticket number to commit message
(to close it automatically).

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [tarantool-patches] Re: [PATCH v1 1/1] sql: raise error for DELETE FROM nonexistent table
  2018-07-16 15:09 [tarantool-patches] [PATCH v1 1/1] sql: raise error for DELETE FROM nonexistent table Kirill Shcherbatov
  2018-07-16 15:13 ` [tarantool-patches] " n.pettik
@ 2018-07-19 10:48 ` Kirill Yukhin
  1 sibling, 0 replies; 3+ messages in thread
From: Kirill Yukhin @ 2018-07-19 10:48 UTC (permalink / raw)
  To: tarantool-patches; +Cc: korablev, Kirill Shcherbatov

Hello,
On 16 июл 18:09, Kirill Shcherbatov wrote:
> 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
I've checked in your patch into 2.0 branch.

--
Regards, Kirill Yukhin

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-07-19 10:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-16 15:09 [tarantool-patches] [PATCH v1 1/1] sql: raise error for DELETE FROM nonexistent table Kirill Shcherbatov
2018-07-16 15:13 ` [tarantool-patches] " n.pettik
2018-07-19 10:48 ` Kirill Yukhin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox