From 817e908f6cec4957daa53556e4a6e310e530fba6 Mon Sep 17 00:00:00 2001 From: Jan Jakes Date: Mon, 19 Jan 2026 17:31:52 +0100 Subject: [PATCH] Add support for SHOW FULL COLUMNS --- .github/workflows/wp-tests-phpunit-run.js | 8 ---- tests/WP_SQLite_Driver_Metadata_Tests.php | 32 +++++++++++++++ .../class-wp-pdo-mysql-on-sqlite.php | 39 +++++++++++++++---- 3 files changed, 63 insertions(+), 16 deletions(-) diff --git a/.github/workflows/wp-tests-phpunit-run.js b/.github/workflows/wp-tests-phpunit-run.js index 6d60f8bb..88502fc4 100644 --- a/.github/workflows/wp-tests-phpunit-run.js +++ b/.github/workflows/wp-tests-phpunit-run.js @@ -44,11 +44,6 @@ const expectedFailures = [ 'Tests_DB_Charset::test_get_column_charset_non_mysql with data set #5', 'Tests_DB_Charset::test_get_column_charset_non_mysql with data set #6', 'Tests_DB_Charset::test_get_column_charset_non_mysql with data set #7', - 'Tests_DB_Charset::test_get_table_charset with data set #1', - 'Tests_DB_Charset::test_get_table_charset with data set #4', - 'Tests_DB_Charset::test_get_table_charset with data set #5', - 'Tests_DB_Charset::test_get_table_charset with data set #6', - 'Tests_DB_Charset::test_get_table_charset with data set #7', 'Tests_DB_Charset::test_process_field_charsets_on_nonexistent_table', 'Tests_DB_Charset::test_strip_invalid_text with data set #21', 'Tests_DB_Charset::test_strip_invalid_text with data set #22', @@ -70,9 +65,6 @@ const expectedFailures = [ 'Tests_DB_Charset::test_strip_invalid_text with data set #40', 'Tests_DB_Charset::test_strip_invalid_text with data set #41', 'Tests_DB_Charset::test_strip_invalid_text_for_column_bails_if_ascii_input_too_long', - 'Tests_DB_Charset::test_strip_invalid_text_from_query with data set "utf8 + utf8mb4"', - 'Tests_DB_Charset::test_table_collation_check with data set "utf8_bin + big5_chinese_ci"', - 'Tests_DB_Charset::test_table_collation_check with data set "utf8_unicode_ci"', 'Tests_DB_dbDelta::test_spatial_indices', 'Tests_DB::test_charset_switched_to_utf8mb4', 'Tests_DB::test_close', diff --git a/tests/WP_SQLite_Driver_Metadata_Tests.php b/tests/WP_SQLite_Driver_Metadata_Tests.php index 9b201905..2b9ca1ed 100644 --- a/tests/WP_SQLite_Driver_Metadata_Tests.php +++ b/tests/WP_SQLite_Driver_Metadata_Tests.php @@ -628,6 +628,38 @@ public function testShowTableStatus() { ); } + public function testShowFullColumns(): void { + $this->assertQuery( "CREATE TABLE t (id INT COMMENT 'Comment ID', name TEXT COMMENT 'Comment Name')" ); + $result = $this->assertQuery( 'SHOW FULL COLUMNS FROM t' ); + $this->assertEquals( + array( + (object) array( + 'Field' => 'id', + 'Type' => 'int', + 'Collation' => null, + 'Null' => 'YES', + 'Key' => '', + 'Default' => null, + 'Extra' => '', + 'Privileges' => 'select,insert,update,references', + 'Comment' => 'Comment ID', + ), + (object) array( + 'Field' => 'name', + 'Type' => 'text', + 'Collation' => 'utf8mb4_0900_ai_ci', + 'Null' => 'YES', + 'Key' => '', + 'Default' => null, + 'Extra' => '', + 'Privileges' => 'select,insert,update,references', + 'Comment' => 'Comment Name', + ), + ), + $result + ); + } + public function testShowColumnsLike(): void { $this->assertQuery( 'CREATE TABLE t (id INT, val1 INT, val2 INT, name TEXT)' ); $result = $this->assertQuery( "SHOW COLUMNS FROM t LIKE 'val%'" ); diff --git a/wp-includes/sqlite-ast/class-wp-pdo-mysql-on-sqlite.php b/wp-includes/sqlite-ast/class-wp-pdo-mysql-on-sqlite.php index 659b3f1c..73e01fa7 100644 --- a/wp-includes/sqlite-ast/class-wp-pdo-mysql-on-sqlite.php +++ b/wp-includes/sqlite-ast/class-wp-pdo-mysql-on-sqlite.php @@ -2897,20 +2897,43 @@ private function execute_show_columns_statement( WP_Parser_Node $node ): void { $condition = $this->translate_show_like_or_where_condition( $like_or_where, 'column_name' ); } + // Handle the FULL keyword. + $command_type = $node->get_first_child_node( 'showCommandType' ); + $is_full = $command_type && $command_type->has_child_token( WP_MySQL_Lexer::FULL_SYMBOL ); + // Fetch column information. $columns_table = $this->information_schema_builder->get_table_name( $table_is_temporary, 'columns' ); - $stmt = $this->execute_sqlite_query( + + if ( $is_full ) { + $fields = ' + column_name AS `Field`, + column_type AS `Type`, + collation_name AS `Collation`, + is_nullable AS `Null`, + column_key AS `Key`, + column_default AS `Default`, + extra AS `Extra`, + privileges AS `Privileges`, + column_comment AS `Comment` + '; + } else { + $fields = ' + column_name AS `Field`, + column_type AS `Type`, + is_nullable AS `Null`, + column_key AS `Key`, + column_default AS `Default`, + extra AS `Extra` + '; + } + + $stmt = $this->execute_sqlite_query( sprintf( - 'SELECT - column_name AS `Field`, - column_type AS `Type`, - is_nullable AS `Null`, - column_key AS `Key`, - column_default AS `Default`, - extra AS `Extra` + 'SELECT %s FROM %s WHERE table_schema = ? AND table_name = ? %s ORDER BY ordinal_position', + $fields, $this->quote_sqlite_identifier( $columns_table ), $condition ?? '' ),