From 18b8f6bd015923e269248f8c09432f9bc63fe3c7 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 23 Dec 2025 16:04:38 +0000 Subject: [PATCH] Fix CursorDefinition.Select type and rename BooleanLikeExpression to LikePredicate - Change CursorDefinition.Select from QueryExpression to *SelectStatement - Rename JSON $type from BooleanLikeExpression to LikePredicate - Add OdbcEscape field to BooleanLikeExpression struct - Enable BaselinesCommon_SetVariableStatementTests and SetVariableStatementTests --- ast/boolean_like_expression.go | 1 + ast/set_variable_statement.go | 4 ++-- parser/marshal.go | 12 ++++-------- parser/parse_statements.go | 7 +++---- .../metadata.json | 2 +- .../testdata/SetVariableStatementTests/metadata.json | 2 +- 6 files changed, 12 insertions(+), 16 deletions(-) diff --git a/ast/boolean_like_expression.go b/ast/boolean_like_expression.go index 3e3896e0..3cfd49fe 100644 --- a/ast/boolean_like_expression.go +++ b/ast/boolean_like_expression.go @@ -6,6 +6,7 @@ type BooleanLikeExpression struct { SecondExpression ScalarExpression EscapeExpression ScalarExpression NotDefined bool + OdbcEscape bool } func (b *BooleanLikeExpression) node() {} diff --git a/ast/set_variable_statement.go b/ast/set_variable_statement.go index 996c8f57..869a7d4d 100644 --- a/ast/set_variable_statement.go +++ b/ast/set_variable_statement.go @@ -17,8 +17,8 @@ func (s *SetVariableStatement) statement() {} // CursorDefinition represents a cursor definition. type CursorDefinition struct { - Options []*CursorOption `json:"Options,omitempty"` - Select QueryExpression `json:"Select,omitempty"` + Options []*CursorOption `json:"Options,omitempty"` + Select *SelectStatement `json:"Select,omitempty"` } // CursorOption represents a cursor option like SCROLL or DYNAMIC. diff --git a/parser/marshal.go b/parser/marshal.go index 70850d0a..3f47847a 100644 --- a/parser/marshal.go +++ b/parser/marshal.go @@ -1663,7 +1663,7 @@ func booleanExpressionToJSON(expr ast.BooleanExpression) jsonNode { return node case *ast.BooleanLikeExpression: node := jsonNode{ - "$type": "BooleanLikeExpression", + "$type": "LikePredicate", } if e.FirstExpression != nil { node["FirstExpression"] = scalarExpressionToJSON(e.FirstExpression) @@ -1675,6 +1675,7 @@ func booleanExpressionToJSON(expr ast.BooleanExpression) jsonNode { node["EscapeExpression"] = scalarExpressionToJSON(e.EscapeExpression) } node["NotDefined"] = e.NotDefined + node["OdbcEscape"] = e.OdbcEscape return node case *ast.BooleanTernaryExpression: node := jsonNode{ @@ -2216,7 +2217,7 @@ func cursorDefinitionToJSON(cd *ast.CursorDefinition) jsonNode { node["Options"] = opts } if cd.Select != nil { - node["Select"] = queryExpressionToJSON(cd.Select) + node["Select"] = selectStatementToJSON(cd.Select) } return node } @@ -7552,12 +7553,7 @@ func declareCursorDefinitionToJSON(d *ast.CursorDefinition) jsonNode { node["Options"] = opts } if d.Select != nil { - // For DeclareCursorStatement, we need to wrap the QueryExpression in a SelectStatement format - selectNode := jsonNode{ - "$type": "SelectStatement", - "QueryExpression": queryExpressionToJSON(d.Select), - } - node["Select"] = selectNode + node["Select"] = selectStatementToJSON(d.Select) } return node } diff --git a/parser/parse_statements.go b/parser/parse_statements.go index d16a68e5..34865d5a 100644 --- a/parser/parse_statements.go +++ b/parser/parse_statements.go @@ -846,7 +846,7 @@ func (p *Parser) parseSetVariableStatement() (ast.Statement, error) { if err != nil { return nil, err } - cursorDef.Select = qe + cursorDef.Select = &ast.SelectStatement{QueryExpression: qe} } stmt.CursorDefinition = cursorDef } else { @@ -5838,13 +5838,12 @@ func (p *Parser) parseDeclareCursorStatementContinued(cursorName *ast.Identifier p.nextToken() } - // Parse SELECT statement and extract its QueryExpression + // Parse SELECT statement selectStmt, err := p.parseSelectStatement() if err != nil { return nil, err } - // CursorDefinition.Select is a QueryExpression, so we extract it from the SelectStatement - stmt.CursorDefinition.Select = selectStmt.QueryExpression + stmt.CursorDefinition.Select = selectStmt // Skip optional semicolon if p.curTok.Type == TokenSemicolon { diff --git a/parser/testdata/BaselinesCommon_SetVariableStatementTests/metadata.json b/parser/testdata/BaselinesCommon_SetVariableStatementTests/metadata.json index ccffb5b9..9e26dfee 100644 --- a/parser/testdata/BaselinesCommon_SetVariableStatementTests/metadata.json +++ b/parser/testdata/BaselinesCommon_SetVariableStatementTests/metadata.json @@ -1 +1 @@ -{"todo": true} \ No newline at end of file +{} \ No newline at end of file diff --git a/parser/testdata/SetVariableStatementTests/metadata.json b/parser/testdata/SetVariableStatementTests/metadata.json index ccffb5b9..9e26dfee 100644 --- a/parser/testdata/SetVariableStatementTests/metadata.json +++ b/parser/testdata/SetVariableStatementTests/metadata.json @@ -1 +1 @@ -{"todo": true} \ No newline at end of file +{} \ No newline at end of file