# HG changeset patch # User Kim Alvefur # Date 1457887129 -3600 # Node ID a23ca90d1984422bfc7db944234edaa4d53637c2 # Parent dae47cd774ac9eb6d3a1e86dc820dd5545601b30 util.sql: Move per-driver (currenly only PostgreSQL) query transform into its own method diff -r dae47cd774ac -r a23ca90d1984 util/sql.lua --- 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