Repository navigation
SQLite Compatibility #92
Copy link
Copy link
Closed
Labels
command:transientRelated to 'transient' commandRelated to 'transient' commandcommand:transient-deleteRelated to 'transient delete' commandRelated to 'transient delete' commandcommand:transient-listRelated to 'transient list' commandRelated to 'transient list' command
Description
When I manually run the tests locally with SQLite, the following scenarios are failing:
001 Scenario: Deleting all transients on single site # features/transient.feature:58
Then STDOUT should be: # features/transient.feature:76
$ wp transient delete --all
Success: No transients found.
002 Scenario: Deleting expired transients on single site # features/transient.feature:123
Then STDOUT should be: # features/transient.feature:134
$ wp transient delete --expired
Success: No expired transients found.
003 Scenario: Deleting all transients on multisite # features/transient.feature:194
Then STDOUT should be: # features/transient.feature:215
$ wp transient delete --all
Success: No transients found.
004 Scenario: Deleting expired transients on multisite # features/transient.feature:286
Then STDOUT should be: # features/transient.feature:301
$ wp transient delete --expired
Success: No expired transients found.
005 Scenario: List transients on single site # features/transient.feature:386
Then STDOUT should contain: # features/transient.feature:400
$ wp transient list --format=csv
name,value,expiration
006 Scenario: List transients on multisite # features/transient.feature:431
Then STDOUT should contain: # features/transient.feature:445
$ wp transient list --format=csv
name,value,expiration
007 Scenario: List transients with search and exclude pattern # features/transient.feature:476
Then STDOUT should be: # features/transient.feature:485
$ wp transient list --format=csv --fields=name --search="foo"
name
The transient command uses lots of custom MySQL queries. The SQLite integration plugin is supposed to make those SQLite-compatible, but perhaps something is not working there.
Or, since deletion and listing are failing, maybe the issue is that the insertion using set_transient() is failing in the first place.
Let's figure it out together. This could involve changes to the command, the tests, core, or the SQLite plugin.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
command:transientRelated to 'transient' commandRelated to 'transient' commandcommand:transient-deleteRelated to 'transient delete' commandRelated to 'transient delete' commandcommand:transient-listRelated to 'transient list' commandRelated to 'transient list' command
Activity
swissspidy commentedon Oct 23, 2023
OK, so for the
transient deletecommand there seem to be issue with the way LIKEs are being escaped by WordPress. The SQLite plugin might not be translating those properly and ending up deleting 0 rows. "Raw" queries without$wpdb->preparedo seem to work.That said, the returned deletion counts seem to be wrong. Not sure if we need something like
$wpdb->query( "SELECT changes() FROM {$wpdb->options}" )as well.petitphp commentedon Apr 29, 2024
@swissspidy I took a look at this, I'm not familiar with SQLite so I might be mistaking, but it seems that SQLite doesn't support
DELETEstatement for multiple tables like MySQL does :I did manage to get the tests to pass by doing three queries to replicate what this
DELETEstatement, but maybe the SQLite WordPress plugin could handle that automatically.swissspidy commentedon Apr 29, 2024
Interesting! Do you perhaps have a draft PR with that solution so that we could take a look?
It does seem like a case the SQLite plugin could handle, so If you could open an issues I'm sure the maintainers can take a look.
petitphp commentedon Apr 29, 2024
Turn out it's related to the escaping, like you suspected.
Looking at the
wpdb::esc_likemethod in the SQLite integration plugin, they purposely remove theaddslashessince SQLite doesn't care for the_%characters.I'm able to fix the issue by modifying the
Utils::esc_liketo use the nativewpdbmethod if available. But this will break the associated test in SQLite mode. We would need to create a new test to run in that mode.swissspidy commentedon Apr 29, 2024
Let‘s try that 👍
schlessera commentedon May 5, 2025
Looking at the database after a
wp transient set foo bar, you can see that it is properly added towp_optionstable.Also, if you try the same transient again, it correctly fails with an error because this particular transient was already set and conly be updated.
This means that the insertion succeeded, and the list fails because it does not see the existing transients.
schlessera commentedon May 5, 2025
Fixed via wp-cli/wp-cli#6088
bgrgicak commentedon May 6, 2025
Is there maybe an issue where you track overall SQLite compatibility?
I'm curious what other commands fail in WP-CLI.