@@ -321,6 +321,7 @@ 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
+ // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- escaped through self::esc_sql_ident
324
325
$ row = $ wpdb ->get_row ( "SHOW CREATE TABLE $ table_sql " , ARRAY_N );
325
326
fwrite ( $ this ->export_handle , $ row [1 ] . "; \n" );
326
327
list ( $ table_report , $ total_rows ) = $ this ->php_export_table ( $ table , $ old , $ new );
@@ -367,6 +368,7 @@ public function __invoke( $args, $assoc_args ) {
367
368
if ( ! $ php_only && ! $ this ->regex ) {
368
369
$ col_sql = self ::esc_sql_ident ( $ col );
369
370
$ wpdb ->last_error = '' ;
371
+ // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- escaped through self::esc_sql_ident
370
372
$ serial_row = $ wpdb ->get_row ( "SELECT * FROM $ table_sql WHERE $ col_sql REGEXP '^[aiO]:[1-9]' LIMIT 1 " );
371
373
// When the regex triggers an error, we should fall back to PHP
372
374
if ( false !== strpos ( $ wpdb ->last_error , 'ERROR 1139 ' ) ) {
@@ -492,12 +494,14 @@ private function sql_handle_col( $col, $primary_keys, $table, $old, $new ) {
492
494
if ( $ this ->log_handle ) {
493
495
$ count = $ this ->log_sql_diff ( $ col , $ primary_keys , $ table , $ old , $ new );
494
496
} else {
497
+ // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- escaped through self::esc_sql_ident
495
498
$ count = $ wpdb ->get_var ( $ wpdb ->prepare ( "SELECT COUNT( $ col_sql) FROM $ table_sql WHERE $ col_sql LIKE BINARY %s; " , '% ' . self ::esc_like ( $ old ) . '% ' ) );
496
499
}
497
500
} else {
498
501
if ( $ this ->log_handle ) {
499
502
$ this ->log_sql_diff ( $ col , $ primary_keys , $ table , $ old , $ new );
500
503
}
504
+ // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- escaped through self::esc_sql_ident
501
505
$ count = $ wpdb ->query ( $ wpdb ->prepare ( "UPDATE $ table_sql SET $ col_sql = REPLACE( $ col_sql, %s, %s); " , $ old , $ new ) );
502
506
}
503
507
@@ -518,6 +522,7 @@ private function php_handle_col( $col, $primary_keys, $table, $old, $new ) {
518
522
$ col_sql = self ::esc_sql_ident ( $ col );
519
523
$ where = $ this ->regex ? '' : " WHERE $ col_sql " . $ wpdb ->prepare ( ' LIKE BINARY %s ' , '% ' . self ::esc_like ( $ old ) . '% ' );
520
524
$ primary_keys_sql = implode ( ', ' , self ::esc_sql_ident ( $ primary_keys ) );
525
+ // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- escaped through self::esc_sql_ident
521
526
$ rows = $ wpdb ->get_results ( "SELECT {$ primary_keys_sql } FROM {$ table_sql } {$ where }" );
522
527
foreach ( $ rows as $ keys ) {
523
528
$ where_sql = '' ;
@@ -527,6 +532,7 @@ private function php_handle_col( $col, $primary_keys, $table, $old, $new ) {
527
532
}
528
533
$ where_sql .= self ::esc_sql_ident ( $ k ) . ' = ' . self ::esc_sql_value ( $ v );
529
534
}
535
+ // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- escaped through self::esc_sql_ident
530
536
$ col_value = $ wpdb ->get_var ( "SELECT {$ col_sql } FROM {$ table_sql } WHERE {$ where_sql }" );
531
537
if ( '' === $ col_value ) {
532
538
continue ;
@@ -611,9 +617,11 @@ private function write_sql_row_fields( $table, $rows ) {
611
617
612
618
if ( method_exists ( $ wpdb , 'remove_placeholder_escape ' ) ) {
613
619
// since 4.8.3
620
+ // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- verified inputs above
614
621
$ sql = $ wpdb ->remove_placeholder_escape ( $ wpdb ->prepare ( $ sql , array_values ( $ values ) ) );
615
622
} else {
616
623
// 4.8.2 or less
624
+ // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- verified inputs above
617
625
$ sql = $ wpdb ->prepare ( $ sql , array_values ( $ values ) );
618
626
}
619
627
@@ -640,6 +648,7 @@ private static function get_columns( $table ) {
640
648
$ text_columns = array ();
641
649
$ all_columns = array ();
642
650
$ suppress_errors = $ wpdb ->suppress_errors ();
651
+ // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- escaped through self::esc_sql_ident
643
652
$ results = $ wpdb ->get_results ( "DESCRIBE $ table_sql " );
644
653
if ( ! empty ( $ results ) ) {
645
654
foreach ( $ results as $ col ) {
@@ -777,7 +786,11 @@ private function log_sql_diff( $col, $primary_keys, $table, $old, $new ) {
777
786
$ primary_keys_sql = '' ;
778
787
}
779
788
780
- $ results = $ wpdb ->get_results ( $ wpdb ->prepare ( "SELECT {$ primary_keys_sql }` $ col` FROM ` $ table` WHERE ` $ col` LIKE BINARY %s " , '% ' . self ::esc_like ( $ old ) . '% ' ), ARRAY_N );
789
+ $ table_sql = self ::esc_sql_ident ( $ table );
790
+ $ col_sql = self ::esc_sql_ident ( $ col );
791
+
792
+ // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- escaped through self::esc_sql_ident
793
+ $ 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 );
781
794
if ( empty ( $ results ) ) {
782
795
return 0 ;
783
796
}
0 commit comments