[tarantool-patches] [PATCH v1 1/1] sql: replace schema_find_id() by box_space_id_by_name()
imeevma at tarantool.org
imeevma at tarantool.org
Sat Apr 27 18:30:44 MSK 2019
This patch replaces schema_find_id() with box_space_id_by_name()
in SQL. The box_space_id_by_name() is more specialized. In
addition, it checks if the user has sufficient rights, unlike
schema_find_id().
Closes #3570
---
https://github.com/tarantool/tarantool/issues/3570
https://github.com/tarantool/tarantool/tree/imeevma/gh-3570-replace-schema_find_id
src/box/sql/trigger.c | 7 +++----
test/sql/triggers.result | 36 ++++++++++++++++++++++++++++++++++++
test/sql/triggers.test.lua | 18 ++++++++++++++++++
3 files changed, 57 insertions(+), 4 deletions(-)
diff --git a/src/box/sql/trigger.c b/src/box/sql/trigger.c
index 14e4198..fe19244 100644
--- a/src/box/sql/trigger.c
+++ b/src/box/sql/trigger.c
@@ -38,6 +38,7 @@
#include "tarantoolInt.h"
#include "vdbeInt.h"
#include "box/session.h"
+#include "box/box.h"
/* See comment in sqlInt.h */
int sqlSubProgramsRemaining;
@@ -87,10 +88,8 @@ sql_trigger_begin(struct Parse *parse)
goto trigger_cleanup;
const char *table_name = alter_def->entity_name->a[0].zName;
- uint32_t space_id;
- if (schema_find_id(BOX_SPACE_ID, 2, table_name, strlen(table_name),
- &space_id) != 0)
- goto set_tarantool_error_and_cleanup;
+ uint32_t space_id = box_space_id_by_name(table_name,
+ strlen(table_name));
if (space_id == BOX_ID_NIL) {
diag_set(ClientError, ER_NO_SUCH_SPACE, table_name);
goto set_tarantool_error_and_cleanup;
diff --git a/test/sql/triggers.result b/test/sql/triggers.result
index 77b88f4..af9085d 100644
--- a/test/sql/triggers.result
+++ b/test/sql/triggers.result
@@ -512,3 +512,39 @@ box.execute("DROP TABLE t1;")
---
- row_count: 1
...
+--
+-- gh-3570: Use box_space_id_by_name() instead of schema_find_id()
+-- in SQL
+--
+box.schema.user.create('tester')
+---
+...
+box.schema.user.grant('tester','read,write,create,execute', 'space', '_trigger')
+---
+...
+box.execute("CREATE TABLE t1(x INTEGER PRIMARY KEY AUTOINCREMENT);")
+---
+- row_count: 1
+...
+box.session.su('tester')
+---
+...
+--
+-- Ensure that the CREATE TRIGGER statement cannot be executed if
+-- the user does not have enough rights. In this case, the user
+-- does not have rights to read from _space.
+--
+box.execute([[CREATE TRIGGER r1 AFTER INSERT ON t1 FOR EACH ROW BEGIN SELECT 1; END; ]])
+---
+- error: Space 'T1' does not exist
+...
+box.session.su('admin')
+---
+...
+box.schema.user.drop('tester')
+---
+...
+box.execute("DROP TABLE t1;")
+---
+- row_count: 1
+...
diff --git a/test/sql/triggers.test.lua b/test/sql/triggers.test.lua
index 13497d6..a056e79 100644
--- a/test/sql/triggers.test.lua
+++ b/test/sql/triggers.test.lua
@@ -173,3 +173,21 @@ box.execute("CREATE TABLE t1(a INT PRIMARY KEY, b INT);")
space_id = box.space.T1.id
box.execute("CREATE TRIGGER tr1 AFTER INSERT ON t1 BEGIN ; END;")
box.execute("DROP TABLE t1;")
+
+--
+-- gh-3570: Use box_space_id_by_name() instead of schema_find_id()
+-- in SQL
+--
+box.schema.user.create('tester')
+box.schema.user.grant('tester','read,write,create,execute', 'space', '_trigger')
+box.execute("CREATE TABLE t1(x INTEGER PRIMARY KEY AUTOINCREMENT);")
+box.session.su('tester')
+--
+-- Ensure that the CREATE TRIGGER statement cannot be executed if
+-- the user does not have enough rights. In this case, the user
+-- does not have rights to read from _space.
+--
+box.execute([[CREATE TRIGGER r1 AFTER INSERT ON t1 FOR EACH ROW BEGIN SELECT 1; END; ]])
+box.session.su('admin')
+box.schema.user.drop('tester')
+box.execute("DROP TABLE t1;")
--
2.7.4
More information about the Tarantool-patches
mailing list