@@ -495,35 +495,35 @@ public function cli( $_, $assoc_args ) {
495
495
* +---------+-----------------------+
496
496
*/
497
497
public function query ( $ args , $ assoc_args ) {
498
-
498
+
499
499
$ command = sprintf ( '/usr/bin/env mysql%s --no-auto-rehash ' , $ this ->get_defaults_flag_string ( $ assoc_args ) );
500
500
WP_CLI ::debug ( "Running shell command: {$ command }" , 'db ' );
501
-
501
+
502
502
$ assoc_args ['database ' ] = DB_NAME ;
503
-
503
+
504
504
// The query might come from STDIN.
505
505
if ( ! empty ( $ args ) ) {
506
506
$ assoc_args ['execute ' ] = $ args [0 ];
507
507
}
508
-
508
+
509
509
if ( isset ( $ assoc_args ['execute ' ] ) ) {
510
510
// Ensure that the SQL mode is compatible with WPDB.
511
511
$ assoc_args ['execute ' ] = $ this ->get_sql_mode_query ( $ assoc_args ) . $ assoc_args ['execute ' ];
512
512
}
513
-
513
+
514
514
$ is_row_modifying_query = isset ( $ assoc_args ['execute ' ] ) && preg_match ( '/\b(UPDATE|DELETE|INSERT|REPLACE|LOAD DATA)\b/i ' , $ assoc_args ['execute ' ] );
515
-
515
+
516
516
if ( $ is_row_modifying_query ) {
517
517
$ assoc_args ['execute ' ] .= '; SELECT ROW_COUNT(); ' ;
518
518
}
519
-
519
+
520
520
WP_CLI ::debug ( 'Associative arguments: ' . json_encode ( $ assoc_args ), 'db ' );
521
521
list ( $ stdout , $ stderr , $ exit_code ) = self ::run ( $ command , $ assoc_args , false );
522
-
522
+
523
523
if ( $ exit_code ) {
524
524
WP_CLI ::error ( "Query failed: {$ stderr }" );
525
525
}
526
-
526
+
527
527
if ( $ is_row_modifying_query ) {
528
528
$ output_lines = explode ( "\n" , trim ( $ stdout ) );
529
529
$ affected_rows = (int ) trim ( end ( $ output_lines ) );
0 commit comments