Skip to content

Commit 36339ad

Browse files
wojteknJanJakes
authored andcommitted
Fix the parenthesis issue
1 parent 23305c1 commit 36339ad

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1150,7 +1150,28 @@ private function parse_mysql_create_table_field() {
11501150
WP_SQLite_Token::FLAG_KEYWORD_FUNCTION,
11511151
array( 'DEFAULT' )
11521152
) ) {
1153-
$result->default = $this->rewriter->consume()->token;
1153+
// Consume the next token (could be a value, opening paren, etc.)
1154+
$default_token = $this->rewriter->consume();
1155+
$result->default = $default_token->token;
1156+
1157+
// Check if the default value is wrapped in parentheses (for function calls like (now()))
1158+
if ( $default_token->matches( WP_SQLite_Token::TYPE_OPERATOR, null, array( '(' ) ) ) {
1159+
// Track parenthesis depth to consume the complete expression
1160+
$paren_depth = 1;
1161+
$default_value = '(';
1162+
1163+
while ( $paren_depth > 0 && ( $next_token = $this->rewriter->consume() ) ) {
1164+
$default_value .= $next_token->token;
1165+
1166+
if ( $next_token->matches( WP_SQLite_Token::TYPE_OPERATOR, null, array( '(' ) ) ) {
1167+
++$paren_depth;
1168+
} elseif ( $next_token->matches( WP_SQLite_Token::TYPE_OPERATOR, null, array( ')' ) ) ) {
1169+
--$paren_depth;
1170+
}
1171+
}
1172+
1173+
$result->default = $default_value;
1174+
}
11541175
continue;
11551176
}
11561177

0 commit comments

Comments
 (0)