aboutsummaryrefslogtreecommitdiffstats
path: root/util
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
commitee05252824f694381864c2141544297b032fe50e (patch)
tree59690cb5d2a5d04796a8e9c7188ebd320c711154 /util
parent3c8ec0ee57562b1e7c30aa4d175c80c0c0ae383f (diff)
downloadprosody-ee05252824f694381864c2141544297b032fe50e.tar.gz
prosody-ee05252824f694381864c2141544297b032fe50e.zip
util.sql: Move per-driver (currenly only PostgreSQL) query transform into its own method
Diffstat (limited to 'util')
-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