Software /
code /
prosody
Comparison
util/sql.lua @ 8078:60207251863c
Merge 0.10->trunk
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 12 Apr 2017 20:59:18 +0200 |
parent | 8077:29b3957db212 |
child | 8084:655837e9eeeb |
comparison
equal
deleted
inserted
replaced
8074:4b403f881176 | 8078:60207251863c |
---|---|
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 |
157 rowcount = function(self) return self.__stmt:rowcount(); end; | 158 rowcount = function(self) return self.__stmt:rowcount(); end; |
158 } }; | 159 } }; |
159 | 160 |
160 local function debugquery(where, sql, ...) | 161 local function debugquery(where, sql, ...) |
161 local i = 0; local a = {...} | 162 local i = 0; local a = {...} |
163 sql = sql:gsub("\n?\t+", " "); | |
162 log("debug", "[%s] %s", where, sql:gsub("%?", function () i = i + 1; local v = a[i]; if type(v) == "string" then v = ("%q"):format(v); end return tostring(v); end)); | 164 log("debug", "[%s] %s", where, sql:gsub("%?", function () i = i + 1; local v = a[i]; if type(v) == "string" then v = ("%q"):format(v); end return tostring(v); end)); |
163 end | 165 end |
164 | 166 |
165 function engine:execute_query(sql, ...) | 167 function engine:execute_query(sql, ...) |
166 sql = self:prepquery(sql); | 168 sql = self:prepquery(sql); |
252 sql = sql:gsub("\"([,)])", "\"(20)%1"); | 254 sql = sql:gsub("\"([,)])", "\"(20)%1"); |
253 end | 255 end |
254 if index.unique then | 256 if index.unique then |
255 sql = sql:gsub("^CREATE", "CREATE UNIQUE"); | 257 sql = sql:gsub("^CREATE", "CREATE UNIQUE"); |
256 end | 258 end |
257 sql = self:prepquery(sql); | |
258 if self._debug then | 259 if self._debug then |
259 debugquery("create", sql); | 260 debugquery("create", sql); |
260 end | 261 end |
261 return self:execute(sql); | 262 return self:execute(sql); |
262 end | 263 end |
284 end | 285 end |
285 sql = sql.. ");" | 286 sql = sql.. ");" |
286 if self.params.driver == "MySQL" then | 287 if self.params.driver == "MySQL" then |
287 sql = sql:gsub(";$", (" CHARACTER SET '%s' COLLATE '%s_bin';"):format(self.charset, self.charset)); | 288 sql = sql:gsub(";$", (" CHARACTER SET '%s' COLLATE '%s_bin';"):format(self.charset, self.charset)); |
288 end | 289 end |
289 sql = self:prepquery(sql); | |
290 if self._debug then | 290 if self._debug then |
291 debugquery("create", sql); | 291 debugquery("create", sql); |
292 end | 292 end |
293 local success,err = self:execute(sql); | 293 local success,err = self:execute(sql); |
294 if not success then return success,err; end | 294 if not success then return success,err; end |