@@ -2230,7 +2230,7 @@ private function execute_show_statement( WP_Parser_Node $node ): void {
22302230
22312231 switch ( $ keyword1 ->id ) {
22322232 case WP_MySQL_Lexer::COLLATION_SYMBOL :
2233- $ this ->execute_show_collation_statement ();
2233+ $ this ->execute_show_collation_statement ( $ node );
22342234 return ;
22352235 case WP_MySQL_Lexer::DATABASES_SYMBOL :
22362236 $ this ->execute_show_databases_statement ( $ node );
@@ -2359,12 +2359,18 @@ private function execute_show_statement( WP_Parser_Node $node ): void {
23592359
23602360 /**
23612361 * Translate and execute a MySQL SHOW COLLATION statement in SQLite.
2362+ *
2363+ * @param WP_Parser_Node $node The "showStatement" AST node.
23622364 */
2363- private function execute_show_collation_statement (): void {
2365+ private function execute_show_collation_statement ( WP_Parser_Node $ node ): void {
23642366 $ definition = $ this ->information_schema_builder
23652367 ->get_computed_information_schema_table_definition ( 'collations ' );
23662368
2367- // TODO: LIKE and WHERE clauses.
2369+ // LIKE and WHERE clauses.
2370+ $ like_or_where = $ node ->get_first_child_node ( 'likeOrWhere ' );
2371+ if ( $ like_or_where ) {
2372+ $ condition = $ this ->translate_show_like_or_where_condition ( $ like_or_where , 'collation_name ' );
2373+ }
23682374
23692375 $ stmt = $ this ->execute_sqlite_query (
23702376 sprintf (
@@ -2376,8 +2382,10 @@ private function execute_show_collation_statement(): void {
23762382 IS_COMPILED AS `Compiled`,
23772383 SORTLEN AS `Sortlen`,
23782384 PAD_ATTRIBUTE AS `Pad_attribute`
2379- FROM (%s) ' ,
2380- $ definition
2385+ FROM (%s)
2386+ WHERE TRUE %s ' ,
2387+ $ definition ,
2388+ $ condition ?? ''
23812389 )
23822390 );
23832391 $ this ->store_last_column_meta_from_statement ( $ stmt );
@@ -2394,10 +2402,9 @@ private function execute_show_databases_statement( WP_Parser_Node $node ): void
23942402
23952403 // LIKE and WHERE clauses.
23962404 $ like_or_where = $ node ->get_first_child_node ( 'likeOrWhere ' );
2397- if ( null !== $ like_or_where ) {
2405+ if ( $ like_or_where ) {
23982406 $ condition = $ this ->translate_show_like_or_where_condition ( $ like_or_where , 'schema_name ' );
23992407 }
2400-
24012408 $ stmt = $ this ->execute_sqlite_query (
24022409 sprintf (
24032410 'SELECT SCHEMA_NAME AS Database
@@ -2424,10 +2431,9 @@ private function execute_show_databases_statement( WP_Parser_Node $node ): void
24242431 * @param WP_Parser_Node $node The "showStatement" AST node.
24252432 */
24262433 private function execute_show_index_statement ( WP_Parser_Node $ node ): void {
2434+ // Get database and table name.
24272435 $ table_ref = $ node ->get_first_child_node ( 'tableRef ' );
24282436 $ in_db = $ node ->get_first_child_node ( 'inDb ' );
2429-
2430- // Get database and table name.
24312437 if ( $ in_db ) {
24322438 // FROM/IN database.
24332439 $ database = $ this ->get_database_name ( $ in_db );
@@ -2436,7 +2442,14 @@ private function execute_show_index_statement( WP_Parser_Node $node ): void {
24362442 }
24372443 $ table_name = $ this ->unquote_sqlite_identifier ( $ this ->translate ( $ table_ref ) );
24382444
2439- // TODO: WHERE
2445+ // WHERE clause.
2446+ $ where = $ node ->get_first_child_node ( 'whereClause ' );
2447+ if ( null !== $ where ) {
2448+ $ value = $ this ->translate ( $ where ->get_first_child_node ( 'expr ' ) );
2449+ $ condition = sprintf ( 'AND %s ' , $ value );
2450+ } else {
2451+ $ condition = '' ;
2452+ }
24402453
24412454 $ table_is_temporary = $ this ->information_schema_builder ->temporary_table_exists ( $ table_name );
24422455
@@ -2480,6 +2493,7 @@ private function execute_show_index_statement( WP_Parser_Node $node ): void {
24802493 FROM ' . $ this ->quote_sqlite_identifier ( $ statistics_table ) . "
24812494 WHERE table_schema = ?
24822495 AND table_name = ?
2496+ $ condition
24832497 ORDER BY
24842498 INDEX_NAME = 'PRIMARY' DESC,
24852499 NON_UNIQUE = '0' DESC,
@@ -2624,10 +2638,10 @@ private function execute_show_tables_statement( WP_Parser_Node $node ): void {
26242638 */
26252639 private function execute_show_columns_statement ( WP_Parser_Node $ node ): void {
26262640 // TODO: EXTENDED, FULL
2627- $ table_ref = $ node ->get_first_child_node ( 'tableRef ' );
2628- $ in_db = $ node ->get_first_child_node ( 'inDb ' );
26292641
26302642 // Get database and table name.
2643+ $ table_ref = $ node ->get_first_child_node ( 'tableRef ' );
2644+ $ in_db = $ node ->get_first_child_node ( 'inDb ' );
26312645 if ( $ in_db ) {
26322646 // FROM/IN database.
26332647 $ database = $ this ->get_database_name ( $ in_db );
0 commit comments