Skip to content

Commit 14c63a7

Browse files
committed
Add support for simple now expressions
1 parent f6e392e commit 14c63a7

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

wp-includes/sqlite-ast/class-wp-sqlite-information-schema-builder.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2088,6 +2088,25 @@ private function get_column_default( WP_Parser_Node $node ): ?string {
20882088
return $this->get_value( $signed_literal );
20892089
}
20902090

2091+
// DEFAULT (expression) - MySQL 8.0.13+ supports exprWithParentheses
2092+
$expr_with_parens = $default_attr->get_first_child_node( 'exprWithParentheses' );
2093+
if ( $expr_with_parens ) {
2094+
// For now, only support simple function calls like (now()), (CURRENT_TIMESTAMP)
2095+
// Check if it's (now()) or (NOW())
2096+
$now_tokens = $expr_with_parens->get_descendant_tokens( WP_MySQL_Lexer::NOW_SYMBOL );
2097+
if ( ! empty( $now_tokens ) ) {
2098+
return 'CURRENT_TIMESTAMP';
2099+
}
2100+
2101+
// Check if it's (CURRENT_TIMESTAMP) or (CURRENT_TIMESTAMP())
2102+
$current_ts_tokens = $expr_with_parens->get_descendant_tokens( WP_MySQL_Lexer::CURRENT_TIMESTAMP_SYMBOL );
2103+
if ( ! empty( $current_ts_tokens ) ) {
2104+
return 'CURRENT_TIMESTAMP';
2105+
}
2106+
2107+
// For any other complex expressions, throw an exception
2108+
throw new Exception( 'DEFAULT values with complex expressions are not yet supported. Only (now()) and (CURRENT_TIMESTAMP) are currently supported.' );
2109+
}
20912110
throw new Exception( 'DEFAULT values with expressions are not yet supported.' );
20922111
}
20932112

0 commit comments

Comments
 (0)