@@ -258,7 +258,7 @@ public function testShowCreateTable1() {
258258 PRIMARY KEY (`ID`),
259259 UNIQUE KEY `option_name` (`option_name`),
260260 KEY `composite` (`option_name`, `option_value`)
261- ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci " ,
261+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci " ,
262262 $ results [0 ]->{'Create Table ' }
263263 );
264264 }
@@ -286,7 +286,7 @@ public function testShowCreateTableQuoted() {
286286 PRIMARY KEY (`ID`),
287287 UNIQUE KEY `option_name` (`option_name`),
288288 KEY `composite` (`option_name`, `option_value`)
289- ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci " ,
289+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci " ,
290290 $ results [0 ]->{'Create Table ' }
291291 );
292292 }
@@ -305,7 +305,7 @@ public function testShowCreateTableSimpleTable() {
305305 $ this ->assertEquals (
306306 'CREATE TABLE `_tmp_table` (
307307 `ID` bigint NOT NULL
308- ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ' ,
308+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci ' ,
309309 $ results [0 ]->{'Create Table ' }
310310 );
311311 }
@@ -338,7 +338,7 @@ public function testShowCreateTableWithAlterAndCreateIndex() {
338338 `option_value` text NOT NULL,
339339 PRIMARY KEY (`ID`),
340340 KEY `option_name` (`option_name`)
341- ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ' ,
341+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci ' ,
342342 $ results [0 ]->{'Create Table ' }
343343 );
344344 }
@@ -389,7 +389,7 @@ public function testShowCreateTableWithComments(): void {
389389 " `special_chars_12` text NOT NULL COMMENT '🙂', " ,
390390 " `special_chars_13` text NOT NULL COMMENT '🙂', " ,
391391 " KEY `idx_id` (`id`) COMMENT 'Index comment' " ,
392- ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='Table comment' " ,
392+ ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='Table comment' " ,
393393 )
394394 ),
395395 $ results [0 ]->{'Create Table ' }
@@ -441,7 +441,7 @@ public function testShowCreateTablePreservesDoubleUnderscoreKeyNames() {
441441 PRIMARY KEY (`ID`),
442442 KEY `option_name` (`option_name`),
443443 KEY `double__underscores` (`option_name`, `ID`)
444- ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ' ,
444+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci ' ,
445445 $ results [0 ]->{'Create Table ' }
446446 );
447447 }
@@ -466,7 +466,7 @@ public function testShowCreateTableWithPrimaryKeyColumnsReverseOrdered() {
466466 `ID_B` bigint NOT NULL,
467467 `ID_C` bigint NOT NULL,
468468 PRIMARY KEY (`ID_B`, `ID_A`, `ID_C`)
469- ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ' ,
469+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci ' ,
470470 $ results [0 ]->{'Create Table ' }
471471 );
472472 }
@@ -532,7 +532,7 @@ public function testShowCreateTableWithDefaultValues(): void {
532532 " `special_chars_12` text NOT NULL COMMENT '🙂', " ,
533533 " `special_chars_13` text NOT NULL COMMENT '🙂', " ,
534534 ' PRIMARY KEY (`ID`) ' ,
535- ') ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ' ,
535+ ') ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci ' ,
536536 )
537537 ),
538538 $ results [0 ]->{'Create Table ' }
@@ -1964,7 +1964,7 @@ public function testAlterTableAddIndexWithOrder(): void {
19641964 ' `id` int DEFAULT NULL, ' ,
19651965 ' `value` varchar(255) DEFAULT NULL, ' ,
19661966 ' KEY `idx_value` (`value` DESC) ' ,
1967- ') ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ' ,
1967+ ') ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci ' ,
19681968 )
19691969 ),
19701970 $ result [0 ]->{'Create Table ' }
@@ -3937,7 +3937,7 @@ public function testColumnDefaults(): void {
39373937 . " `description` varchar(250) NOT NULL DEFAULT '', \n"
39383938 . " `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP, \n"
39393939 . " `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP \n"
3940- . ') ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ' ,
3940+ . ') ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci ' ,
39413941 $ result [0 ]->{'Create Table ' }
39423942 );
39433943 }
@@ -4050,7 +4050,7 @@ public function testShowCreateTableWithEmptyDatetimeDefault() {
40504050 `notempty4` year DEFAULT '2024',
40514051 `notempty5` timestamp NULL DEFAULT '1999-12-12 12:12:12',
40524052 PRIMARY KEY (`ID`)
4053- ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci " ,
4053+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci " ,
40544054 $ results [0 ]->{'Create Table ' }
40554055 );
40564056 }
@@ -4085,7 +4085,7 @@ public function testShowCreateTablePreservesKeyLengths() {
40854085 KEY `meta_key_value` (`meta_key`(20), `meta_value`(82)),
40864086 KEY `order_id_meta_key_meta_value` (`order_id`, `meta_key`(100), `meta_value`(82)),
40874087 KEY `order_id_meta_key_meta_data` (`order_id`, `meta_key`(100), `meta_data`(100))
4088- ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ' ,
4088+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci ' ,
40894089 $ results [0 ]->{'Create Table ' }
40904090 );
40914091 }
@@ -4225,7 +4225,7 @@ public function testTemporaryTableHasPriorityOverStandardTable(): void {
42254225 "CREATE TEMPORARY TABLE `t` ( \n"
42264226 . " `b` int DEFAULT NULL, \n"
42274227 . " KEY `ib` (`b`) \n"
4228- . ') ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ' ,
4228+ . ') ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci ' ,
42294229 $ result [0 ]->{'Create Table ' }
42304230 );
42314231
@@ -5015,7 +5015,7 @@ public function testIndexNamePrecedesConstraintName(): void {
50155015 'CREATE TABLE `t` ( ' ,
50165016 ' `id` int DEFAULT NULL, ' ,
50175017 ' UNIQUE KEY `idx_id` (`id`) ' ,
5018- ') ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ' ,
5018+ ') ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci ' ,
50195019 )
50205020 ),
50215021 $ result [0 ]->{'Create Table ' }
@@ -5641,7 +5641,7 @@ public function testCreateIndexWithOrder(): void {
56415641 ' `id` int DEFAULT NULL, ' ,
56425642 ' `value` varchar(255) DEFAULT NULL, ' ,
56435643 ' KEY `idx_value` (`value` DESC) ' ,
5644- ') ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ' ,
5644+ ') ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci ' ,
56455645 )
56465646 ),
56475647 $ result [0 ]->{'Create Table ' }
@@ -5741,7 +5741,7 @@ public function testCreateComplexIndex(): void {
57415741 ' `created_at` datetime DEFAULT NULL, ' ,
57425742 ' PRIMARY KEY (`id`), ' ,
57435743 " UNIQUE KEY `idx_complex` (`score`, `name`(16) DESC, `created_at` DESC) COMMENT 'Test comment' " ,
5744- ') ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ' ,
5744+ ') ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci ' ,
57455745 )
57465746 ),
57475747 $ result [0 ]->{'Create Table ' }
@@ -5975,4 +5975,49 @@ public function testComplexInformationSchemaQueries(): void {
59755975 $ this ->assertCount ( 1 , $ result );
59765976 $ this ->assertEquals ( $ create_table_query , $ result [0 ]->{'Create Table ' } );
59775977 }
5978+
5979+ public function testDatabaseNameEmpty (): void {
5980+ $ pdo = new PDO ( 'sqlite::memory: ' );
5981+ $ connection = new WP_SQLite_Connection ( array ( 'pdo ' => $ pdo ) );
5982+
5983+ $ this ->expectException ( WP_SQLite_Driver_Exception::class );
5984+ $ this ->expectExceptionMessage ( 'The database name cannot be empty. ' );
5985+ new WP_SQLite_Driver ( $ connection , '' );
5986+ }
5987+
5988+ public function testDatabaseNameMismatch (): void {
5989+ $ pdo = new PDO ( 'sqlite::memory: ' );
5990+ $ connection = new WP_SQLite_Connection ( array ( 'pdo ' => $ pdo ) );
5991+
5992+ // Create a driver with database name 'db-one'.
5993+ new WP_SQLite_Driver ( $ connection , 'db-one ' );
5994+
5995+ // Create another driver with the same name - no errors.
5996+ new WP_SQLite_Driver ( $ connection , 'db-one ' );
5997+
5998+ // Create a driver with a different name - failure.
5999+ $ this ->expectException ( WP_SQLite_Driver_Exception::class );
6000+ $ this ->expectExceptionMessage ( "Incorrect database name. The database was created with name 'db-one', but 'db-two' is used in the current session. " );
6001+ new WP_SQLite_Driver ( $ connection , 'db-two ' );
6002+ }
6003+
6004+ public function testDatabaseNameMismatchWithExistingInformationSchemaTableData (): void {
6005+ $ pdo = new PDO ( 'sqlite::memory: ' );
6006+ $ connection = new WP_SQLite_Connection ( array ( 'pdo ' => $ pdo ) );
6007+
6008+ // Create a driver with database name 'db-one'.
6009+ $ driver = new WP_SQLite_Driver ( $ connection , 'db-one ' );
6010+
6011+ // Create a table so that there is a record in the information schema.
6012+ $ driver ->query ( 'CREATE TABLE t (id INT) ' );
6013+
6014+ // Delete all variables, including driver version and database name.
6015+ $ pdo ->exec ( sprintf ( 'DELETE FROM %s ' , WP_SQLite_Driver::GLOBAL_VARIABLES_TABLE_NAME ) );
6016+
6017+ // Create a driver with a different name - failure.
6018+ // An information schema record with a different database name already exists.
6019+ $ this ->expectException ( WP_SQLite_Driver_Exception::class );
6020+ $ this ->expectExceptionMessage ( "Incorrect database name. The database was created with name 'db-one', but 'db-two' is used in the current session. " );
6021+ new WP_SQLite_Driver ( $ connection , 'db-two ' );
6022+ }
59786023}
0 commit comments