Skip to content

Commit 821a8ce

Browse files
committed
Add support for SHOW COLLATIONS statement
1 parent 3210282 commit 821a8ce

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

tests/WP_SQLite_Driver_Metadata_Tests.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,19 @@ public function testRepairTable() {
467467
);
468468
}
469469

470+
public function testShowCollation(): void {
471+
$this->assertQuery( 'SHOW COLLATION' );
472+
$actual = $this->engine->get_query_results();
473+
$this->assertCount( 7, $actual );
474+
$this->assertEquals( 'binary', $actual[0]->Collation );
475+
$this->assertEquals( 'utf8_bin', $actual[1]->Collation );
476+
$this->assertEquals( 'utf8_general_ci', $actual[2]->Collation );
477+
$this->assertEquals( 'utf8_unicode_ci', $actual[3]->Collation );
478+
$this->assertEquals( 'utf8mb4_bin', $actual[4]->Collation );
479+
$this->assertEquals( 'utf8mb4_unicode_ci', $actual[5]->Collation );
480+
$this->assertEquals( 'utf8mb4_0900_ai_ci', $actual[6]->Collation );
481+
}
482+
470483
public function testShowDatabases(): void {
471484
// Simple.
472485
$this->assertQuery( 'SHOW DATABASES' );

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2200,6 +2200,9 @@ private function execute_show_statement( WP_Parser_Node $node ): void {
22002200
$keyword2 = $tokens[2] ?? null;
22012201

22022202
switch ( $keyword1->id ) {
2203+
case WP_MySQL_Lexer::COLLATION_SYMBOL:
2204+
$this->execute_show_collation_statement();
2205+
return;
22032206
case WP_MySQL_Lexer::DATABASES_SYMBOL:
22042207
$this->execute_show_databases_statement( $node );
22052208
return;
@@ -2267,6 +2270,32 @@ private function execute_show_statement( WP_Parser_Node $node ): void {
22672270
);
22682271
}
22692272

2273+
/**
2274+
* Translate and execute a MySQL SHOW COLLATION statement in SQLite.
2275+
*/
2276+
private function execute_show_collation_statement(): void {
2277+
$definition = $this->information_schema_builder
2278+
->get_computed_information_schema_table_definition( 'collations' );
2279+
2280+
// TODO: LIKE and WHERE clauses.
2281+
2282+
$result = $this->execute_sqlite_query( $definition )->fetchAll( PDO::FETCH_ASSOC );
2283+
2284+
$collations = array();
2285+
foreach ( $result as $row ) {
2286+
$collations[] = (object) array(
2287+
'Collation' => $row['COLLATION_NAME'],
2288+
'Charset' => $row['CHARACTER_SET_NAME'],
2289+
'Id' => $row['ID'],
2290+
'Default' => $row['IS_DEFAULT'],
2291+
'Compiled' => $row['IS_COMPILED'],
2292+
'Sortlen' => $row['SORTLEN'],
2293+
'Pad_attribute' => $row['PAD_ATTRIBUTE'],
2294+
);
2295+
}
2296+
$this->set_results_from_fetched_data( $collations );
2297+
}
2298+
22702299
/**
22712300
* Translate and execute a MySQL SHOW DATABASES statement in SQLite.
22722301
*

0 commit comments

Comments
 (0)