Loading core/lib/Drupal/Core/Database/Schema.php +6 −1 Original line number Diff line number Diff line Loading @@ -180,7 +180,12 @@ public function tableExists($table) { * Finds all tables that are like the specified base table name. * * @param string $table_expression * An SQL expression, for example "cache_%" (without the quotes). * A case-insensitive pattern against which table names are compared. Both * '_' and '%' are treated like wildcards in MySQL 'LIKE' expressions, where * '_' matches any single character and '%' matches an arbitrary number of * characters (including zero characters). So 'foo%bar' matches table names * like 'foobar', 'fooXBar', 'fooXBaR', or 'fooXxBar'; whereas 'foo_bar' * matches 'fooXBar' and 'fooXBaR' but not 'fooBar' or 'fooXxxBar'. * * @return array * Both the keys and the values are the matching tables. Loading core/tests/Drupal/KernelTests/Core/Database/SchemaTest.php +55 −0 Original line number Diff line number Diff line Loading @@ -1307,6 +1307,61 @@ public function testFindTables() { 'test_2_table', ]; $this->assertEquals($expected, $tables, 'Two tables were found.'); // Check '_' and '%' wildcards. $test_schema->createTable('test3table', $table_specification); $test_schema->createTable('test4', $table_specification); $test_schema->createTable('testTable', $table_specification); $test_schema->createTable('test', $table_specification); $tables = $test_schema->findTables('test%'); sort($tables); $expected = [ 'test', 'test3table', 'test4', 'testTable', 'test_1_table', 'test_2_table', ]; $this->assertEquals($expected, $tables, 'All "test" prefixed tables were found.'); $tables = $test_schema->findTables('test_%'); sort($tables); $expected = [ 'test3table', 'test4', 'testTable', 'test_1_table', 'test_2_table', ]; $this->assertEquals($expected, $tables, 'All "/^test..*?/" tables were found.'); $tables = $test_schema->findTables('test%table'); sort($tables); $expected = [ 'test3table', 'testTable', 'test_1_table', 'test_2_table', ]; $this->assertEquals($expected, $tables, 'All "/^test.*?table/" tables were found.'); $tables = $test_schema->findTables('test_%table'); sort($tables); $expected = [ 'test3table', 'test_1_table', 'test_2_table', ]; $this->assertEquals($expected, $tables, 'All "/^test..*?table/" tables were found.'); $tables = $test_schema->findTables('test_'); sort($tables); $expected = [ 'test4', ]; $this->assertEquals($expected, $tables, 'All "/^test./" tables were found.'); } /** Loading Loading
core/lib/Drupal/Core/Database/Schema.php +6 −1 Original line number Diff line number Diff line Loading @@ -180,7 +180,12 @@ public function tableExists($table) { * Finds all tables that are like the specified base table name. * * @param string $table_expression * An SQL expression, for example "cache_%" (without the quotes). * A case-insensitive pattern against which table names are compared. Both * '_' and '%' are treated like wildcards in MySQL 'LIKE' expressions, where * '_' matches any single character and '%' matches an arbitrary number of * characters (including zero characters). So 'foo%bar' matches table names * like 'foobar', 'fooXBar', 'fooXBaR', or 'fooXxBar'; whereas 'foo_bar' * matches 'fooXBar' and 'fooXBaR' but not 'fooBar' or 'fooXxxBar'. * * @return array * Both the keys and the values are the matching tables. Loading
core/tests/Drupal/KernelTests/Core/Database/SchemaTest.php +55 −0 Original line number Diff line number Diff line Loading @@ -1307,6 +1307,61 @@ public function testFindTables() { 'test_2_table', ]; $this->assertEquals($expected, $tables, 'Two tables were found.'); // Check '_' and '%' wildcards. $test_schema->createTable('test3table', $table_specification); $test_schema->createTable('test4', $table_specification); $test_schema->createTable('testTable', $table_specification); $test_schema->createTable('test', $table_specification); $tables = $test_schema->findTables('test%'); sort($tables); $expected = [ 'test', 'test3table', 'test4', 'testTable', 'test_1_table', 'test_2_table', ]; $this->assertEquals($expected, $tables, 'All "test" prefixed tables were found.'); $tables = $test_schema->findTables('test_%'); sort($tables); $expected = [ 'test3table', 'test4', 'testTable', 'test_1_table', 'test_2_table', ]; $this->assertEquals($expected, $tables, 'All "/^test..*?/" tables were found.'); $tables = $test_schema->findTables('test%table'); sort($tables); $expected = [ 'test3table', 'testTable', 'test_1_table', 'test_2_table', ]; $this->assertEquals($expected, $tables, 'All "/^test.*?table/" tables were found.'); $tables = $test_schema->findTables('test_%table'); sort($tables); $expected = [ 'test3table', 'test_1_table', 'test_2_table', ]; $this->assertEquals($expected, $tables, 'All "/^test..*?table/" tables were found.'); $tables = $test_schema->findTables('test_'); sort($tables); $expected = [ 'test4', ]; $this->assertEquals($expected, $tables, 'All "/^test./" tables were found.'); } /** Loading