aboutsummaryrefslogtreecommitdiffstats
path: root/util/sqlite3.lua
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2023-06-10 22:20:26 +0200
committerKim Alvefur <zash@zash.se>2023-06-10 22:20:26 +0200
commitdd37d17425c58e539c7aa19d30edf194b2c8f071 (patch)
treebf836954807ffac2b2f9965d01b3dcff3efa0e71 /util/sqlite3.lua
parent95687d9ddd62821e26ad417aa6caa2a9ce85694e (diff)
downloadprosody-dd37d17425c58e539c7aa19d30edf194b2c8f071.tar.gz
prosody-dd37d17425c58e539c7aa19d30edf194b2c8f071.zip
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.
Diffstat (limited to 'util/sqlite3.lua')
-rw-r--r--util/sqlite3.lua18
1 files changed, 8 insertions, 10 deletions
diff --git a/util/sqlite3.lua b/util/sqlite3.lua
index 0f9b97d1..cdb90b8f 100644
--- a/util/sqlite3.lua
+++ b/util/sqlite3.lua
@@ -163,6 +163,7 @@ end
function engine:ondisconnect() -- luacheck: ignore 212/self
-- Override from create_engine()
end
+
function engine:execute(sql, ...)
local success, err = self:connect();
if not success then return success, err; end
@@ -178,20 +179,17 @@ function engine:execute(sql, ...)
return true;
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
- err = sqlite_errors.new(err);
- err.text = self.conn:errmsg();
- return stmt, err;
- end
- prepared[sql] = stmt;
+ err = sqlite_errors.new(err);
+ err.text = self.conn:errmsg();
+ return stmt, err;
end
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;
end