@@ -3384,4 +3384,41 @@ public static function mysqlVariablesToTest() {
33843384 array ( '@@sEssIOn.sqL_moDe ' ),
33853385 );
33863386 }
3387+
3388+ /**
3389+ * Test CREATE TABLE with DEFAULT (now()) - GitHub issue #300
3390+ * Tests that DEFAULT with function calls in parentheses works correctly.
3391+ */
3392+ public function testCreateTableWithDefaultNowFunction () {
3393+ // Test the exact SQL from the issue
3394+ $ this ->assertQuery (
3395+ "CREATE TABLE `test_now_default` (
3396+ `id` int NOT NULL,
3397+ `updated` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP
3398+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci; "
3399+ );
3400+
3401+ // Verify the table was created successfully
3402+ $ results = $ this ->assertQuery ( 'DESCRIBE test_now_default; ' );
3403+ $ this ->assertCount ( 2 , $ results );
3404+
3405+ // Verify the updated column has the correct properties
3406+ $ updated_field = $ results [1 ];
3407+ $ this ->assertEquals ( 'updated ' , $ updated_field ->Field );
3408+ $ this ->assertEquals ( 'timestamp ' , $ updated_field ->Type );
3409+ $ this ->assertEquals ( 'NO ' , $ updated_field ->Null );
3410+
3411+ // Insert a row to verify the default value works
3412+ $ this ->assertQuery ( 'INSERT INTO test_now_default (id) VALUES (1) ' );
3413+ $ result = $ this ->assertQuery ( 'SELECT * FROM test_now_default WHERE id = 1 ' );
3414+ $ this ->assertCount ( 1 , $ result );
3415+
3416+ // Verify the updated timestamp was set (should match YYYY-MM-DD HH:MM:SS format)
3417+ $ this ->assertRegExp ( '/\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d/ ' , $ result [0 ]->updated );
3418+
3419+ // Test ON UPDATE trigger works
3420+ $ this ->assertQuery ( 'UPDATE test_now_default SET id = 2 WHERE id = 1 ' );
3421+ $ result = $ this ->assertQuery ( 'SELECT * FROM test_now_default WHERE id = 2 ' );
3422+ $ this ->assertRegExp ( '/\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d/ ' , $ result [0 ]->updated );
3423+ }
33873424}
0 commit comments