mirror of
https://github.com/bjc/prosody.git
synced 2025-04-04 21:57:45 +03:00
util.sql: Move per-driver (currenly only PostgreSQL) query transform into its own method
This commit is contained in:
parent
89df062a5e
commit
b65ec4aebe
1 changed files with 10 additions and 6 deletions
16
util/sql.lua
16
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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue