Skip to content

Commit 8b27c85

Browse files
committed
Fix FROM/IN handling for SHOW statements
1 parent f7c99c1 commit 8b27c85

2 files changed

Lines changed: 19 additions & 7 deletions

File tree

tests/WP_SQLite_Driver_Tests.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ public function testShowTableStatusFrom() {
691691
);
692692

693693
$this->assertQuery(
694-
'SHOW TABLE STATUS FROM mydb;'
694+
'SHOW TABLE STATUS FROM wp;'
695695
);
696696

697697
$this->assertCount(
@@ -714,7 +714,7 @@ public function testShowTableStatusIn() {
714714
);
715715

716716
$this->assertQuery(
717-
'SHOW TABLE STATUS IN mydb;'
717+
'SHOW TABLE STATUS IN wp;'
718718
);
719719

720720
$this->assertCount(
@@ -744,7 +744,7 @@ public function testShowTableStatusInTwoTables() {
744744
);"
745745
);
746746
$this->assertQuery(
747-
'SHOW TABLE STATUS IN mydb;'
747+
'SHOW TABLE STATUS IN wp;'
748748
);
749749

750750
$this->assertCount(

wp-includes/sqlite-ast/class-wp-sqlite-driver.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,8 +1273,14 @@ private function execute_show_index_statement( string $table_name ): void {
12731273

12741274
private function execute_show_table_status_statement( WP_Parser_Node $node ): void {
12751275
// FROM/IN database.
1276-
$in_db = $node->get_first_child_node( 'idDb' );
1277-
$database = null === $in_db ? $this->db_name : $this->translate( $in_db );
1276+
$in_db = $node->get_first_child_node( 'inDb' );
1277+
if ( null === $in_db ) {
1278+
$database = $this->db_name;
1279+
} else {
1280+
$database = $this->unquote_sqlite_identifier(
1281+
$this->translate( $in_db->get_first_child_node( 'identifier' ) )
1282+
);
1283+
}
12781284

12791285
// LIKE and WHERE clauses.
12801286
$like_or_where = $node->get_first_child_node( 'likeOrWhere' );
@@ -1325,8 +1331,14 @@ private function execute_show_table_status_statement( WP_Parser_Node $node ): vo
13251331

13261332
private function execute_show_tables_statement( WP_Parser_Node $node ): void {
13271333
// FROM/IN database.
1328-
$in_db = $node->get_first_child_node( 'idDb' );
1329-
$database = null === $in_db ? $this->db_name : $this->translate( $in_db );
1334+
$in_db = $node->get_first_child_node( 'inDb' );
1335+
if ( null === $in_db ) {
1336+
$database = $this->db_name;
1337+
} else {
1338+
$database = $this->unquote_sqlite_identifier(
1339+
$this->translate( $in_db->get_first_child_node( 'identifier' ) )
1340+
);
1341+
}
13301342

13311343
// LIKE and WHERE clauses.
13321344
$like_or_where = $node->get_first_child_node( 'likeOrWhere' );

0 commit comments

Comments
 (0)