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 creating a table with AUTOINCREMENT and ON UPDATE followed by PRIMARY KEY #158

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
21 changes: 21 additions & 0 deletions tests/WP_SQLite_Translator_Tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -1196,6 +1196,27 @@ public function testColumnWithOnUpdateAndNoIdField() {
$this->assertRegExp( '/\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d/', $result[0]->created_at );
}

public function testColumnWithOnUpdateAndAutoincrementPrimaryKey() {
// CREATE TABLE with ON UPDATE, AUTO_INCREMENT, and PRIMARY KEY
$this->assertQuery(
'CREATE TABLE _tmp_table (
id int(11) NOT NULL AUTO_INCREMENT,
created_at timestamp NULL ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (id)
);'
);

// on INSERT, no timestamps are expected
$this->assertQuery( 'INSERT INTO _tmp_table (id) VALUES (1)' );
$result = $this->assertQuery( 'SELECT * FROM _tmp_table WHERE id = 1' );
$this->assertNull( $result[0]->created_at );

// on UPDATE, we expect timestamps in form YYYY-MM-DD HH:MM:SS
$this->assertQuery( 'UPDATE _tmp_table SET id = 2 WHERE id = 1' );
$result = $this->assertQuery( 'SELECT * FROM _tmp_table WHERE id = 2' );
$this->assertRegExp( '/\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d/', $result[0]->created_at );
}

public function testChangeColumnWithOnUpdate() {
// CREATE TABLE with ON UPDATE
$this->assertQuery(
Expand Down
3 changes: 1 addition & 2 deletions wp-includes/sqlite/class-wp-sqlite-translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -1145,8 +1145,7 @@ private function parse_mysql_create_table_field() {
array( 'CURRENT_TIMESTAMP' )
)
) {
$this->rewriter->skip(); // ON UPDATE
$this->rewriter->skip(); // CURRENT_TIMESTAMP
$this->rewriter->skip();
$result->on_update = true;
continue;
}
Expand Down
Loading