Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
…lable Agent-Logs-Url: https://github.com/wp-cli/db-command/sessions/8996fc65-2840-4792-8cf4-ddc700a7c040 Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Agent-Logs-Url: https://github.com/wp-cli/db-command/sessions/8996fc65-2840-4792-8cf4-ddc700a7c040 Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix wp db query to fallback using WPDB
Add wpdb fallback for Apr 2, 2026
wp db query when mysql/mariadb binary is unavailable
This comment was marked as resolved.
This comment was marked as resolved.
Agent-Logs-Url: https://github.com/wp-cli/db-command/sessions/2fe9988f-095f-4c61-b162-5bf4f8956cca Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
This comment was marked as resolved.
This comment was marked as resolved.
Copilot
AI
changed the title
Add wpdb fallback for
Add wpdb fallback for Apr 3, 2026
wp db query when mysql/mariadb binary is unavailablewp db query, wp db import, wp db create, wp db drop, and wp db reset when mysql/mariadb binary is unavailable
swissspidy
reviewed
Apr 3, 2026
This comment was marked as resolved.
This comment was marked as resolved.
Agent-Logs-Url: https://github.com/wp-cli/db-command/sessions/fa41acc5-de2a-4dc3-9f7a-f5b282ed670a Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
This comment was marked as resolved.
This comment was marked as resolved.
Copilot
AI
changed the title
Add wpdb fallback for
Add wpdb fallback for Apr 3, 2026
wp db query, wp db import, wp db create, wp db drop, and wp db reset when mysql/mariadb binary is unavailablewp db query, wp db import, wp db drop, and wp db reset when mysql/mariadb binary is unavailable
swissspidy
reviewed
Apr 3, 2026
swissspidy
reviewed
Apr 3, 2026
Co-authored-by: Pascal Birchler <pascal.birchler@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Several
wp dbcommands currently require themysql/mariadbCLI binary, causing failures with drop-in database engines (HyperDB, custom drivers) or environments where the binary simply isn't installed. This PR adds automatic fallback to WordPress's$wpdbfor all relevant commands.Changes
src/DB_Command.phpis_mysql_binary_available()— probes for the mysql/mariadb binary via/usr/bin/env <binary> --version; result is statically cachedmaybe_load_wpdb()— loads the minimal WordPress files needed for$wpdb(load.php,compat.php,plugin.php,functions.php,class-wpdb.php), includes anywp-content/db.phpdrop-in (HyperDB et al.), and falls back to creating a plainwpdbinstance with wp-config.php credentials +$table_prefixrun_query()— now checks binary availability at the top and, when absent, routes throughmaybe_load_wpdb()+$wpdb->query()instead of invoking the mysql CLI. This coversdropandreset.query()— after the existing SQLite branch, checks binary availability and routes to the new wpdb path when absent viawpdb_query()wpdb_query()— executes arbitrary SQL via$wpdb; mirrors the mysql-path behaviour (row-count reporting for DML, formatted tabular output for SELECT,--skip-column-namessupport)import()— when the mysql binary is unavailable, reads the SQL file (or STDIN) and delegates towpdb_import()wpdb_import()— executes a SQL dump through$wpdbstatement-by-statement, applying the sameautocommit=0 / unique_checks=0 / foreign_key_checks=0 … COMMIToptimizations as the mysql path (unless--skip-optimizationis passed)split_sql_statements()— splits a SQL string into individual statements using a state-machine parser that correctly handles single-quoted strings, double-quoted strings,--line comments, and/* */block commentsfeatures/db-query.featureAdded a
@require-mysql-or-mariadbscenario that shadows the real binary with a fakeexit 127script viaPATHprepending, then asserts the query succeeds and the debug message confirms the fallback was taken.features/db.featureAdded
@require-mysql-or-mariadbscenarios forwp db dropandwp db resetthat shadow the binary with a fakeexit 127script and assert each command succeeds via the wpdb path (verified via theQuery via wpdb:debug line).features/db-import.featureAdded a
@require-mysql-or-mariadbscenario that exports a real SQL dump first, then shadows the binary and re-imports it, asserting success and theMySQL/MariaDB binary not available, falling back to wpdb for import.debug message.