Skip to content

Commit 65aaca3

Browse files
wojteknJanJakes
authored andcommitted
Add support for simple now expressions
1 parent 6e949cf commit 65aaca3

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
@@ -2093,6 +2093,25 @@ private function get_column_default( WP_Parser_Node $node ): ?string {
20932093
return $this->get_value( $signed_literal );
20942094
}
20952095

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

0 commit comments

Comments
 (0)