Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix invalid default values in show create output #141

Merged
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
24 changes: 24 additions & 0 deletions tests/WP_SQLite_Translator_Tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,30 @@ public function testShowCreateTableWithColumnKeys() {
);
}

public function testShowCreateTableWithCorrectDefaultValues() {
$this->assertQuery(
"CREATE TABLE _tmp__table (
ID BIGINT PRIMARY KEY AUTO_INCREMENT NOT NULL,
default_empty_string VARCHAR(255) default '',
null_no_default VARCHAR(255),
);"
);

$this->assertQuery(
'SHOW CREATE TABLE _tmp__table;'
);
$results = $this->engine->get_query_results();
$this->assertEquals(
'CREATE TABLE `_tmp__table` (
`ID` bigint NOT NULL AUTO_INCREMENT,
`default_empty_string` varchar(255) DEFAULT \'\',
`null_no_default` varchar(255),
PRIMARY KEY (`ID`)
);',
$results[0]->{'Create Table'}
);
}

public function testSelectIndexHintForce() {
$this->assertQuery( "INSERT INTO _options (option_name) VALUES ('first');" );
$result = $this->assertQuery(
Expand Down
2 changes: 1 addition & 1 deletion wp-includes/sqlite/class-wp-sqlite-translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -3522,7 +3522,7 @@ protected function get_column_definitions( $table_name, $columns ) {
$definition[] = 'NOT NULL';
}

if ( '' !== $column->dflt_value && ! $is_auto_incr ) {
if ( null !== $column->dflt_value && '' !== $column->dflt_value && ! $is_auto_incr ) {
$definition[] = 'DEFAULT ' . $column->dflt_value;
}

Expand Down
Loading