Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions tests/WP_SQLite_Driver_Metadata_Tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -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%'" );
Expand Down
39 changes: 31 additions & 8 deletions wp-includes/sqlite-ast/class-wp-pdo-mysql-on-sqlite.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?? ''
),
Expand Down
Loading