OllieJones / sqlite-object-cache

A WordPress persistent object cache for the rest of us.
GNU General Public License v2.0
24 stars 4 forks source link

Not all versions of SQLite allow DELETE ... LIMIT n #37

Closed OllieJones closed 9 months ago

OllieJones commented 9 months ago

@wabetainfo reported: (https://wordpress.org/support/topic/sqlite_remove_expired-near-limit-syntax-error-1/)

I am testing the latest update and I found this error in the debug log file:

SQLite Object Cache: 3.39.4 no igbinary: php 8.0.30: Apache: sqlite_remove_expired near "LIMIT": syntax error (1)

It appears that “LIMIT” is not supported in “DELETE” statements: https://stackoverflow.com/a/61996257

It's true. The various LIMIT n DELETEs added to avoid locking for too long, they don't work everywhere. This appears to be due to a compilation option in SQLite, not tied to any particular version. So we have to do

DELETE FROM tbl WHERE what<ever LIMIT 10

as this, which works.

DELETE FROM tbl WHERE pk IN (SELECT pk FROM tbl WHERE what<ever LIMIT 10)

OllieJones commented 9 months ago

Fixed. Some SQLite versions accept those LIMIT clauses on DELETE (and UPDATE) and others don't. So this code no longer relies on the presence of the feature.