Comparison

plugins/mod_storage_sql.lua @ 10011:2408e6362c15 0.11

mod_storage_sql: Move code out of if-else chain
author Kim Alvefur <zash@zash.se>
date Mon, 13 May 2019 14:47:41 +0200
parent 9628:2fcf517b811e
child 10012:acf4a7bfb6aa
comparison
equal deleted inserted replaced
9998:c8646f65767a 10011:2408e6362c15
388 if query.truncate == nil then 388 if query.truncate == nil then
389 sql_query = sql_query:format(t_concat(where, " AND ")); 389 sql_query = sql_query:format(t_concat(where, " AND "));
390 else 390 else
391 args[#args+1] = query.truncate; 391 args[#args+1] = query.truncate;
392 local unlimited = "ALL"; 392 local unlimited = "ALL";
393 sql_query = [[
394 DELETE FROM "prosodyarchive"
395 WHERE "sort_id" IN (
396 SELECT "sort_id" FROM "prosodyarchive"
397 WHERE %s
398 ORDER BY "sort_id" %s
399 LIMIT %s OFFSET ?
400 );]];
393 if engine.params.driver == "SQLite3" then 401 if engine.params.driver == "SQLite3" then
394 sql_query = [[ 402 sql_query = [[
395 DELETE FROM "prosodyarchive" 403 DELETE FROM "prosodyarchive"
396 WHERE %s 404 WHERE %s
397 ORDER BY "sort_id" %s 405 ORDER BY "sort_id" %s
405 WHERE %s 413 WHERE %s
406 ORDER BY "sort_id" %s 414 ORDER BY "sort_id" %s
407 LIMIT %s OFFSET ? 415 LIMIT %s OFFSET ?
408 ) AS limiter on result.sort_id = limiter.sort_id;]]; 416 ) AS limiter on result.sort_id = limiter.sort_id;]];
409 unlimited = "18446744073709551615"; 417 unlimited = "18446744073709551615";
410 else
411 sql_query = [[
412 DELETE FROM "prosodyarchive"
413 WHERE "sort_id" IN (
414 SELECT "sort_id" FROM "prosodyarchive"
415 WHERE %s
416 ORDER BY "sort_id" %s
417 LIMIT %s OFFSET ?
418 );]];
419 end 418 end
420 sql_query = string.format(sql_query, t_concat(where, " AND "), 419 sql_query = string.format(sql_query, t_concat(where, " AND "),
421 query.reverse and "ASC" or "DESC", unlimited); 420 query.reverse and "ASC" or "DESC", unlimited);
422 end 421 end
423 return engine:delete(sql_query, unpack(args)); 422 return engine:delete(sql_query, unpack(args));