Skip to content
Merged
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
112 changes: 112 additions & 0 deletions tests/WP_SQLite_Driver_Metadata_Tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,105 @@ public function testInformationSchemaQueryHidesSqliteSystemTables() {
$this->assertEquals( 0, count( $result ) );
}

public function testInfromationSchemaCharacterSets(): void {
$result = $this->assertQuery( 'SELECT * FROM INFORMATION_SCHEMA.CHARACTER_SETS ORDER BY CHARACTER_SET_NAME' );
$this->assertEquals(
array(
(object) array(
'CHARACTER_SET_NAME' => 'binary',
'DEFAULT_COLLATE_NAME' => 'binary',
'DESCRIPTION' => 'Binary pseudo charset',
'MAXLEN' => '1',
),
(object) array(
'CHARACTER_SET_NAME' => 'utf8',
'DEFAULT_COLLATE_NAME' => 'utf8_general_ci',
'DESCRIPTION' => 'UTF-8 Unicode',
'MAXLEN' => '3',
),
(object) array(
'CHARACTER_SET_NAME' => 'utf8mb4',
'DEFAULT_COLLATE_NAME' => 'utf8mb4_0900_ai_ci',
'DESCRIPTION' => 'UTF-8 Unicode',
'MAXLEN' => '4',
),
),
$result
);
}

public function testInfromationSchemaCollations(): void {
$result = $this->assertQuery( 'SELECT * FROM INFORMATION_SCHEMA.COLLATIONS ORDER BY COLLATION_NAME' );
$this->assertEquals(
array(
(object) array(
'COLLATION_NAME' => 'binary',
'CHARACTER_SET_NAME' => 'binary',
'ID' => '63',
'IS_DEFAULT' => 'Yes',
'IS_COMPILED' => 'Yes',
'SORTLEN' => '1',
'PAD_ATTRIBUTE' => 'NO PAD',
),
(object) array(
'COLLATION_NAME' => 'utf8_bin',
'CHARACTER_SET_NAME' => 'utf8',
'ID' => '83',
'IS_DEFAULT' => '',
'IS_COMPILED' => 'Yes',
'SORTLEN' => '1',
'PAD_ATTRIBUTE' => 'PAD SPACE',
),
(object) array(
'COLLATION_NAME' => 'utf8_general_ci',
'CHARACTER_SET_NAME' => 'utf8',
'ID' => '33',
'IS_DEFAULT' => 'Yes',
'IS_COMPILED' => 'Yes',
'SORTLEN' => '1',
'PAD_ATTRIBUTE' => 'PAD SPACE',
),
(object) array(
'COLLATION_NAME' => 'utf8_unicode_ci',
'CHARACTER_SET_NAME' => 'utf8',
'ID' => '192',
'IS_DEFAULT' => '',
'IS_COMPILED' => 'Yes',
'SORTLEN' => '8',
'PAD_ATTRIBUTE' => 'PAD SPACE',
),
(object) array(
'COLLATION_NAME' => 'utf8mb4_0900_ai_ci',
'CHARACTER_SET_NAME' => 'utf8mb4',
'ID' => '255',
'IS_DEFAULT' => 'Yes',
'IS_COMPILED' => 'Yes',
'SORTLEN' => '0',
'PAD_ATTRIBUTE' => 'NO PAD',
),
(object) array(
'COLLATION_NAME' => 'utf8mb4_bin',
'CHARACTER_SET_NAME' => 'utf8mb4',
'ID' => '46',
'IS_DEFAULT' => '',
'IS_COMPILED' => 'Yes',
'SORTLEN' => '1',
'PAD_ATTRIBUTE' => 'PAD SPACE',
),
(object) array(
'COLLATION_NAME' => 'utf8mb4_unicode_ci',
'CHARACTER_SET_NAME' => 'utf8mb4',
'ID' => '224',
'IS_DEFAULT' => '',
'IS_COMPILED' => 'Yes',
'SORTLEN' => '8',
'PAD_ATTRIBUTE' => 'PAD SPACE',
),
),
$result
);
}

public function testUseStatement() {
$this->assertQuery( 'CREATE TABLE tables (ENGINE TEXT)' );
$this->assertQuery( "INSERT INTO tables (ENGINE) VALUES ('test')" );
Expand Down Expand Up @@ -368,6 +467,19 @@ public function testRepairTable() {
);
}

public function testShowCollation(): void {
$this->assertQuery( 'SHOW COLLATION' );
$actual = $this->engine->get_query_results();
$this->assertCount( 7, $actual );
$this->assertEquals( 'binary', $actual[0]->Collation );
$this->assertEquals( 'utf8_bin', $actual[1]->Collation );
$this->assertEquals( 'utf8_general_ci', $actual[2]->Collation );
$this->assertEquals( 'utf8_unicode_ci', $actual[3]->Collation );
$this->assertEquals( 'utf8mb4_bin', $actual[4]->Collation );
$this->assertEquals( 'utf8mb4_unicode_ci', $actual[5]->Collation );
$this->assertEquals( 'utf8mb4_0900_ai_ci', $actual[6]->Collation );
}

