Comparison

util/sql.lua @ 10275:a247fa8df7df

util.sql: Preserve 3rd and 4th return values from transaction (fixes #1434) (thanks mrdoctorwho)
author Kim Alvefur <zash@zash.se>
date Sat, 28 Sep 2019 18:24:28 +0200
parent 10109:c59d384b0959
child 10534:8a42fd6702e6
comparison
equal deleted inserted replaced
10274:b4596a056a4c 10275:a247fa8df7df
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(...)
221 local ok, ret = self:_transaction(...); 221 local ok, ret, b, c = self:_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]", (...)); 227 log("debug", "Retrying SQL transaction [%s]", (...));
228 ok, ret = self:_transaction(...); 228 ok, ret, b, c = 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
233 if not ok then 233 if not ok then
234 log("error", "Error in SQL transaction: %s", ret); 234 log("error", "Error in SQL transaction: %s", ret);
235 end 235 end
236 end 236 end
237 return ok, ret; 237 return ok, ret, b, c;
238 end 238 end
239 function engine:_create_index(index) 239 function engine:_create_index(index)
240 local sql = "CREATE INDEX \""..index.name.."\" ON \""..index.table.."\" ("; 240 local sql = "CREATE INDEX \""..index.name.."\" ON \""..index.table.."\" (";
241 if self.params.driver ~= "MySQL" then 241 if self.params.driver ~= "MySQL" then
242 sql = sql:gsub("^CREATE INDEX", "%1 IF NOT EXISTS"); 242 sql = sql:gsub("^CREATE INDEX", "%1 IF NOT EXISTS");