Software /
code /
prosody
Comparison
util/sql.lua @ 8076:6e0defa19ab9
util.sql: Apply quote transform in engine:execute so it is applied to eg encoding checks in mod_storage_sql (thanks Martin)
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 12 Apr 2017 17:26:44 +0200 |
parent | 8073:7361412a9664 |
child | 8077:29b3957db212 |
comparison
equal
deleted
inserted
replaced
8075:a4dd08fd64cf | 8076:6e0defa19ab9 |
---|---|
137 function engine:execute(sql, ...) | 137 function engine:execute(sql, ...) |
138 local success, err = self:connect(); | 138 local success, err = self:connect(); |
139 if not success then return success, err; end | 139 if not success then return success, err; end |
140 local prepared = self.prepared; | 140 local prepared = self.prepared; |
141 | 141 |
142 sql = self:prepquery(sql); | |
142 local stmt = prepared[sql]; | 143 local stmt = prepared[sql]; |
143 if not stmt then | 144 if not stmt then |
144 local err; | 145 local err; |
145 stmt, err = self.conn:prepare(sql); | 146 stmt, err = self.conn:prepare(sql); |
146 if not stmt then return stmt, err; end | 147 if not stmt then return stmt, err; end |
252 sql = sql:gsub("\"([,)])", "\"(20)%1"); | 253 sql = sql:gsub("\"([,)])", "\"(20)%1"); |
253 end | 254 end |
254 if index.unique then | 255 if index.unique then |
255 sql = sql:gsub("^CREATE", "CREATE UNIQUE"); | 256 sql = sql:gsub("^CREATE", "CREATE UNIQUE"); |
256 end | 257 end |
257 sql = self:prepquery(sql); | |
258 if self._debug then | 258 if self._debug then |
259 debugquery("create", sql); | 259 debugquery("create", sql); |
260 end | 260 end |
261 return self:execute(sql); | 261 return self:execute(sql); |
262 end | 262 end |
284 end | 284 end |
285 sql = sql.. ");" | 285 sql = sql.. ");" |
286 if self.params.driver == "MySQL" then | 286 if self.params.driver == "MySQL" then |
287 sql = sql:gsub(";$", (" CHARACTER SET '%s' COLLATE '%s_bin';"):format(self.charset, self.charset)); | 287 sql = sql:gsub(";$", (" CHARACTER SET '%s' COLLATE '%s_bin';"):format(self.charset, self.charset)); |
288 end | 288 end |
289 sql = self:prepquery(sql); | |
290 if self._debug then | 289 if self._debug then |
291 debugquery("create", sql); | 290 debugquery("create", sql); |
292 end | 291 end |
293 local success,err = self:execute(sql); | 292 local success,err = self:execute(sql); |
294 if not success then return success,err; end | 293 if not success then return success,err; end |