@@ -321,7 +321,10 @@ public function __invoke( $args, $assoc_args ) {
321
321
322
322
if ( $ this ->export_handle ) {
323
323
fwrite ( $ this ->export_handle , "\nDROP TABLE IF EXISTS $ table_sql; \n" );
324
+
325
+ // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- escaped through self::esc_sql_ident
324
326
$ row = $ wpdb ->get_row ( "SHOW CREATE TABLE $ table_sql " , ARRAY_N );
327
+
325
328
fwrite ( $ this ->export_handle , $ row [1 ] . "; \n" );
326
329
list ( $ table_report , $ total_rows ) = $ this ->php_export_table ( $ table , $ old , $ new );
327
330
if ( $ this ->report ) {
@@ -367,7 +370,10 @@ public function __invoke( $args, $assoc_args ) {
367
370
if ( ! $ php_only && ! $ this ->regex ) {
368
371
$ col_sql = self ::esc_sql_ident ( $ col );
369
372
$ wpdb ->last_error = '' ;
370
- $ serial_row = $ wpdb ->get_row ( "SELECT * FROM $ table_sql WHERE $ col_sql REGEXP '^[aiO]:[1-9]' LIMIT 1 " );
373
+
374
+ // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- escaped through self::esc_sql_ident
375
+ $ serial_row = $ wpdb ->get_row ( "SELECT * FROM $ table_sql WHERE $ col_sql REGEXP '^[aiO]:[1-9]' LIMIT 1 " );
376
+
371
377
// When the regex triggers an error, we should fall back to PHP
372
378
if ( false !== strpos ( $ wpdb ->last_error , 'ERROR 1139 ' ) ) {
373
379
$ serial_row = true ;
@@ -492,12 +498,14 @@ private function sql_handle_col( $col, $primary_keys, $table, $old, $new ) {
492
498
if ( $ this ->log_handle ) {
493
499
$ count = $ this ->log_sql_diff ( $ col , $ primary_keys , $ table , $ old , $ new );
494
500
} else {
501
+ // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- escaped through self::esc_sql_ident
495
502
$ count = $ wpdb ->get_var ( $ wpdb ->prepare ( "SELECT COUNT( $ col_sql) FROM $ table_sql WHERE $ col_sql LIKE BINARY %s; " , '% ' . self ::esc_like ( $ old ) . '% ' ) );
496
503
}
497
504
} else {
498
505
if ( $ this ->log_handle ) {
499
506
$ this ->log_sql_diff ( $ col , $ primary_keys , $ table , $ old , $ new );
500
507
}
508
+ // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- escaped through self::esc_sql_ident
501
509
$ count = $ wpdb ->query ( $ wpdb ->prepare ( "UPDATE $ table_sql SET $ col_sql = REPLACE( $ col_sql, %s, %s); " , $ old , $ new ) );
502
510
}
503
511
@@ -518,7 +526,10 @@ private function php_handle_col( $col, $primary_keys, $table, $old, $new ) {
518
526
$ col_sql = self ::esc_sql_ident ( $ col );
519
527
$ where = $ this ->regex ? '' : " WHERE $ col_sql " . $ wpdb ->prepare ( ' LIKE BINARY %s ' , '% ' . self ::esc_like ( $ old ) . '% ' );
520
528
$ primary_keys_sql = implode ( ', ' , self ::esc_sql_ident ( $ primary_keys ) );
521
- $ rows = $ wpdb ->get_results ( "SELECT {$ primary_keys_sql } FROM {$ table_sql } {$ where }" );
529
+
530
+ // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- escaped through self::esc_sql_ident
531
+ $ rows = $ wpdb ->get_results ( "SELECT {$ primary_keys_sql } FROM {$ table_sql } {$ where }" );
532
+
522
533
foreach ( $ rows as $ keys ) {
523
534
$ where_sql = '' ;
524
535
foreach ( (array ) $ keys as $ k => $ v ) {
@@ -527,7 +538,10 @@ private function php_handle_col( $col, $primary_keys, $table, $old, $new ) {
527
538
}
528
539
$ where_sql .= self ::esc_sql_ident ( $ k ) . ' = ' . self ::esc_sql_value ( $ v );
529
540
}
541
+
542
+ // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- escaped through self::esc_sql_ident
530
543
$ col_value = $ wpdb ->get_var ( "SELECT {$ col_sql } FROM {$ table_sql } WHERE {$ where_sql }" );
544
+
531
545
if ( '' === $ col_value ) {
532
546
continue ;
533
547
}
@@ -609,9 +623,11 @@ private function write_sql_row_fields( $table, $rows ) {
609
623
610
624
if ( method_exists ( $ wpdb , 'remove_placeholder_escape ' ) ) {
611
625
// since 4.8.3
626
+ // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- verified inputs above
612
627
$ sql = $ wpdb ->remove_placeholder_escape ( $ wpdb ->prepare ( $ sql , array_values ( $ values ) ) );
613
628
} else {
614
629
// 4.8.2 or less
630
+ // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- verified inputs above
615
631
$ sql = $ wpdb ->prepare ( $ sql , array_values ( $ values ) );
616
632
}
617
633
@@ -638,7 +654,10 @@ private static function get_columns( $table ) {
638
654
$ text_columns = array ();
639
655
$ all_columns = array ();
640
656
$ suppress_errors = $ wpdb ->suppress_errors ();
641
- $ results = $ wpdb ->get_results ( "DESCRIBE $ table_sql " );
657
+
658
+ // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- escaped through self::esc_sql_ident
659
+ $ results = $ wpdb ->get_results ( "DESCRIBE $ table_sql " );
660
+
642
661
if ( ! empty ( $ results ) ) {
643
662
foreach ( $ results as $ col ) {
644
663
if ( 'PRI ' === $ col ->Key ) {
@@ -775,7 +794,12 @@ private function log_sql_diff( $col, $primary_keys, $table, $old, $new ) {
775
794
$ primary_keys_sql = '' ;
776
795
}
777
796
778
- $ results = $ wpdb ->get_results ( $ wpdb ->prepare ( "SELECT {$ primary_keys_sql }` $ col` FROM ` $ table` WHERE ` $ col` LIKE BINARY %s " , '% ' . self ::esc_like ( $ old ) . '% ' ), ARRAY_N );
797
+ $ table_sql = self ::esc_sql_ident ( $ table );
798
+ $ col_sql = self ::esc_sql_ident ( $ col );
799
+
800
+ // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- escaped through self::esc_sql_ident
801
+ $ results = $ wpdb ->get_results ( $ wpdb ->prepare ( "SELECT {$ primary_keys_sql }{$ col_sql } FROM {$ table_sql } WHERE {$ col_sql } LIKE BINARY %s " , '% ' . self ::esc_like ( $ old ) . '% ' ), ARRAY_N );
802
+
779
803
if ( empty ( $ results ) ) {
780
804
return 0 ;
781
805
}
0 commit comments