Skip to content

Commit 6e949cf

Browse files
wojteknJanJakes
authored andcommitted
Add (failing) test for AST driver
1 parent 913ca4b commit 6e949cf

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

tests/WP_SQLite_Driver_Tests.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11368,4 +11368,28 @@ public function testSubstringFunction(): void {
1136811368
$result = $this->assertQuery( "SELECT SUBSTRING('abcdef' FROM 4) AS s" );
1136911369
$this->assertSame( 'def', $result[0]->s );
1137011370
}
11371+
11372+
/**
11373+
* Test CREATE TABLE with DEFAULT (now()) - GitHub issue #300
11374+
* Tests that DEFAULT with function calls in parentheses works correctly in AST driver.
11375+
*
11376+
* @see https://github.com/WordPress/sqlite-database-integration/issues/300
11377+
*/
11378+
public function testCreateTableWithDefaultNowFunction(): void {
11379+
// Test the exact SQL from the issue
11380+
$this->assertQuery(
11381+
'CREATE TABLE `test_now_default` (
11382+
`id` int NOT NULL,
11383+
`updated` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP
11384+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;'
11385+
);
11386+
11387+
// Insert a row to verify the default value works
11388+
$this->assertQuery( 'INSERT INTO test_now_default (id) VALUES (1)' );
11389+
$result = $this->assertQuery( 'SELECT * FROM test_now_default WHERE id = 1' );
11390+
$this->assertCount( 1, $result );
11391+
11392+
// Verify the updated timestamp was set (should match YYYY-MM-DD HH:MM:SS format)
11393+
$this->assertRegExp( '/\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d/', $result[0]->updated );
11394+
}
1137111395
}

0 commit comments

Comments
 (0)