@@ -500,6 +500,9 @@ public function cli( $_, $assoc_args ) {
500500 */
501501 public function query ( $ args , $ assoc_args ) {
502502
503+ // Preserve the original defaults flag value before get_defaults_flag_string modifies $assoc_args.
504+ $ original_assoc_args_for_sql_mode = $ assoc_args ;
505+
503506 $ command = sprintf (
504507 '/usr/bin/env %s%s --no-auto-rehash ' ,
505508 $ this ->get_mysql_command (),
@@ -516,7 +519,7 @@ public function query( $args, $assoc_args ) {
516519
517520 if ( isset ( $ assoc_args ['execute ' ] ) ) {
518521 // Ensure that the SQL mode is compatible with WPDB.
519- $ assoc_args ['execute ' ] = $ this ->get_sql_mode_query ( $ assoc_args ) . $ assoc_args ['execute ' ];
522+ $ assoc_args ['execute ' ] = $ this ->get_sql_mode_query ( $ original_assoc_args_for_sql_mode ) . $ assoc_args ['execute ' ];
520523 }
521524
522525 $ is_row_modifying_query = isset ( $ assoc_args ['execute ' ] ) && preg_match ( '/\b(UPDATE|DELETE|INSERT|REPLACE|LOAD DATA)\b/i ' , $ assoc_args ['execute ' ] );
@@ -805,6 +808,9 @@ public function import( $args, $assoc_args ) {
805808 $ result_file = sprintf ( '%s.sql ' , DB_NAME );
806809 }
807810
811+ // Preserve the original defaults flag value before get_defaults_flag_string modifies $assoc_args.
812+ $ original_assoc_args_for_sql_mode = $ assoc_args ;
813+
808814 // Process options to MySQL.
809815 $ mysql_args = array_merge (
810816 [ 'database ' => DB_NAME ],
@@ -821,7 +827,7 @@ public function import( $args, $assoc_args ) {
821827 ? 'SOURCE %s; '
822828 : 'SET autocommit = 0; SET unique_checks = 0; SET foreign_key_checks = 0; SOURCE %s; COMMIT; ' ;
823829
824- $ query = $ this ->get_sql_mode_query ( $ assoc_args ) . $ query ;
830+ $ query = $ this ->get_sql_mode_query ( $ original_assoc_args_for_sql_mode ) . $ query ;
825831
826832 $ mysql_args ['execute ' ] = sprintf ( $ query , $ result_file );
827833 } else {
@@ -1753,8 +1759,11 @@ private static function get_create_query() {
17531759 * @param array $assoc_args Optional. Associative array of arguments.
17541760 */
17551761 protected function run_query ( $ query , $ assoc_args = [] ) {
1762+ // Preserve the original defaults flag value before get_defaults_flag_string modifies $assoc_args.
1763+ $ original_assoc_args_for_sql_mode = $ assoc_args ;
1764+
17561765 // Ensure that the SQL mode is compatible with WPDB.
1757- $ query = $ this ->get_sql_mode_query ( $ assoc_args ) . $ query ;
1766+ $ query = $ this ->get_sql_mode_query ( $ original_assoc_args_for_sql_mode ) . $ query ;
17581767
17591768 WP_CLI ::debug ( "Query: {$ query }" , 'db ' );
17601769
0 commit comments