Skip to content

Commit a6d85a6

Browse files
aristathadamzieljeroenpfakirk
authored
v2.1.12 (#131)
Co-authored-by: Adam Zieliński <[email protected]> Co-authored-by: Jeroen P <[email protected]> Co-authored-by: Alex Kirk <[email protected]>
1 parent e476698 commit a6d85a6

File tree

6 files changed

+492
-115
lines changed

6 files changed

+492
-115
lines changed

load.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Plugin Name: SQLite Database Integration
44
* Description: SQLite database driver drop-in.
55
* Author: The WordPress Team
6-
* Version: 2.1.11
6+
* Version: 2.1.12
77
* Requires PHP: 7.0
88
* Textdomain: sqlite-database-integration
99
*

readme.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
=== SQLite Database Integration ===
22

33
Contributors: wordpressdotorg, aristath
4-
Requires at least: 6.0
5-
Tested up to: 6.4
6-
Requires PHP: 5.6
7-
Stable tag: 2.1.11
4+
Requires at least: 6.4
5+
Tested up to: 6.6.1
6+
Requires PHP: 7.0
7+
Stable tag: 2.1.12
88
License: GPLv2 or later
99
License URI: https://www.gnu.org/licenses/gpl-2.0.html
1010
Tags: performance, database

tests/WP_SQLite_Query_Tests.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,23 @@ public function testOnDuplicateKey() {
519519
ON DUPLICATE KEY UPDATE `text` = "test1"'
520520
);
521521
}
522+
public function testOnDuplicateKeyWithUnnamedKeys() {
523+
$this->assertQuery(
524+
'CREATE TABLE `test` (
525+
`id` INT,
526+
`name` VARCHAR(255),
527+
`other` VARCHAR(255),
528+
PRIMARY KEY (id),
529+
UNIQUE KEY (name)
530+
);'
531+
);
532+
// The order is deliberate to test that the query works with the keys in any order.
533+
$this->assertQuery(
534+
'INSERT INTO test (`name`, other)
535+
VALUES ("name", "test")
536+
ON DUPLICATE KEY UPDATE `other` = values(other)'
537+
);
538+
}
522539

523540
public function testShowColumns() {
524541

tests/WP_SQLite_Translator_Tests.php

Lines changed: 187 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,14 @@ public function testSelectFromDual() {
253253
$this->assertEquals( 1, $result[0]->output );
254254
}
255255

256+
public function testShowCreateTableNotFound() {
257+
$this->assertQuery(
258+
'SHOW CREATE TABLE _no_such_table;'
259+
);
260+
$results = $this->engine->get_query_results();
261+
$this->assertCount( 0, $results );
262+
}
263+
256264
public function testShowCreateTable1() {
257265
$this->assertQuery(
258266
"CREATE TABLE _tmp_table (
@@ -270,12 +278,42 @@ public function testShowCreateTable1() {
270278
$results = $this->engine->get_query_results();
271279
# TODO: Should we fix mismatch with original `option_value` text NOT NULL,` without default?
272280
$this->assertEquals(
281+
"CREATE TABLE `_tmp_table` (
282+
`ID` bigint NOT NULL AUTO_INCREMENT,
283+
`option_name` varchar(255) DEFAULT '',
284+
`option_value` text NOT NULL DEFAULT '',
285+
PRIMARY KEY (`ID`),
286+
KEY `composite` (`option_name`, `option_value`),
287+
UNIQUE KEY `option_name` (`option_name`)
288+
);",
289+
$results[0]->{'Create Table'}
290+
);
291+
}
292+
293+
public function testShowCreateTableQuoted() {
294+
$this->assertQuery(
273295
"CREATE TABLE _tmp_table (
274-
`ID` bigint PRIMARY KEY AUTO_INCREMENT NOT NULL,
296+
ID BIGINT PRIMARY KEY AUTO_INCREMENT NOT NULL,
297+
option_name VARCHAR(255) default '',
298+
option_value TEXT NOT NULL,
299+
UNIQUE KEY option_name (option_name),
300+
KEY composite (option_name, option_value)
301+
);"
302+
);
303+
304+
$this->assertQuery(
305+
'SHOW CREATE TABLE `_tmp_table`;'
306+
);
307+
$results = $this->engine->get_query_results();
308+
# TODO: Should we fix mismatch with original `option_value` text NOT NULL,` without default?
309+
$this->assertEquals(
310+
"CREATE TABLE `_tmp_table` (
311+
`ID` bigint NOT NULL AUTO_INCREMENT,
275312
`option_name` varchar(255) DEFAULT '',
276313
`option_value` text NOT NULL DEFAULT '',
277-
KEY _tmp_table__composite (option_name, option_value),
278-
UNIQUE KEY _tmp_table__option_name (option_name)
314+
PRIMARY KEY (`ID`),
315+
KEY `composite` (`option_name`, `option_value`),
316+
UNIQUE KEY `option_name` (`option_name`)
279317
);",
280318
$results[0]->{'Create Table'}
281319
);
@@ -293,8 +331,8 @@ public function testShowCreateTableSimpleTable() {
293331
);
294332
$results = $this->engine->get_query_results();
295333
$this->assertEquals(
296-
'CREATE TABLE _tmp_table (
297-
`ID` bigint NOT NULL
334+
'CREATE TABLE `_tmp_table` (
335+
`ID` bigint NOT NULL DEFAULT 0
298336
);',
299337
$results[0]->{'Create Table'}
300338
);
@@ -322,16 +360,103 @@ public function testShowCreateTableWithAlterAndCreateIndex() {
322360
);
323361
$results = $this->engine->get_query_results();
324362
$this->assertEquals(
325-
'CREATE TABLE _tmp_table (
326-
`ID` bigint PRIMARY KEY AUTO_INCREMENT NOT NULL,
363+
'CREATE TABLE `_tmp_table` (
364+
`ID` bigint NOT NULL AUTO_INCREMENT,
327365
`option_name` smallint NOT NULL DEFAULT 14,
328366
`option_value` text NOT NULL DEFAULT \'\',
329-
KEY _tmp_table__option_name (option_name)
367+
PRIMARY KEY (`ID`),
368+
KEY `option_name` (`option_name`)
330369
);',
331370
$results[0]->{'Create Table'}
332371
);
333372
}
334373

374+
public function testCreateTablseWithIdenticalIndexNames() {
375+
$this->assertQuery(
376+
"CREATE TABLE _tmp_table_a (
377+
ID BIGINT PRIMARY KEY AUTO_INCREMENT NOT NULL,
378+
option_name VARCHAR(255) default '',
379+
option_value TEXT NOT NULL,
380+
KEY `option_name` (`option_name`),
381+
KEY `double__underscores` (`option_name`, `ID`)
382+
);"
383+
);
384+
385+
$this->assertQuery(
386+
"CREATE TABLE _tmp_table_b (
387+
ID BIGINT PRIMARY KEY AUTO_INCREMENT NOT NULL,
388+
option_name VARCHAR(255) default '',
389+
option_value TEXT NOT NULL,
390+
KEY `option_name` (`option_name`),
391+
KEY `double__underscores` (`option_name`, `ID`)
392+
);"
393+
);
394+
}
395+
396+
public function testShowCreateTablePreservesDoubleUnderscoreKeyNames() {
397+
$this->assertQuery(
398+
"CREATE TABLE _tmp__table (
399+
ID BIGINT PRIMARY KEY AUTO_INCREMENT NOT NULL,
400+
option_name VARCHAR(255) default '',
401+
option_value TEXT NOT NULL,
402+
KEY `option_name` (`option_name`),
403+
KEY `double__underscores` (`option_name`, `ID`)
404+
);"
405+
);
406+
407+
$this->assertQuery(
408+
'SHOW CREATE TABLE _tmp__table;'
409+
);
410+
$results = $this->engine->get_query_results();
411+
$this->assertEquals(
412+
'CREATE TABLE `_tmp__table` (
413+
`ID` bigint NOT NULL AUTO_INCREMENT,
414+
`option_name` varchar(255) DEFAULT \'\',
415+
`option_value` text NOT NULL DEFAULT \'\',
416+
PRIMARY KEY (`ID`),
417+
KEY `double__underscores` (`option_name`, `ID`),
418+
KEY `option_name` (`option_name`)
419+
);',
420+
$results[0]->{'Create Table'}
421+
);
422+
}
423+
424+
public function testShowCreateTableWithPrimaryKeyColumnsReverseOrdered() {
425+
$this->assertQuery(
426+
'CREATE TABLE `_tmp_table` (
427+
`ID_A` BIGINT NOT NULL,
428+
`ID_B` BIGINT NOT NULL,
429+
`ID_C` BIGINT NOT NULL,
430+
PRIMARY KEY (`ID_B`, `ID_A`, `ID_C`)
431+
);'
432+
);
433+
434+
$this->assertQuery(
435+
'SHOW CREATE TABLE _tmp_table;'
436+
);
437+
$results = $this->engine->get_query_results();
438+
$this->assertEquals(
439+
'CREATE TABLE `_tmp_table` (
440+
`ID_A` bigint NOT NULL DEFAULT 0,
441+
`ID_B` bigint NOT NULL DEFAULT 0,
442+
`ID_C` bigint NOT NULL DEFAULT 0,
443+
PRIMARY KEY (`ID_B`, `ID_A`, `ID_C`)
444+
);',
445+
$results[0]->{'Create Table'}
446+
);
447+
}
448+
449+
public function testShowCreateTableWithColumnKeys() {
450+
$this->assertQuery(
451+
"CREATE TABLE _tmp_table (
452+
`ID` bigint PRIMARY KEY AUTO_INCREMENT NOT NULL,
453+
`option_name` varchar(255) DEFAULT '',
454+
`option_value` text NOT NULL DEFAULT '',
455+
KEY _tmp_table__composite (option_name, option_value),
456+
UNIQUE KEY _tmp_table__option_name (option_name) );"
457+
);
458+
}
459+
335460
public function testSelectIndexHintForce() {
336461
$this->assertQuery( "INSERT INTO _options (option_name) VALUES ('first');" );
337462
$result = $this->assertQuery(
@@ -668,6 +793,60 @@ public function testCreateTableSpatialIndex() {
668793
$this->assertEquals( 1, $result );
669794
}
670795

796+
public function testCreateTableWithMultiValueColumnTypeModifiers() {
797+
$result = $this->assertQuery(
798+
"CREATE TABLE wptests_users (
799+
ID bigint(20) unsigned NOT NULL auto_increment,
800+
decimal_column DECIMAL(10,2) NOT NULL DEFAULT 0,
801+
float_column FLOAT(10,2) NOT NULL DEFAULT 0,
802+
enum_column ENUM('a', 'b', 'c') NOT NULL DEFAULT 'a',
803+
PRIMARY KEY (ID),
804+
)"
805+
);
806+
$this->assertEquals( '', $this->engine->get_error_message() );
807+
$this->assertEquals( 1, $result );
808+
809+
$this->assertQuery( 'DESCRIBE wptests_users;' );
810+
$results = $this->engine->get_query_results();
811+
$this->assertEquals(
812+
array(
813+
(object) array(
814+
'Field' => 'ID',
815+
'Type' => 'bigint(20) unsigned',
816+
'Null' => 'NO',
817+
'Key' => 'PRI',
818+
'Default' => '0',
819+
'Extra' => '',
820+
),
821+
(object) array(
822+
'Field' => 'decimal_column',
823+
'Type' => 'decimal(10,2)',
824+
'Null' => 'NO',
825+
'Key' => '',
826+
'Default' => 0,
827+
'Extra' => '',
828+
),
829+
(object) array(
830+
'Field' => 'float_column',
831+
'Type' => 'float(10,2)',
832+
'Null' => 'NO',
833+
'Key' => '',
834+
'Default' => 0,
835+
'Extra' => '',
836+
),
837+
(object) array(
838+
'Field' => 'enum_column',
839+
'Type' => "enum('a','b','c')",
840+
'Null' => 'NO',
841+
'Key' => '',
842+
'Default' => 'a',
843+
'Extra' => '',
844+
),
845+
),
846+
$results
847+
);
848+
}
849+
671850
public function testAlterTableAddColumn() {
672851
$result = $this->assertQuery(
673852
"CREATE TABLE _tmp_table (

wp-includes/sqlite/class-wp-sqlite-token.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ public function matches( $type = null, $flags = null, $values = null ) {
218218
return (
219219
( null === $type || $this->type === $type )
220220
&& ( null === $flags || ( $this->flags & $flags ) )
221-
&& ( null === $values || in_array( strtoupper( $this->value ), $values, true ) )
221+
&& ( null === $values || in_array( strtoupper( $this->value ?? '' ), $values, true ) )
222222
);
223223
}
224224

@@ -241,7 +241,7 @@ public function is_semantically_void() {
241241
private function extract() {
242242
switch ( $this->type ) {
243243
case self::TYPE_KEYWORD:
244-
$this->keyword = strtoupper( $this->token );
244+
$this->keyword = strtoupper( $this->token ?? '' );
245245
if ( ! ( $this->flags & self::FLAG_KEYWORD_RESERVED ) ) {
246246
/*
247247
* Unreserved keywords should stay the way they are
@@ -256,7 +256,7 @@ private function extract() {
256256
return ' ';
257257

258258
case self::TYPE_BOOL:
259-
return strtoupper( $this->token ) === 'TRUE';
259+
return strtoupper( $this->token ?? '' ) === 'TRUE';
260260

261261
case self::TYPE_NUMBER:
262262
$ret = str_replace( '--', '', $this->token ); // e.g. ---42 === -42.

0 commit comments

Comments
 (0)