mirror of
https://github.com/bjc/prosody.git
synced 2025-04-04 21:57:45 +03:00
util.sqlite3: Don't cache prepared statements for one-off queries
The :execute method is mainly used for one-off queries such as creating tables and indices. There is no need to cache this prepared statement, as those queries are only done on startup. Further, prepared statements can't be reused without being reset, so this was likely broken anyway.
This commit is contained in:
parent
95687d9ddd
commit
dd37d17425
1 changed files with 8 additions and 10 deletions
|
@ -163,6 +163,7 @@ end
|
||||||
function engine:ondisconnect() -- luacheck: ignore 212/self
|
function engine:ondisconnect() -- luacheck: ignore 212/self
|
||||||
-- Override from create_engine()
|
-- Override from create_engine()
|
||||||
end
|
end
|
||||||
|
|
||||||
function engine:execute(sql, ...)
|
function engine:execute(sql, ...)
|
||||||
local success, err = self:connect();
|
local success, err = self:connect();
|
||||||
if not success then return success, err; end
|
if not success then return success, err; end
|
||||||
|
@ -178,20 +179,17 @@ function engine:execute(sql, ...)
|
||||||
return true;
|
return true;
|
||||||
end
|
end
|
||||||
|
|
||||||
local stmt = prepared[sql];
|
local stmt, err = self.conn:prepare(sql);
|
||||||
if not stmt then
|
|
||||||
local err;
|
|
||||||
stmt, err = self.conn:prepare(sql);
|
|
||||||
if not stmt then
|
if not stmt then
|
||||||
err = sqlite_errors.new(err);
|
err = sqlite_errors.new(err);
|
||||||
err.text = self.conn:errmsg();
|
err.text = self.conn:errmsg();
|
||||||
return stmt, err;
|
return stmt, err;
|
||||||
end
|
end
|
||||||
prepared[sql] = stmt;
|
|
||||||
end
|
|
||||||
|
|
||||||
local ret = stmt:bind_values(...);
|
local ret = stmt:bind_values(...);
|
||||||
if ret ~= lsqlite3.OK then return nil, sqlite_errors.new(ret, { message = self.conn:errmsg() }); end
|
if ret ~= lsqlite3.OK then
|
||||||
|
return nil, sqlite_errors.new(ret, { message = self.conn:errmsg() });
|
||||||
|
end
|
||||||
return stmt;
|
return stmt;
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue