aboutsummaryrefslogtreecommitdiffstats
path: root/util/sql.lua
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2016-03-13 17:38:49 +0100
committerKim Alvefur <zash@zash.se>2016-03-13 17:38:49 +0100
commitb65ec4aebe68d0810faa076c7ae68acc2abe34e3 (patch)
tree59690cb5d2a5d04796a8e9c7188ebd320c711154 /util/sql.lua
parent89df062a5e59c9bad2e15b0b11a89361cc439cb1 (diff)
downloadprosody-b65ec4aebe68d0810faa076c7ae68acc2abe34e3.tar.gz
prosody-b65ec4aebe68d0810faa076c7ae68acc2abe34e3.zip
util.sql: Move per-driver (currenly only PostgreSQL) query transform into its own method
Diffstat (limited to 'util/sql.lua')
-rw-r--r--util/sql.lua16
1 files changed, 10 insertions, 6 deletions
diff --git a/util/sql.lua b/util/sql.lua
index 9981ac3c..85664567 100644
--- a/util/sql.lua
+++ b/util/sql.lua
@@ -124,6 +124,14 @@ end
function engine:onconnect()
-- Override from create_engine()
end
+
+function engine:prepquery(sql)
+ if self.params.driver == "PostgreSQL" then
+ sql = sql:gsub("`", "\"");
+ end
+ return sql;
+end
+
function engine:execute(sql, ...)
local success, err = self:connect();
if not success then return success, err; end
@@ -153,17 +161,13 @@ local function debugquery(where, sql, ...)
end
function engine:execute_query(sql, ...)
- if self.params.driver == "PostgreSQL" then
- sql = sql:gsub("`", "\"");
- end
+ sql = self:prepquery(sql);
local stmt = assert(self.conn:prepare(sql));
assert(stmt:execute(...));
return stmt:rows();
end
function engine:execute_update(sql, ...)
- if self.params.driver == "PostgreSQL" then
- sql = sql:gsub("`", "\"");
- end
+ sql = self:prepquery(sql);
local prepared = self.prepared;
local stmt = prepared[sql];
if not stmt then