diff --git a/features/search-replace.feature b/features/search-replace.feature index 325b6e2c..2bccd606 100644 --- a/features/search-replace.feature +++ b/features/search-replace.feature @@ -222,7 +222,6 @@ Feature: Do global search/replace """ # See https://github.com/wp-cli/search-replace-command/issues/190 - @skip-sqlite Scenario: Regex search/replace Given a WP install When I run `wp search-replace '(Hello)\s(world)' '$2, $1' --regex` @@ -962,6 +961,8 @@ Feature: Do global search/replace And STDERR should be empty # See https://github.com/wp-cli/search-replace-command/issues/190 + # SQLite: regex backreference replacement produces different results due to + # LIKE case-sensitivity differences. Requires further investigation. @skip-sqlite Scenario: Logging with regex replace Given a WP install @@ -1326,7 +1327,6 @@ Feature: Do global search/replace """ # See https://github.com/wp-cli/search-replace-command/issues/190 - @skip-sqlite Scenario: Regex search/replace with `--regex-limit=1` option Given a WP install And I run `wp post create --post_content="I have a pen, I have an apple. Pen, pine-apple, apple-pen."` @@ -1338,7 +1338,6 @@ Feature: Do global search/replace """ # See https://github.com/wp-cli/search-replace-command/issues/190 - @skip-sqlite Scenario: Regex search/replace with `--regex-limit=2` option Given a WP install And I run `wp post create --post_content="I have a pen, I have an apple. Pen, pine-apple, apple-pen."` @@ -1350,7 +1349,6 @@ Feature: Do global search/replace """ # See https://github.com/wp-cli/search-replace-command/issues/190 - @skip-sqlite Scenario: Regex search/replace with incorrect or default `--regex-limit` Given a WP install When I try `wp search-replace '(Hello)\s(world)' '$2, $1' --regex --regex-limit=asdf` diff --git a/src/Search_Replace_Command.php b/src/Search_Replace_Command.php index c37ad0df..8423560d 100644 --- a/src/Search_Replace_Command.php +++ b/src/Search_Replace_Command.php @@ -480,10 +480,16 @@ public function __invoke( $args, $assoc_args ) { $tables = Utils\wp_get_table_names( $args, $assoc_args ); // Identify views so they can be skipped; views are dynamic and cannot be directly modified. - $views_args = $assoc_args; - $views_args['views-only'] = true; - $views = Utils\wp_get_table_names( [], $views_args ); - $view_set = array_flip( array_intersect( $views, $tables ) ); + // The SQLite integration drop-in does not support SHOW FULL TABLES and WordPress + // on SQLite does not use views, so skip the views query entirely. + if ( 'sqlite' === Utils\get_db_type() ) { + $view_set = array(); + } else { + $views_args = $assoc_args; + $views_args['views-only'] = true; + $views = Utils\wp_get_table_names( [], $views_args ); + $view_set = array_flip( array_intersect( $views, $tables ) ); + } foreach ( $tables as $table ) { foreach ( $this->skip_tables as $skip_table ) { @@ -555,12 +561,17 @@ public function __invoke( $args, $assoc_args ) { $col_sql = self::esc_sql_ident( $col ); $wpdb->last_error = ''; - // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- escaped through self::esc_sql_ident - $serial_row = $wpdb->get_row( "SELECT * FROM $table_sql WHERE $col_sql REGEXP '^[aiO]:[1-9]' LIMIT 1" ); - - // When the regex triggers an error, we should fall back to PHP - if ( false !== strpos( $wpdb->last_error, 'ERROR 1139' ) ) { + if ( 'sqlite' === Utils\get_db_type() ) { + // SQLite does not support REGEXP by default, fall back to PHP processing. $serial_row = true; + } else { + // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- escaped through self::esc_sql_ident + $serial_row = $wpdb->get_row( "SELECT * FROM $table_sql WHERE $col_sql REGEXP '^[aiO]:[1-9]' LIMIT 1" ); + + // When the regex triggers an error, we should fall back to PHP + if ( false !== strpos( $wpdb->last_error, 'ERROR 1139' ) ) { + $serial_row = true; + } } }