Mercurial > prosody-hg
comparison plugins/mod_storage_sql.lua @ 10017:994cccebb597
Merge 0.11->trunk
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sun, 26 May 2019 19:41:58 +0200 |
| parents | b6b5b9d7417d acf4a7bfb6aa |
| children | deb68066c7aa |
comparison
equal
deleted
inserted
replaced
| 10010:34bfefb39937 | 10017:994cccebb597 |
|---|---|
| 470 if query.truncate == nil then | 470 if query.truncate == nil then |
| 471 sql_query = sql_query:format(t_concat(where, " AND ")); | 471 sql_query = sql_query:format(t_concat(where, " AND ")); |
| 472 else | 472 else |
| 473 args[#args+1] = query.truncate; | 473 args[#args+1] = query.truncate; |
| 474 local unlimited = "ALL"; | 474 local unlimited = "ALL"; |
| 475 if engine.params.driver == "SQLite3" then | 475 sql_query = [[ |
| 476 sql_query = [[ | 476 DELETE FROM "prosodyarchive" |
| 477 DELETE FROM "prosodyarchive" | 477 WHERE "sort_id" IN ( |
| 478 SELECT "sort_id" FROM "prosodyarchive" | |
| 478 WHERE %s | 479 WHERE %s |
| 479 ORDER BY "sort_id" %s | 480 ORDER BY "sort_id" %s |
| 480 LIMIT %s OFFSET ?; | 481 LIMIT %s OFFSET ? |
| 481 ]]; | 482 );]]; |
| 483 if engine.params.driver == "SQLite3" then | |
| 484 if engine._have_delete_limit then | |
| 485 sql_query = [[ | |
| 486 DELETE FROM "prosodyarchive" | |
| 487 WHERE %s | |
| 488 ORDER BY "sort_id" %s | |
| 489 LIMIT %s OFFSET ?; | |
| 490 ]]; | |
| 491 end | |
| 482 unlimited = "-1"; | 492 unlimited = "-1"; |
| 483 elseif engine.params.driver == "MySQL" then | 493 elseif engine.params.driver == "MySQL" then |
| 484 sql_query = [[ | 494 sql_query = [[ |
| 485 DELETE result FROM prosodyarchive AS result JOIN ( | 495 DELETE result FROM prosodyarchive AS result JOIN ( |
| 486 SELECT sort_id FROM prosodyarchive | 496 SELECT sort_id FROM prosodyarchive |
| 487 WHERE %s | 497 WHERE %s |
| 488 ORDER BY "sort_id" %s | 498 ORDER BY "sort_id" %s |
| 489 LIMIT %s OFFSET ? | 499 LIMIT %s OFFSET ? |
| 490 ) AS limiter on result.sort_id = limiter.sort_id;]]; | 500 ) AS limiter on result.sort_id = limiter.sort_id;]]; |
| 491 unlimited = "18446744073709551615"; | 501 unlimited = "18446744073709551615"; |
| 492 else | |
| 493 sql_query = [[ | |
| 494 DELETE FROM "prosodyarchive" | |
| 495 WHERE "sort_id" IN ( | |
| 496 SELECT "sort_id" FROM "prosodyarchive" | |
| 497 WHERE %s | |
| 498 ORDER BY "sort_id" %s | |
| 499 LIMIT %s OFFSET ? | |
| 500 );]]; | |
| 501 end | 502 end |
| 502 sql_query = string.format(sql_query, t_concat(where, " AND "), | 503 sql_query = string.format(sql_query, t_concat(where, " AND "), |
| 503 query.reverse and "ASC" or "DESC", unlimited); | 504 query.reverse and "ASC" or "DESC", unlimited); |
| 504 end | 505 end |
| 505 return engine:delete(sql_query, unpack(args)); | 506 return engine:delete(sql_query, unpack(args)); |
| 716 -- Check whether the table needs upgrading | 717 -- Check whether the table needs upgrading |
| 717 if upgrade_table(engine, params, false) then | 718 if upgrade_table(engine, params, false) then |
| 718 module:log("error", "Old database format detected. Please run: prosodyctl mod_%s upgrade", module.name); | 719 module:log("error", "Old database format detected. Please run: prosodyctl mod_%s upgrade", module.name); |
| 719 return false, "database upgrade needed"; | 720 return false, "database upgrade needed"; |
| 720 end | 721 end |
| 722 if engine.params.driver == "SQLite3" then | |
| 723 for row in engine:select("PRAGMA compile_options") do | |
| 724 if row[1] == "ENABLE_UPDATE_DELETE_LIMIT" then | |
| 725 engine._have_delete_limit = true; | |
| 726 end | |
| 727 end | |
| 728 end | |
| 721 end | 729 end |
| 722 end); | 730 end); |
| 723 engines[sql.db2uri(params)] = engine; | 731 engines[sql.db2uri(params)] = engine; |
| 724 end | 732 end |
| 725 | 733 |
