Skip to content

Commit c6eeea2

Browse files
committed
Fix the parenthesis issue
1 parent 4495f33 commit c6eeea2

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

wp-includes/sqlite/class-wp-sqlite-translator.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1130,7 +1130,28 @@ private function parse_mysql_create_table_field() {
11301130
WP_SQLite_Token::FLAG_KEYWORD_FUNCTION,
11311131
array( 'DEFAULT' )
11321132
) ) {
1133-
$result->default = $this->rewriter->consume()->token;
1133+
// Consume the next token (could be a value, opening paren, etc.)
1134+
$default_token = $this->rewriter->consume();
1135+
$result->default = $default_token->token;
1136+
1137+
// Check if the default value is wrapped in parentheses (for function calls like (now()))
1138+
if ( $default_token->matches( WP_SQLite_Token::TYPE_OPERATOR, null, array( '(' ) ) ) {
1139+
// Track parenthesis depth to consume the complete expression
1140+
$paren_depth = 1;
1141+
$default_value = '(';
1142+
1143+
while ( $paren_depth > 0 && ( $next_token = $this->rewriter->consume() ) ) {
1144+
$default_value .= $next_token->token;
1145+
1146+
if ( $next_token->matches( WP_SQLite_Token::TYPE_OPERATOR, null, array( '(' ) ) ) {
1147+
++$paren_depth;
1148+
} elseif ( $next_token->matches( WP_SQLite_Token::TYPE_OPERATOR, null, array( ')' ) ) ) {
1149+
--$paren_depth;
1150+
}
1151+
}
1152+
1153+
$result->default = $default_value;
1154+
}
11341155
continue;
11351156
}
11361157

0 commit comments

Comments
 (0)