Software / code / prosody
Comparison
plugins/mod_storage_sql.lua @ 10012:acf4a7bfb6aa 0.11
mod_storage_sql: Handle SQLite DELETE with LIMIT being optional (fixes #1359)
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Mon, 13 May 2019 14:39:38 +0200 |
| parent | 10011:2408e6362c15 |
| child | 10017:994cccebb597 |
| child | 10652:0c00274528a4 |
comparison
equal
deleted
inserted
replaced
| 10011:2408e6362c15 | 10012:acf4a7bfb6aa |
|---|---|
| 397 WHERE %s | 397 WHERE %s |
| 398 ORDER BY "sort_id" %s | 398 ORDER BY "sort_id" %s |
| 399 LIMIT %s OFFSET ? | 399 LIMIT %s OFFSET ? |
| 400 );]]; | 400 );]]; |
| 401 if engine.params.driver == "SQLite3" then | 401 if engine.params.driver == "SQLite3" then |
| 402 sql_query = [[ | 402 if engine._have_delete_limit then |
| 403 DELETE FROM "prosodyarchive" | 403 sql_query = [[ |
| 404 WHERE %s | 404 DELETE FROM "prosodyarchive" |
| 405 ORDER BY "sort_id" %s | 405 WHERE %s |
| 406 LIMIT %s OFFSET ?; | 406 ORDER BY "sort_id" %s |
| 407 ]]; | 407 LIMIT %s OFFSET ?; |
| 408 ]]; | |
| 409 end | |
| 408 unlimited = "-1"; | 410 unlimited = "-1"; |
| 409 elseif engine.params.driver == "MySQL" then | 411 elseif engine.params.driver == "MySQL" then |
| 410 sql_query = [[ | 412 sql_query = [[ |
| 411 DELETE result FROM prosodyarchive AS result JOIN ( | 413 DELETE result FROM prosodyarchive AS result JOIN ( |
| 412 SELECT sort_id FROM prosodyarchive | 414 SELECT sort_id FROM prosodyarchive |
| 618 -- Check whether the table needs upgrading | 620 -- Check whether the table needs upgrading |
| 619 if upgrade_table(engine, params, false) then | 621 if upgrade_table(engine, params, false) then |
| 620 module:log("error", "Old database format detected. Please run: prosodyctl mod_%s upgrade", module.name); | 622 module:log("error", "Old database format detected. Please run: prosodyctl mod_%s upgrade", module.name); |
| 621 return false, "database upgrade needed"; | 623 return false, "database upgrade needed"; |
| 622 end | 624 end |
| 625 if engine.params.driver == "SQLite3" then | |
| 626 for row in engine:select("PRAGMA compile_options") do | |
| 627 if row[1] == "ENABLE_UPDATE_DELETE_LIMIT" then | |
| 628 engine._have_delete_limit = true; | |
| 629 end | |
| 630 end | |
| 631 end | |
| 623 end | 632 end |
| 624 end); | 633 end); |
| 625 engines[sql.db2uri(params)] = engine; | 634 engines[sql.db2uri(params)] = engine; |
| 626 end | 635 end |
| 627 | 636 |