Software /
code /
prosody
Comparison
util/sql.lua @ 10109:c59d384b0959
util.sql: Remove tostring call from logging
Taken care of by loggingmanager now
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 30 Jul 2019 02:23:44 +0200 |
parent | 10038:7dd0dddd8e02 |
child | 10275:a247fa8df7df |
comparison
equal
deleted
inserted
replaced
10108:659ffa03f1e7 | 10109:c59d384b0959 |
---|---|
199 if not self.conn then | 199 if not self.conn then |
200 local ok, err = self:connect(); | 200 local ok, err = self:connect(); |
201 if not ok then return ok, err; end | 201 if not ok then return ok, err; end |
202 end | 202 end |
203 --assert(not self.__transaction, "Recursive transactions not allowed"); | 203 --assert(not self.__transaction, "Recursive transactions not allowed"); |
204 log("debug", "SQL transaction begin [%s]", tostring(func)); | 204 log("debug", "SQL transaction begin [%s]", func); |
205 self.__transaction = true; | 205 self.__transaction = true; |
206 local success, a, b, c = xpcall(func, handleerr, ...); | 206 local success, a, b, c = xpcall(func, handleerr, ...); |
207 self.__transaction = nil; | 207 self.__transaction = nil; |
208 if success then | 208 if success then |
209 log("debug", "SQL transaction success [%s]", tostring(func)); | 209 log("debug", "SQL transaction success [%s]", func); |
210 local ok, err = self.conn:commit(); | 210 local ok, err = self.conn:commit(); |
211 -- LuaDBI doesn't actually return an error message here, just a boolean | 211 -- LuaDBI doesn't actually return an error message here, just a boolean |
212 if not ok then return ok, err or "commit failed"; end | 212 if not ok then return ok, err or "commit failed"; end |
213 return success, a, b, c; | 213 return success, a, b, c; |
214 else | 214 else |
215 log("debug", "SQL transaction failure [%s]: %s", tostring(func), a.err); | 215 log("debug", "SQL transaction failure [%s]: %s", func, a.err); |
216 if self.conn then self.conn:rollback(); end | 216 if self.conn then self.conn:rollback(); end |
217 return success, a.err; | 217 return success, a.err; |
218 end | 218 end |
219 end | 219 end |
220 function engine:transaction(...) | 220 function engine:transaction(...) |
222 if not ok then | 222 if not ok then |
223 local conn = self.conn; | 223 local conn = self.conn; |
224 if not conn or not conn:ping() then | 224 if not conn or not conn:ping() then |
225 log("debug", "Database connection was closed. Will reconnect and retry."); | 225 log("debug", "Database connection was closed. Will reconnect and retry."); |
226 self.conn = nil; | 226 self.conn = nil; |
227 log("debug", "Retrying SQL transaction [%s]", tostring((...))); | 227 log("debug", "Retrying SQL transaction [%s]", (...)); |
228 ok, ret = self:_transaction(...); | 228 ok, ret = self:_transaction(...); |
229 log("debug", "SQL transaction retry %s", ok and "succeeded" or "failed"); | 229 log("debug", "SQL transaction retry %s", ok and "succeeded" or "failed"); |
230 else | 230 else |
231 log("debug", "SQL connection is up, so not retrying"); | 231 log("debug", "SQL connection is up, so not retrying"); |
232 end | 232 end |