@@ -3510,4 +3510,41 @@ public static function mysqlVariablesToTest() {
35103510 array ( '@@sEssIOn.sqL_moDe ' ),
35113511 );
35123512 }
3513+
3514+ /**
3515+ * Test CREATE TABLE with DEFAULT (now()) - GitHub issue #300
3516+ * Tests that DEFAULT with function calls in parentheses works correctly.
3517+ */
3518+ public function testCreateTableWithDefaultNowFunction () {
3519+ // Test the exact SQL from the issue
3520+ $ this ->assertQuery (
3521+ "CREATE TABLE `test_now_default` (
3522+ `id` int NOT NULL,
3523+ `updated` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP
3524+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci; "
3525+ );
3526+
3527+ // Verify the table was created successfully
3528+ $ results = $ this ->assertQuery ( 'DESCRIBE test_now_default; ' );
3529+ $ this ->assertCount ( 2 , $ results );
3530+
3531+ // Verify the updated column has the correct properties
3532+ $ updated_field = $ results [1 ];
3533+ $ this ->assertEquals ( 'updated ' , $ updated_field ->Field );
3534+ $ this ->assertEquals ( 'timestamp ' , $ updated_field ->Type );
3535+ $ this ->assertEquals ( 'NO ' , $ updated_field ->Null );
3536+
3537+ // Insert a row to verify the default value works
3538+ $ this ->assertQuery ( 'INSERT INTO test_now_default (id) VALUES (1) ' );
3539+ $ result = $ this ->assertQuery ( 'SELECT * FROM test_now_default WHERE id = 1 ' );
3540+ $ this ->assertCount ( 1 , $ result );
3541+
3542+ // Verify the updated timestamp was set (should match YYYY-MM-DD HH:MM:SS format)
3543+ $ this ->assertRegExp ( '/\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d/ ' , $ result [0 ]->updated );
3544+
3545+ // Test ON UPDATE trigger works
3546+ $ this ->assertQuery ( 'UPDATE test_now_default SET id = 2 WHERE id = 1 ' );
3547+ $ result = $ this ->assertQuery ( 'SELECT * FROM test_now_default WHERE id = 2 ' );
3548+ $ this ->assertRegExp ( '/\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d/ ' , $ result [0 ]->updated );
3549+ }
35133550}
0 commit comments