Description
There are critical errors in class-wp-sqlite-translator.php that prevent it from running correctly and subsequently cause a ton of error debug messages to dump into php.log on every page request. Here is the fix for sites running relatively newer versions of PHP/Sqlite3 which are sensitive to this (apparently, older versions are immune which is why this bug seems to evade some developers).
Two SELECT statements in get_keys()
need to have their quotes reversed (I reported this in another issue but I have since closed it for clarity here). Enclosing a table name in double quotes is not valid in SQLite:
INCORRECT:
'SELECT * FROM pragma_index_list("' . $table_name . '") as l;'
CORRECT:
"SELECT * FROM pragma_index_list('" . $table_name . "') as l;"
Because of this error, the code for translating ON DUPLICATE KEY
in translate_on_duplicate_key()
never gets a chance to execute when it calls $this->get_keys()
.
Also, a minor optimization in that function. These three skip calls aren't needed since the while loop does the same job.
if ( ! $conflict_columns ) {
// Drop the consumed "ON".
$this->rewriter->drop_last();
// Skip over "DUPLICATE", "KEY", and "UPDATE".
// $this->rewriter->skip();
// $this->rewriter->skip();
// $this->rewriter->skip();
while ( $this->rewriter->skip() ) {
// Skip over the rest of the query.
}
return;
}
Once the above fixes are made, php.log no longer spews ton of lines of debug on every page request. It also allowed some plugins to update their settings properly (e.g., WP Armour) which previously was breaking.
Works on:
- PHP 8.2.19
- SQLite3 3.46.0