@@ -11391,5 +11391,58 @@ public function testCreateTableWithDefaultNowFunction(): void {
1139111391
1139211392 // Verify the updated timestamp was set (should match YYYY-MM-DD HH:MM:SS format)
1139311393 $ this ->assertRegExp ( '/\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d/ ' , $ result [0 ]->updated );
11394+
11395+ // SHOW CREATE TABLE
11396+ $ this ->assertQuery ( 'SHOW CREATE TABLE test_now_default ' );
11397+ $ results = $ this ->engine ->get_query_results ();
11398+ $ this ->assertEquals (
11399+ implode (
11400+ "\n" ,
11401+ array (
11402+ 'CREATE TABLE `test_now_default` ( ' ,
11403+ ' `id` int NOT NULL, ' ,
11404+ ' `updated` timestamp NOT NULL DEFAULT ( now( ) ) ON UPDATE CURRENT_TIMESTAMP ' ,
11405+ ') ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci ' ,
11406+ )
11407+ ),
11408+ $ results [0 ]->{'Create Table ' }
11409+ );
11410+ }
11411+
11412+ public function testCreateTableWithDefaultExpressions (): void {
11413+ $ this ->assertQuery (
11414+ 'CREATE TABLE t (
11415+ id int NOT NULL,
11416+ col1 int NOT NULL DEFAULT (1 + 2),
11417+ col2 datetime NOT NULL DEFAULT (DATE_ADD(NOW(), INTERVAL 1 YEAR)),
11418+ col3 varchar(255) NOT NULL DEFAULT (CONCAT( \'a \', \'b \'))
11419+ ) '
11420+ );
11421+
11422+ // Insert a row and verify the default values
11423+ $ this ->assertQuery ( 'INSERT INTO t (id) VALUES (1) ' );
11424+ $ this ->assertQuery ( 'SELECT * FROM t WHERE id = 1 ' );
11425+ $ results = $ this ->engine ->get_query_results ();
11426+ $ this ->assertEquals ( 3 , $ results [0 ]->col1 );
11427+ $ this ->assertStringStartsWith ( ( gmdate ( 'Y ' ) + 1 ) . '- ' , $ results [0 ]->col2 );
11428+ $ this ->assertEquals ( 'ab ' , $ results [0 ]->col3 );
11429+
11430+ // SHOW CREATE TABLE
11431+ $ this ->assertQuery ( 'SHOW CREATE TABLE t ' );
11432+ $ results = $ this ->engine ->get_query_results ();
11433+ $ this ->assertEquals (
11434+ implode (
11435+ "\n" ,
11436+ array (
11437+ 'CREATE TABLE `t` ( ' ,
11438+ ' `id` int NOT NULL, ' ,
11439+ ' `col1` int NOT NULL DEFAULT ( 1 + 2 ), ' ,
11440+ ' `col2` datetime NOT NULL DEFAULT ( DATE_ADD( NOW( ) , INTERVAL 1 YEAR ) ), ' ,
11441+ " `col3` varchar(255) NOT NULL DEFAULT ( CONCAT( 'a' , 'b' ) ) " ,
11442+ ') ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci ' ,
11443+ )
11444+ ),
11445+ $ results [0 ]->{'Create Table ' }
11446+ );
1139411447 }
1139511448}
0 commit comments