Skip to content

Commit 4d2edf2

Browse files
wojteknJanJakes
authored andcommitted
Add (failing) test for AST driver
1 parent e46372c commit 4d2edf2

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
@@ -11293,4 +11293,28 @@ public function testSubstringFunction(): void {
1129311293
$result = $this->assertQuery( "SELECT SUBSTRING('abcdef' FROM 4) AS s" );
1129411294
$this->assertSame( 'def', $result[0]->s );
1129511295
}
11296+
11297+
/**
11298+
* Test CREATE TABLE with DEFAULT (now()) - GitHub issue #300
11299+
* Tests that DEFAULT with function calls in parentheses works correctly in AST driver.
11300+
*
11301+
* @see https://github.com/WordPress/sqlite-database-integration/issues/300
11302+
*/
11303+
public function testCreateTableWithDefaultNowFunction(): void {
11304+
// Test the exact SQL from the issue
11305+
$this->assertQuery(
11306+
'CREATE TABLE `test_now_default` (
11307+
`id` int NOT NULL,
11308+
`updated` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP
11309+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;'
11310+
);
11311+
11312+
// Insert a row to verify the default value works
11313+
$this->assertQuery( 'INSERT INTO test_now_default (id) VALUES (1)' );
11314+
$result = $this->assertQuery( 'SELECT * FROM test_now_default WHERE id = 1' );
11315+
$this->assertCount( 1, $result );
11316+
11317+
// Verify the updated timestamp was set (should match YYYY-MM-DD HH:MM:SS format)
11318+
$this->assertRegExp( '/\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d/', $result[0]->updated );
11319+
}
1129611320
}

0 commit comments

Comments
 (0)