@@ -11316,5 +11316,58 @@ public function testCreateTableWithDefaultNowFunction(): void {
1131611316
1131711317 // Verify the updated timestamp was set (should match YYYY-MM-DD HH:MM:SS format)
1131811318 $ this ->assertRegExp ( '/\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d/ ' , $ result [0 ]->updated );
11319+
11320+ // SHOW CREATE TABLE
11321+ $ this ->assertQuery ( 'SHOW CREATE TABLE test_now_default ' );
11322+ $ results = $ this ->engine ->get_query_results ();
11323+ $ this ->assertEquals (
11324+ implode (
11325+ "\n" ,
11326+ array (
11327+ 'CREATE TABLE `test_now_default` ( ' ,
11328+ ' `id` int NOT NULL, ' ,
11329+ ' `updated` timestamp NOT NULL DEFAULT ( now( ) ) ON UPDATE CURRENT_TIMESTAMP ' ,
11330+ ') ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci ' ,
11331+ )
11332+ ),
11333+ $ results [0 ]->{'Create Table ' }
11334+ );
11335+ }
11336+
11337+ public function testCreateTableWithDefaultExpressions (): void {
11338+ $ this ->assertQuery (
11339+ 'CREATE TABLE t (
11340+ id int NOT NULL,
11341+ col1 int NOT NULL DEFAULT (1 + 2),
11342+ col2 datetime NOT NULL DEFAULT (DATE_ADD(NOW(), INTERVAL 1 YEAR)),
11343+ col3 varchar(255) NOT NULL DEFAULT (CONCAT( \'a \', \'b \'))
11344+ ) '
11345+ );
11346+
11347+ // Insert a row and verify the default values
11348+ $ this ->assertQuery ( 'INSERT INTO t (id) VALUES (1) ' );
11349+ $ this ->assertQuery ( 'SELECT * FROM t WHERE id = 1 ' );
11350+ $ results = $ this ->engine ->get_query_results ();
11351+ $ this ->assertEquals ( 3 , $ results [0 ]->col1 );
11352+ $ this ->assertStringStartsWith ( ( gmdate ( 'Y ' ) + 1 ) . '- ' , $ results [0 ]->col2 );
11353+ $ this ->assertEquals ( 'ab ' , $ results [0 ]->col3 );
11354+
11355+ // SHOW CREATE TABLE
11356+ $ this ->assertQuery ( 'SHOW CREATE TABLE t ' );
11357+ $ results = $ this ->engine ->get_query_results ();
11358+ $ this ->assertEquals (
11359+ implode (
11360+ "\n" ,
11361+ array (
11362+ 'CREATE TABLE `t` ( ' ,
11363+ ' `id` int NOT NULL, ' ,
11364+ ' `col1` int NOT NULL DEFAULT ( 1 + 2 ), ' ,
11365+ ' `col2` datetime NOT NULL DEFAULT ( DATE_ADD( NOW( ) , INTERVAL 1 YEAR ) ), ' ,
11366+ " `col3` varchar(255) NOT NULL DEFAULT ( CONCAT( 'a' , 'b' ) ) " ,
11367+ ') ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci ' ,
11368+ )
11369+ ),
11370+ $ results [0 ]->{'Create Table ' }
11371+ );
1131911372 }
1132011373}
0 commit comments