@@ -33,37 +33,34 @@ protected function get_pdo() {
3333 /**
3434 * Lists all tables in the SQLite database.
3535 *
36- * @param string |null $pattern Optional wildcard pattern to filter tables.
36+ * @param array |null $patterns Optional wildcard patterns to filter tables.
3737 * @param array $assoc_args Associative array of options.
3838 * @return void
3939 */
40- public function run ( $ pattern = null , $ assoc_args = [] ) {
40+ public function run ( ? array $ patterns = null , $ assoc_args = [] ) {
4141 $ pdo = $ this ->get_pdo ();
4242
4343 // Get all tables
4444 $ stmt = $ pdo ->query ( "SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%' " );
4545 $ tables = $ stmt ->fetchAll ( PDO ::FETCH_COLUMN );
4646
4747 // Filter tables if wildcard pattern is provided
48- if ( $ pattern ) {
49- $ sql_pattern = str_replace ( '? ' , '_ ' , $ pattern );
50- $ sql_pattern = str_replace ( '* ' , '% ' , $ sql_pattern );
51-
52- $ tables = array_filter (
53- $ tables ,
54- function ( $ table ) use ( $ pattern ) {
55- return fnmatch ( $ pattern , $ table , FNM_CASEFOLD );
56- }
57- );
48+ if ( ! empty ( $ patterns ) ) {
49+ foreach ( $ patterns as $ pattern ) {
50+ $ tables = array_filter (
51+ $ tables ,
52+ fn ( $ table ) => fnmatch ( $ pattern , $ table , FNM_CASEFOLD )
53+ );
54+ }
5855 }
5956
6057 // Remove system tables
6158 $ tables_to_exclude = array ( '_mysql_data_types_cache ' );
6259 $ tables = array_diff ( $ tables , $ tables_to_exclude );
6360
6461 if ( empty ( $ tables ) ) {
65- if ( $ pattern ) {
66- WP_CLI ::error ( 'No tables found matching: ' . $ pattern );
62+ if ( ! empty ( $ patterns ) ) {
63+ WP_CLI ::error ( 'No tables found. ' );
6764 } else {
6865 WP_CLI ::error ( 'No tables found in the database. ' );
6966 }
0 commit comments