Software /
code /
prosody
Changeset
7272:a23ca90d1984
util.sql: Move per-driver (currenly only PostgreSQL) query transform into its own method
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 13 Mar 2016 17:38:49 +0100 |
parents | 7271:dae47cd774ac |
children | 7273:7e659f87973d |
files | util/sql.lua |
diffstat | 1 files changed, 10 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/util/sql.lua Sat Mar 12 18:13:24 2016 +0100 +++ b/util/sql.lua Sun Mar 13 17:38:49 2016 +0100 @@ -124,6 +124,14 @@ 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 @@ 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