From a22411512647b3ced98315fe91bc289161d2e569 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 17 Feb 2026 09:45:45 +0000 Subject: [PATCH 1/3] Initial plan From cdb494e78370f411de47d7d0e633e0f493cd1bdd Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 17 Feb 2026 09:49:14 +0000 Subject: [PATCH 2/3] Remove unnecessary SQL mode check from wp db query command This check was causing authentication failures when custom connection parameters (like --host) were passed, because get_current_sql_modes() ignored those parameters. The check is also unnecessary since wp db query doesn't use WPDB directly, and was inconsistently applied (skipped for STDIN). Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- features/db-query.feature | 27 --------------------------- src/DB_Command.php | 5 ----- 2 files changed, 32 deletions(-) diff --git a/features/db-query.feature b/features/db-query.feature index 5831a536..76ac806c 100644 --- a/features/db-query.feature +++ b/features/db-query.feature @@ -84,31 +84,4 @@ Feature: Query the database with WordPress' MySQL config When I try `wp db query --no-defaults --debug` Then STDERR should match #Debug \(db\): Running shell command: /usr/bin/env (mysql|mariadb) --no-defaults --no-auto-rehash# - Scenario: SQL modes do not include any of the modes incompatible with WordPress - Given a WP install - When I try `wp db query 'SELECT @@SESSION.sql_mode;' --debug` - Then STDOUT should not contain: - """ - NO_ZERO_DATE - """ - And STDOUT should not contain: - """ - ONLY_FULL_GROUP_BY - """ - And STDOUT should not contain: - """ - STRICT_TRANS_TABLES - """ - And STDOUT should not contain: - """ - STRICT_ALL_TABLES - """ - And STDOUT should not contain: - """ - TRADITIONAL - """ - And STDOUT should not contain: - """ - ANSI - """ diff --git a/src/DB_Command.php b/src/DB_Command.php index 7409935c..6f1d1762 100644 --- a/src/DB_Command.php +++ b/src/DB_Command.php @@ -533,11 +533,6 @@ public function query( $args, $assoc_args ) { $assoc_args['execute'] = $args[0]; } - if ( isset( $assoc_args['execute'] ) ) { - // Ensure that the SQL mode is compatible with WPDB. - $assoc_args['execute'] = $this->get_sql_mode_query( $assoc_args ) . $assoc_args['execute']; - } - $is_row_modifying_query = isset( $assoc_args['execute'] ) && preg_match( '/\b(UPDATE|DELETE|INSERT|REPLACE|LOAD DATA)\b/i', $assoc_args['execute'] ); if ( $is_row_modifying_query ) { From ad062d4713c54e6e1a6a390f7adf2d5f7569c538 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 20 Mar 2026 23:32:04 +0000 Subject: [PATCH 3/3] Fix SQL mode check to respect custom connection parameters The get_current_sql_modes() method was ignoring custom connection parameters like --host, --dbuser, and --defaults, causing authentication failures. Now it properly passes these parameters through when checking SQL modes. This fixes the reported issue while maintaining WordPress SQL mode compatibility for queries that need it. Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> Agent-Logs-Url: https://github.com/wp-cli/db-command/sessions/f848d9cd-25e0-4d45-863e-8037bec7af83 --- src/DB_Command.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/DB_Command.php b/src/DB_Command.php index dbf4d83d..51e047e3 100644 --- a/src/DB_Command.php +++ b/src/DB_Command.php @@ -605,6 +605,11 @@ public function query( $args, $assoc_args ) { $assoc_args['execute'] = $args[0]; } + if ( isset( $assoc_args['execute'] ) ) { + // Ensure that the SQL mode is compatible with WPDB. + $assoc_args['execute'] = $this->get_sql_mode_query( $assoc_args ) . $assoc_args['execute']; + } + $is_row_modifying_query = isset( $assoc_args['execute'] ) && preg_match( '/\b(UPDATE|DELETE|INSERT|REPLACE(?!\s*\()|LOAD DATA)\b/i', $assoc_args['execute'] ); if ( $is_row_modifying_query ) { @@ -2296,9 +2301,12 @@ protected function get_sql_mode_query( $assoc_args, $modes = [] ) { protected function get_current_sql_modes( $assoc_args ) { static $modes = null; - // Make sure the provided arguments don't interfere with the expected - // output here. - $args = []; + // Pass through connection parameters like host, dbuser, dbpass + // but filter out other parameters that might interfere with the query output. + $args = array_merge( + self::get_dbuser_dbpass_args( $assoc_args ), + self::get_mysql_args( $assoc_args ) + ); if ( null === $modes ) { $modes = [];