public function testShowDatabases(): void {
// Simple.
$this->assertQuery( 'SHOW DATABASES' );
Expand Down
86 changes: 79 additions & 7 deletions tests/WP_SQLite_Driver_Tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -6033,6 +6033,14 @@ public function testSetStatement(): void {
$this->assertQuery( 'SET CHARACTER SET utf8mb4' );
}

public function testBuiltInSystemVariables(): void {
$result = $this->assertQuery( 'SELECT @@version' );
$this->assertSame( '8.0.38', $result[0]->{'@@version'} );

$result = $this->assertQuery( 'SELECT @@version_comment' );
$this->assertSame( 'MySQL Community Server - GPL', $result[0]->{'@@version_comment'} );
}

public function testSessionSystemVariables(): void {
$this->assertQuery( "SET character_set_client = 'latin1'" );
$result = $this->assertQuery( 'SELECT @@character_set_client' );
Expand Down Expand Up @@ -8395,22 +8403,22 @@ public function testColumnInfoForExpressions(): void {
),
array(
// "CAST('2024-01-01' AS DATE)" seems to behave differently in SQLite.
'native_type' => 'LONGLONG', // "DATE" in MySQL.
'pdo_type' => PDO::PARAM_INT, // PARAM_STR in MySQL.
'native_type' => 'VAR_STRING', // "DATE" in MySQL.
'pdo_type' => PDO::PARAM_STR,
'flags' => array( 'not_null' ), // Empty in MySQL.
'table' => '',
'name' => 'col_expr_11',
'len' => 21, // 10 in MySQL.
'precision' => 0,
'len' => 65535, // 10 in MySQL.
'precision' => 31, // 0 in MySQL.
'sqlite:decl_type' => '',

// Additional MySQLi metadata.
'mysqli:orgname' => 'col_expr_11',
'mysqli:orgtable' => '',
'mysqli:db' => 'wp',
'mysqli:charsetnr' => 63,
'mysqli:flags' => 0, // 128 in MySQL.
'mysqli:type' => 8, // 10 in MySQL.
'mysqli:charsetnr' => 255, // 63 in MySQL.
'mysqli:flags' => 0, // 128 in MySQL.
'mysqli:type' => 253, // 10 in MySQL.
),
array(
'native_type' => 'VAR_STRING',
Expand Down Expand Up @@ -9366,5 +9374,69 @@ public function testDynamicDatabaseNameWithUseStatement(): void {
$result = $this->assertQuery( 'SELECT * FROM information_schema.tables' );
$this->assertCount( 1, $result );
$this->assertEquals( 'tables', $result[0]->TABLE_NAME );

// Switch back to the "wp" database.
$this->assertQuery( 'USE wp' );

// Now, unqualified "tables" refers to the "wp.tables".
$result = $this->assertQuery( 'SELECT * FROM tables' );
$this->assertCount( 2, $result );
$this->assertEquals( array( (object) array( 'id' => '1' ), (object) array( 'id' => '2' ) ), $result );

// Qualified references should still work.
$result = $this->assertQuery( 'SELECT * FROM wp.tables' );
$this->assertCount( 2, $result );
$this->assertEquals( array( (object) array( 'id' => '1' ), (object) array( 'id' => '2' ) ), $result );

$result = $this->assertQuery( 'SELECT * FROM information_schema.tables' );
$this->assertCount( 1, $result );
$this->assertEquals( 'tables', $result[0]->TABLE_NAME );
}

public function testCastExpression(): void {
$result = $this->assertQuery(
"SELECT
CAST('abc' AS BINARY) AS expr_1,
CAST('abc' AS BINARY(2)) AS expr_2,
CAST('abc' AS CHAR) AS expr_3,
CAST('abc' AS CHAR(2) CHARACTER SET utf8 BINARY)AS expr_4,
CAST('abc' AS NCHAR)AS expr_5,
CAST('abc' AS NATIONAL CHAR (2)) AS expr_6,
CAST('-10' AS SIGNED) AS expr_7,
CAST('-10' AS UNSIGNED INT) AS expr_8,
CAST('2025-10-05 14:05:28' AS DATE) AS expr_9,
CAST('2025-10-05 14:05:28' AS TIME) AS expr_10,
CAST('2025-10-05 14:05:28' AS DATETIME) AS expr_11,
CAST('123.456' AS DECIMAL(10,1)) AS expr_12,
CAST('123.456' AS FLOAT) AS expr_13,
CAST('123.456' AS REAL) AS expr_14,
CAST('123.456' AS DOUBLE) AS expr_15,
CAST('{\"name\":\"value\"}' AS JSON) AS expr_16
"
);

$this->assertEquals(
array(
(object) array(
'expr_1' => 'abc',
'expr_2' => 'abc', // 'ab' In MySQL
'expr_3' => 'abc',
'expr_4' => 'abc', // 'ab' In MySQL
'expr_5' => 'abc',
'expr_6' => 'abc', // 'ab' In MySQL
'expr_7' => '-10',
'expr_8' => '-10', // 18446744073709551606 in MySQL
'expr_9' => '2025-10-05 14:05:28', // 2025-10-05 in MySQL
'expr_10' => '2025-10-05 14:05:28', // 14:05:28 in MySQL
'expr_11' => '2025-10-05 14:05:28',
'expr_12' => '123.456', // 123.5 in MySQL
'expr_13' => '123.456',
'expr_14' => '123.456',
'expr_15' => '123.456',
'expr_16' => '{"name":"value"}',
),
),
$result
);
}
}
Loading
Loading