Skip to content
Snippets Groups Projects
Commit 14ba68f9 authored by Georgy Kirichenko's avatar Georgy Kirichenko Committed by Kirill Yukhin
Browse files

Return valid lua error for func creation error

Return valid lua error if something fails during sql function creation.

Closes #3724
parent cfa7da04
No related branches found
No related tags found
No related merge requests found
......@@ -188,9 +188,11 @@ lbox_sql_create_function(struct lua_State *L)
if (func_info == NULL)
return luaL_error(L, "out of memory");
func_info->func_ref = luaL_ref(L, LUA_REGISTRYINDEX);
sqlite3_create_function_v2(db, normalized_name, type, func_arg_num,
is_deterministic ? SQLITE_DETERMINISTIC : 0,
func_info, lua_sql_call, NULL, NULL,
lua_sql_destroy);
int rc = sqlite3_create_function_v2(db, normalized_name, type, func_arg_num,
is_deterministic ? SQLITE_DETERMINISTIC : 0,
func_info, lua_sql_call, NULL, NULL,
lua_sql_destroy);
if (rc != 0)
return luaL_error(L, sqlite3ErrStr(rc));
return 0;
}
test_run = require('test_run').new()
---
...
engine = test_run:get_cfg('engine')
---
...
box.sql.execute('pragma sql_default_engine=\''..engine..'\'')
---
...
-- Check errors during function create process
fiber = require('fiber')
---
...
box.internal.sql_create_function('WAITFOR', 'INT', function (n) fiber.sleep(n) return n end)
---
...
ch = fiber.channel(1)
---
...
_ = fiber.create(function () ch:put(box.sql.execute('select WAITFOR(0.2)')) end)
---
...
fiber.sleep(0.1)
---
...
box.internal.sql_create_function('WAITFOR', 'INT', function (n) require('fiber').sleep(n) return n end)
---
- error: database is locked
...
ch:get()
---
- - [0.2]
...
box.internal.sql_create_function('WAITFOR', 'INT', function (n) require('fiber').sleep(n) return n end)
---
...
test_run = require('test_run').new()
engine = test_run:get_cfg('engine')
box.sql.execute('pragma sql_default_engine=\''..engine..'\'')
-- Check errors during function create process
fiber = require('fiber')
box.internal.sql_create_function('WAITFOR', 'INT', function (n) fiber.sleep(n) return n end)
ch = fiber.channel(1)
_ = fiber.create(function () ch:put(box.sql.execute('select WAITFOR(0.2)')) end)
fiber.sleep(0.1)
box.internal.sql_create_function('WAITFOR', 'INT', function (n) require('fiber').sleep(n) return n end)
ch:get()
box.internal.sql_create_function('WAITFOR', 'INT', function (n) require('fiber').sleep(n) return n end)
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