Skip to content

Commit 04d7c17

Browse files
committed
wip
1 parent 0025f57 commit 04d7c17

File tree

3 files changed

+1277
-277
lines changed

3 files changed

+1277
-277
lines changed

tests/WP_SQLite_Driver_Tests.php

Lines changed: 75 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
require_once __DIR__ . '/WP_SQLite_Translator_Tests.php';
44
require_once __DIR__ . '/../wp-includes/sqlite-ast/class-wp-sqlite-driver.php';
5+
require_once __DIR__ . '/../wp-includes/sqlite-ast/class-wp-sqlite-information-schema-builder.php';
56
require_once __DIR__ . '/../wp-includes/sqlite-ast/class-wp-sqlite-expression.php';
67
require_once __DIR__ . '/../wp-includes/sqlite-ast/class-wp-sqlite-token-factory.php';
78
require_once __DIR__ . '/../wp-includes/sqlite-ast/class-wp-sqlite-token.php';
@@ -39,7 +40,7 @@ public static function setUpBeforeClass(): void {
3940
public function setUp(): void {
4041
$this->sqlite = new PDO( 'sqlite::memory:' );
4142

42-
$this->engine = new WP_SQLite_Driver( $this->sqlite );
43+
$this->engine = new WP_SQLite_Driver( 'wp', $this->sqlite );
4344
$this->engine->query(
4445
"CREATE TABLE _options (
4546
ID INTEGER PRIMARY KEY AUTO_INCREMENT NOT NULL,
@@ -287,13 +288,13 @@ public function testShowCreateTable1() {
287288
# TODO: Should we fix mismatch with original `option_value` text NOT NULL,` without default?
288289
$this->assertEquals(
289290
"CREATE TABLE `_tmp_table` (
290-
`ID` bigint NOT NULL AUTO_INCREMENT,
291-
`option_name` varchar(255) DEFAULT '',
292-
`option_value` text NOT NULL DEFAULT '',
293-
PRIMARY KEY (`ID`),
294-
KEY `composite` (`option_name`, `option_value`),
295-
UNIQUE KEY `option_name` (`option_name`)
296-
);",
291+
`ID` bigint NOT NULL AUTO_INCREMENT,
292+
`option_name` varchar(255) DEFAULT '',
293+
`option_value` text NOT NULL,
294+
PRIMARY KEY (`ID`),
295+
UNIQUE KEY `option_name` (`option_name`),
296+
KEY `composite` (`option_name`, `option_value`)
297+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci",
297298
$results[0]->{'Create Table'}
298299
);
299300
}
@@ -316,13 +317,13 @@ public function testShowCreateTableQuoted() {
316317
# TODO: Should we fix mismatch with original `option_value` text NOT NULL,` without default?
317318
$this->assertEquals(
318319
"CREATE TABLE `_tmp_table` (
319-
`ID` bigint NOT NULL AUTO_INCREMENT,
320-
`option_name` varchar(255) DEFAULT '',
321-
`option_value` text NOT NULL DEFAULT '',
322-
PRIMARY KEY (`ID`),
323-
KEY `composite` (`option_name`, `option_value`),
324-
UNIQUE KEY `option_name` (`option_name`)
325-
);",
320+
`ID` bigint NOT NULL AUTO_INCREMENT,
321+
`option_name` varchar(255) DEFAULT '',
322+
`option_value` text NOT NULL,
323+
PRIMARY KEY (`ID`),
324+
UNIQUE KEY `option_name` (`option_name`),
325+
KEY `composite` (`option_name`, `option_value`)
326+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci",
326327
$results[0]->{'Create Table'}
327328
);
328329
}
@@ -340,8 +341,8 @@ public function testShowCreateTableSimpleTable() {
340341
$results = $this->engine->get_query_results();
341342
$this->assertEquals(
342343
'CREATE TABLE `_tmp_table` (
343-
`ID` bigint NOT NULL DEFAULT 0
344-
);',
344+
`ID` bigint NOT NULL
345+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci',
345346
$results[0]->{'Create Table'}
346347
);
347348
}
@@ -369,12 +370,12 @@ public function testShowCreateTableWithAlterAndCreateIndex() {
369370
$results = $this->engine->get_query_results();
370371
$this->assertEquals(
371372
'CREATE TABLE `_tmp_table` (
372-
`ID` bigint NOT NULL AUTO_INCREMENT,
373-
`option_name` smallint NOT NULL DEFAULT 14,
374-
`option_value` text NOT NULL DEFAULT \'\',
375-
PRIMARY KEY (`ID`),
376-
KEY `option_name` (`option_name`)
377-
);',
373+
`ID` bigint NOT NULL AUTO_INCREMENT,
374+
`option_name` smallint NOT NULL DEFAULT \'14\',
375+
`option_value` text NOT NULL,
376+
PRIMARY KEY (`ID`),
377+
KEY `option_name` (`option_name`)
378+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci',
378379
$results[0]->{'Create Table'}
379380
);
380381
}
@@ -418,13 +419,13 @@ public function testShowCreateTablePreservesDoubleUnderscoreKeyNames() {
418419
$results = $this->engine->get_query_results();
419420
$this->assertEquals(
420421
'CREATE TABLE `_tmp__table` (
421-
`ID` bigint NOT NULL AUTO_INCREMENT,
422-
`option_name` varchar(255) DEFAULT \'\',
423-
`option_value` text NOT NULL DEFAULT \'\',
424-
PRIMARY KEY (`ID`),
425-
KEY `double__underscores` (`option_name`, `ID`),
426-
KEY `option_name` (`option_name`)
427-
);',
422+
`ID` bigint NOT NULL AUTO_INCREMENT,
423+
`option_name` varchar(255) DEFAULT \'\',
424+
`option_value` text NOT NULL,
425+
PRIMARY KEY (`ID`),
426+
KEY `option_name` (`option_name`),
427+
KEY `double__underscores` (`option_name`, `ID`)
428+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci',
428429
$results[0]->{'Create Table'}
429430
);
430431
}
@@ -445,11 +446,11 @@ public function testShowCreateTableWithPrimaryKeyColumnsReverseOrdered() {
445446
$results = $this->engine->get_query_results();
446447
$this->assertEquals(
447448
'CREATE TABLE `_tmp_table` (
448-
`ID_A` bigint NOT NULL DEFAULT 0,
449-
`ID_B` bigint NOT NULL DEFAULT 0,
450-
`ID_C` bigint NOT NULL DEFAULT 0,
451-
PRIMARY KEY (`ID_B`, `ID_A`, `ID_C`)
452-
);',
449+
`ID_A` bigint NOT NULL,
450+
`ID_B` bigint NOT NULL,
451+
`ID_C` bigint NOT NULL,
452+
PRIMARY KEY (`ID_B`, `ID_A`, `ID_C`)
453+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci',
453454
$results[0]->{'Create Table'}
454455
);
455456
}
@@ -480,11 +481,11 @@ public function testShowCreateTableWithCorrectDefaultValues() {
480481
$results = $this->engine->get_query_results();
481482
$this->assertEquals(
482483
'CREATE TABLE `_tmp__table` (
483-
`ID` bigint NOT NULL AUTO_INCREMENT,
484-
`default_empty_string` varchar(255) DEFAULT \'\',
485-
`null_no_default` varchar(255),
486-
PRIMARY KEY (`ID`)
487-
);',
484+
`ID` bigint NOT NULL AUTO_INCREMENT,
485+
`default_empty_string` varchar(255) DEFAULT \'\',
486+
`null_no_default` varchar(255),
487+
PRIMARY KEY (`ID`)
488+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci',
488489
$results[0]->{'Create Table'}
489490
);
490491
}
@@ -847,8 +848,8 @@ enum_column ENUM('a', 'b', 'c') NOT NULL DEFAULT 'a',
847848
'Type' => 'bigint(20) unsigned',
848849
'Null' => 'NO',
849850
'Key' => 'PRI',
850-
'Default' => '0',
851-
'Extra' => '',
851+
'Default' => null,
852+
'Extra' => 'auto_increment',
852853
),
853854
(object) array(
854855
'Field' => 'decimal_column',
@@ -1051,7 +1052,7 @@ public function testColumnWithOnUpdate() {
10511052
'Type' => 'int(11)',
10521053
'Null' => 'NO',
10531054
'Key' => '',
1054-
'Default' => '0',
1055+
'Default' => null,
10551056
'Extra' => '',
10561057
),
10571058
(object) array(
@@ -1060,7 +1061,7 @@ public function testColumnWithOnUpdate() {
10601061
'Null' => 'YES',
10611062
'Key' => '',
10621063
'Default' => null,
1063-
'Extra' => '',
1064+
'Extra' => 'on update CURRENT_TIMESTAMP',
10641065
),
10651066
),
10661067
$results
@@ -1078,7 +1079,7 @@ public function testColumnWithOnUpdate() {
10781079
'Type' => 'int(11)',
10791080
'Null' => 'NO',
10801081
'Key' => '',
1081-
'Default' => '0',
1082+
'Default' => null,
10821083
'Extra' => '',
10831084
),
10841085
(object) array(
@@ -1087,15 +1088,15 @@ public function testColumnWithOnUpdate() {
10871088
'Null' => 'YES',
10881089
'Key' => '',
10891090
'Default' => null,
1090-
'Extra' => '',
1091+
'Extra' => 'on update CURRENT_TIMESTAMP',
10911092
),
10921093
(object) array(
10931094
'Field' => 'updated_at',
10941095
'Type' => 'timestamp',
10951096
'Null' => 'YES',
10961097
'Key' => '',
10971098
'Default' => null,
1098-
'Extra' => '',
1099+
'Extra' => 'on update CURRENT_TIMESTAMP',
10991100
),
11001101
),
11011102
$results
@@ -1220,7 +1221,7 @@ public function testChangeColumnWithOnUpdate() {
12201221
'Type' => 'int(11)',
12211222
'Null' => 'NO',
12221223
'Key' => '',
1223-
'Default' => '0',
1224+
'Default' => null,
12241225
'Extra' => '',
12251226
),
12261227
(object) array(
@@ -1253,7 +1254,7 @@ public function testChangeColumnWithOnUpdate() {
12531254
'Type' => 'int(11)',
12541255
'Null' => 'NO',
12551256
'Key' => '',
1256-
'Default' => '0',
1257+
'Default' => null,
12571258
'Extra' => '',
12581259
),
12591260
(object) array(
@@ -1262,7 +1263,7 @@ public function testChangeColumnWithOnUpdate() {
12621263
'Null' => 'YES',
12631264
'Key' => '',
12641265
'Default' => null,
1265-
'Extra' => '',
1266+
'Extra' => 'on update CURRENT_TIMESTAMP',
12661267
),
12671268
),
12681269
$results
@@ -1285,7 +1286,7 @@ public function testChangeColumnWithOnUpdate() {
12851286
'Type' => 'int(11)',
12861287
'Null' => 'NO',
12871288
'Key' => '',
1288-
'Default' => '0',
1289+
'Default' => null,
12891290
'Extra' => '',
12901291
),
12911292
(object) array(
@@ -1327,15 +1328,15 @@ public function testAlterTableWithColumnFirstAndAfter() {
13271328
'Type' => 'int(11)',
13281329
'Null' => 'NO',
13291330
'Key' => '',
1330-
'Default' => '0',
1331+
'Default' => null,
13311332
'Extra' => '',
13321333
),
13331334
(object) array(
13341335
'Field' => 'name',
13351336
'Type' => 'varchar(20)',
13361337
'Null' => 'NO',
13371338
'Key' => '',
1338-
'Default' => null,
1339+
'Default' => '',
13391340
'Extra' => '',
13401341
),
13411342
(object) array(
@@ -1362,7 +1363,7 @@ public function testAlterTableWithColumnFirstAndAfter() {
13621363
'Type' => 'int(11)',
13631364
'Null' => 'NO',
13641365
'Key' => '',
1365-
'Default' => '0',
1366+
'Default' => null,
13661367
'Extra' => '',
13671368
),
13681369
(object) array(
@@ -1456,7 +1457,7 @@ public function testAlterTableWithColumnFirstAndAfter() {
14561457
'Type' => 'varchar(20)',
14571458
'Null' => 'NO',
14581459
'Key' => '',
1459-
'Default' => null,
1460+
'Default' => '',
14601461
'Extra' => '',
14611462
),
14621463
(object) array(
@@ -1502,7 +1503,7 @@ public function testAlterTableWithMultiColumnFirstAndAfter() {
15021503
'Type' => 'int(11)',
15031504
'Null' => 'NO',
15041505
'Key' => '',
1505-
'Default' => '0',
1506+
'Default' => null,
15061507
'Extra' => '',
15071508
),
15081509
(object) array(
@@ -1548,7 +1549,7 @@ public function testAlterTableWithMultiColumnFirstAndAfter() {
15481549
'Type' => 'int(11)',
15491550
'Null' => 'NO',
15501551
'Key' => '',
1551-
'Default' => '0',
1552+
'Default' => null,
15521553
'Extra' => '',
15531554
),
15541555
(object) array(
@@ -1599,7 +1600,7 @@ public function testAlterTableAddIndex() {
15991600
'Table' => '_tmp_table',
16001601
'Non_unique' => '1',
16011602
'Key_name' => 'name',
1602-
'Seq_in_index' => '0',
1603+
'Seq_in_index' => '1',
16031604
'Column_name' => 'name',
16041605
'Collation' => 'A',
16051606
'Cardinality' => '0',
@@ -1609,6 +1610,8 @@ public function testAlterTableAddIndex() {
16091610
'Index_type' => 'BTREE',
16101611
'Comment' => '',
16111612
'Index_comment' => '',
1613+
'Visible' => 'YES',
1614+
'Expression' => null,
16121615
),
16131616
),
16141617
$results
@@ -1634,16 +1637,18 @@ public function testAlterTableAddUniqueIndex() {
16341637
'Table' => '_tmp_table',
16351638
'Non_unique' => '0',
16361639
'Key_name' => 'name',
1637-
'Seq_in_index' => '0',
1640+
'Seq_in_index' => '1',
16381641
'Column_name' => 'name',
16391642
'Collation' => 'A',
16401643
'Cardinality' => '0',
1641-
'Sub_part' => null,
1644+
'Sub_part' => '20',
16421645
'Packed' => null,
16431646
'Null' => '',
16441647
'Index_type' => 'BTREE',
16451648
'Comment' => '',
16461649
'Index_comment' => '',
1650+
'Visible' => 'YES',
1651+
'Expression' => null,
16471652
),
16481653
),
16491654
$results
@@ -1669,16 +1674,18 @@ public function testAlterTableAddFulltextIndex() {
16691674
'Table' => '_tmp_table',
16701675
'Non_unique' => '1',
16711676
'Key_name' => 'name',
1672-
'Seq_in_index' => '0',
1677+
'Seq_in_index' => '1',
16731678
'Column_name' => 'name',
1674-
'Collation' => 'A',
1679+
'Collation' => null,
16751680
'Cardinality' => '0',
16761681
'Sub_part' => null,
16771682
'Packed' => null,
16781683
'Null' => '',
16791684
'Index_type' => 'FULLTEXT',
16801685
'Comment' => '',
16811686
'Index_comment' => '',
1687+
'Visible' => 'YES',
1688+
'Expression' => null,
16821689
),
16831690
),
16841691
$results
@@ -2166,15 +2173,14 @@ public function testNestedTransactionWorkComplexModify() {
21662173
$fields = $this->engine->get_query_results();
21672174

21682175
$this->assertEquals(
2169-
$fields,
21702176
array(
21712177
(object) array(
21722178
'Field' => 'ID',
2173-
'Type' => 'integer',
2179+
'Type' => 'int',
21742180
'Null' => 'NO',
21752181
'Key' => 'PRI',
2176-
'Default' => '0',
2177-
'Extra' => '',
2182+
'Default' => null,
2183+
'Extra' => 'auto_increment',
21782184
),
21792185
(object) array(
21802186
'Field' => 'option_name',
@@ -2192,7 +2198,8 @@ public function testNestedTransactionWorkComplexModify() {
21922198
'Default' => '',
21932199
'Extra' => '',
21942200
),
2195-
)
2201+
),
2202+
$fields
21962203
);
21972204
}
21982205

@@ -2425,7 +2432,7 @@ public function testDescribeAccurate() {
24252432
'Field' => 'term_name',
24262433
'Type' => 'varchar(11)',
24272434
'Null' => 'NO',
2428-
'Key' => '',
2435+
'Key' => 'MUL',
24292436
'Default' => '0',
24302437
'Extra' => '',
24312438
),

0 commit comments

Comments
 (0)