Skip to content
Snippets Groups Projects
Commit afc5f92d authored by Mergen Imeev's avatar Mergen Imeev Committed by Kirill Yukhin
Browse files

sql: replace schema_find_id() by box_space_id_by_name()

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
parent d039fc05
No related branches found
No related tags found
No related merge requests found
......@@ -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;
......
......@@ -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
...
......@@ -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;")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment