Skip to content

Commit d913e6b

Browse files
aristathjeroenpfcostasovo
authored
v2.1.13 (#143)
Version 2.1.13 --------- Co-authored-by: Jeroen P <[email protected]> Co-authored-by: Rostislav Wolný <[email protected]>
1 parent 0529506 commit d913e6b

File tree

4 files changed

+83
-6
lines changed

4 files changed

+83
-6
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.12
6+
* Version: 2.1.13
77
* Requires PHP: 7.0
88
* Textdomain: sqlite-database-integration
99
*

readme.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Contributors: wordpressdotorg, aristath
44
Requires at least: 6.4
55
Tested up to: 6.6.1
66
Requires PHP: 7.0
7-
Stable tag: 2.1.12
7+
Stable tag: 2.1.13
88
License: GPLv2 or later
99
License URI: https://www.gnu.org/licenses/gpl-2.0.html
1010
Tags: performance, database

tests/WP_SQLite_Translator_Tests.php

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,30 @@ public function testShowCreateTableWithColumnKeys() {
457457
);
458458
}
459459

460+
public function testShowCreateTableWithCorrectDefaultValues() {
461+
$this->assertQuery(
462+
"CREATE TABLE _tmp__table (
463+
ID BIGINT PRIMARY KEY AUTO_INCREMENT NOT NULL,
464+
default_empty_string VARCHAR(255) default '',
465+
null_no_default VARCHAR(255),
466+
);"
467+
);
468+
469+
$this->assertQuery(
470+
'SHOW CREATE TABLE _tmp__table;'
471+
);
472+
$results = $this->engine->get_query_results();
473+
$this->assertEquals(
474+
'CREATE TABLE `_tmp__table` (
475+
`ID` bigint NOT NULL AUTO_INCREMENT,
476+
`default_empty_string` varchar(255) DEFAULT \'\',
477+
`null_no_default` varchar(255),
478+
PRIMARY KEY (`ID`)
479+
);',
480+
$results[0]->{'Create Table'}
481+
);
482+
}
483+
460484
public function testSelectIndexHintForce() {
461485
$this->assertQuery( "INSERT INTO _options (option_name) VALUES ('first');" );
462486
$result = $this->assertQuery(
@@ -1074,6 +1098,57 @@ public function testAlterTableModifyColumn() {
10741098
$this->assertEquals( 2, $result[0]->ID );
10751099
}
10761100

1101+
1102+
public function testAlterTableModifyColumnWithSkippedColumnKeyword() {
1103+
$this->assertQuery(
1104+
"CREATE TABLE _tmp_table (
1105+
ID INTEGER PRIMARY KEY AUTO_INCREMENT NOT NULL,
1106+
name varchar(20) NOT NULL default '',
1107+
lastname varchar(20) NOT NULL default '',
1108+
KEY composite (name, lastname),
1109+
UNIQUE KEY name (name)
1110+
);"
1111+
);
1112+
// Insert a record
1113+
$result = $this->assertQuery( "INSERT INTO _tmp_table (ID, name, lastname) VALUES (1, 'Johnny', 'Appleseed');" );
1114+
$this->assertEquals( 1, $result );
1115+
1116+
// Primary key violation:
1117+
$result = $this->engine->query( "INSERT INTO _tmp_table (ID, name, lastname) VALUES (1, 'Mike', 'Pearseed');" );
1118+
$this->assertEquals( false, $result );
1119+
1120+
// Unique constraint violation:
1121+
$result = $this->engine->query( "INSERT INTO _tmp_table (ID, name, lastname) VALUES (2, 'Johnny', 'Appleseed');" );
1122+
$this->assertEquals( false, $result );
1123+
1124+
// Rename the "name" field to "firstname":
1125+
$result = $this->engine->query( "ALTER TABLE _tmp_table CHANGE name firstname varchar(50) NOT NULL default 'mark';" );
1126+
$this->assertEquals( '', $this->engine->get_error_message() );
1127+
$this->assertEquals( 1, $result );
1128+
1129+
// Confirm the original data is still there:
1130+
$result = $this->engine->query( 'SELECT * FROM _tmp_table;' );
1131+
$this->assertCount( 1, $result );
1132+
$this->assertEquals( 1, $result[0]->ID );
1133+
$this->assertEquals( 'Johnny', $result[0]->firstname );
1134+
$this->assertEquals( 'Appleseed', $result[0]->lastname );
1135+
1136+
// Confirm the primary key is intact:
1137+
$result = $this->engine->query( "INSERT INTO _tmp_table (ID, firstname, lastname) VALUES (1, 'Mike', 'Pearseed');" );
1138+
$this->assertEquals( false, $result );
1139+
1140+
// Confirm the unique key is intact:
1141+
$result = $this->engine->query( "INSERT INTO _tmp_table (ID, firstname, lastname) VALUES (2, 'Johnny', 'Appleseed');" );
1142+
$this->assertEquals( false, $result );
1143+
1144+
// Confirm the autoincrement still works:
1145+
$result = $this->engine->query( "INSERT INTO _tmp_table (firstname, lastname) VALUES ('John', 'Doe');" );
1146+
$this->assertEquals( true, $result );
1147+
$result = $this->engine->query( "SELECT * FROM _tmp_table WHERE firstname='John';" );
1148+
$this->assertCount( 1, $result );
1149+
$this->assertEquals( 2, $result[0]->ID );
1150+
}
1151+
10771152
public function testAlterTableModifyColumnWithHyphens() {
10781153
$result = $this->assertQuery(
10791154
'CREATE TABLE wptests_dbdelta_test2 (

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2916,7 +2916,8 @@ private function execute_alter() {
29162916
)
29172917
);
29182918
$op_type = strtoupper( $this->rewriter->consume()->token ?? '' );
2919-
$op_subject = strtoupper( $this->rewriter->consume()->token ?? '' );
2919+
$op_raw_subject = $this->rewriter->consume()->token ?? '';
2920+
$op_subject = strtoupper( $op_raw_subject );
29202921
$mysql_index_type = $this->normalize_mysql_index_type( $op_subject );
29212922
$is_index_op = (bool) $mysql_index_type;
29222923

@@ -2941,9 +2942,10 @@ private function execute_alter() {
29412942
);
29422943
} elseif ( 'DROP' === $op_type && 'COLUMN' === $op_subject ) {
29432944
$this->rewriter->consume_all();
2944-
} elseif ( 'CHANGE' === $op_type && 'COLUMN' === $op_subject ) {
2945+
} elseif ( 'CHANGE' === $op_type ) {
29452946
// Parse the new column definition.
2946-
$from_name = $this->normalize_column_name( $this->rewriter->skip()->token );
2947+
$raw_from_name = 'COLUMN' === $op_subject ? $this->rewriter->skip()->token : $op_raw_subject;
2948+
$from_name = $this->normalize_column_name( $raw_from_name );
29472949
$new_field = $this->parse_mysql_create_table_field();
29482950
$alter_terminator = end( $this->rewriter->output_tokens );
29492951
$this->update_data_type_cache(
@@ -3522,7 +3524,7 @@ protected function get_column_definitions( $table_name, $columns ) {
35223524
$definition[] = 'NOT NULL';
35233525
}
35243526

3525-
if ( '' !== $column->dflt_value && ! $is_auto_incr ) {
3527+
if ( null !== $column->dflt_value && '' !== $column->dflt_value && ! $is_auto_incr ) {
35263528
$definition[] = 'DEFAULT ' . $column->dflt_value;
35273529
}
35283530

0 commit comments

Comments
 (0)