Comparison

plugins/mod_storage_sql.lua @ 12829:fba795dd99c8 0.12

mod_storage_sql: Fix #1639 Patch by Peter Kieser
author Kim Alvefur <zash@zash.se>
date Sun, 01 Jan 2023 16:20:58 +0100
parent 12823:dd6c35325241
child 12830:0c3184378032
comparison
equal deleted inserted replaced
12825:ee5fcfef5200 12829:fba795dd99c8
467 end 467 end
468 468
469 local ok, err = archive_where_id_range(query, args, where); 469 local ok, err = archive_where_id_range(query, args, where);
470 if not ok then return ok, err; end 470 if not ok then return ok, err; end
471 471
472 if query.limit then
473 args[#args+1] = query.limit;
474 end
475
476 sql_query = sql_query:format(t_concat(where, " AND "), query.reverse 472 sql_query = sql_query:format(t_concat(where, " AND "), query.reverse
477 and "DESC" or "ASC", query.limit and " LIMIT ?" or ""); 473 and "DESC" or "ASC", query.limit and " LIMIT " .. query.limit or "");
478 return engine:select(sql_query, unpack(args)); 474 return engine:select(sql_query, unpack(args));
479 end); 475 end);
480 if not ok then return ok, result; end 476 if not ok then return ok, result; end
481 if not result then return nil, err; end 477 if not result then return nil, err; end
482 return function() 478 return function()
590 archive_where(query, args, where); 586 archive_where(query, args, where);
591 local ok, err = archive_where_id_range(query, args, where); 587 local ok, err = archive_where_id_range(query, args, where);
592 if not ok then return ok, err; end 588 if not ok then return ok, err; end
593 if query.truncate == nil then 589 if query.truncate == nil then
594 sql_query = sql_query:format(t_concat(where, " AND ")); 590 sql_query = sql_query:format(t_concat(where, " AND "));
591 elseif engine.params.driver == "MySQL" then
592 sql_query = [[
593 DELETE result FROM prosodyarchive AS result JOIN (
594 SELECT sort_id FROM prosodyarchive
595 WHERE %s
596 ORDER BY "sort_id" %s
597 LIMIT 18446744073709551615 OFFSET %s
598 ) AS limiter on result.sort_id = limiter.sort_id;]];
599
600 sql_query = string.format(sql_query, t_concat(where, " AND "),
601 query.reverse and "ASC" or "DESC", query.truncate);
595 else 602 else
596 args[#args+1] = query.truncate; 603 args[#args+1] = query.truncate;
597 local unlimited = "ALL"; 604 local unlimited = "ALL";
598 sql_query = [[ 605 sql_query = [[
599 DELETE FROM "prosodyarchive" 606 DELETE FROM "prosodyarchive"
611 ORDER BY "sort_id" %s 618 ORDER BY "sort_id" %s
612 LIMIT %s OFFSET ?; 619 LIMIT %s OFFSET ?;
613 ]]; 620 ]];
614 end 621 end
615 unlimited = "-1"; 622 unlimited = "-1";
616 elseif engine.params.driver == "MySQL" then
617 sql_query = [[
618 DELETE result FROM prosodyarchive AS result JOIN (
619 SELECT sort_id FROM prosodyarchive
620 WHERE %s
621 ORDER BY "sort_id" %s
622 LIMIT %s OFFSET ?
623 ) AS limiter on result.sort_id = limiter.sort_id;]];
624 unlimited = "18446744073709551615";
625 end 623 end
626 sql_query = string.format(sql_query, t_concat(where, " AND "), 624 sql_query = string.format(sql_query, t_concat(where, " AND "),
627 query.reverse and "ASC" or "DESC", unlimited); 625 query.reverse and "ASC" or "DESC", unlimited);
628 end 626 end
629 return engine:delete(sql_query, unpack(args)); 627 return engine:delete(sql_query, unpack(args));