Skip to content

Commit 2f02bb0

Browse files
kyleconroyclaude
andauthored
Fix CursorDefinition.Select type and rename BooleanLikeExpression to LikePredicate (#40)
- 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 Co-authored-by: Claude <[email protected]>
1 parent eaa7db3 commit 2f02bb0

File tree

6 files changed

+12
-16
lines changed

6 files changed

+12
-16
lines changed

ast/boolean_like_expression.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ type BooleanLikeExpression struct {
66
SecondExpression ScalarExpression
77
EscapeExpression ScalarExpression
88
NotDefined bool
9+
OdbcEscape bool
910
}
1011

1112
func (b *BooleanLikeExpression) node() {}

ast/set_variable_statement.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ func (s *SetVariableStatement) statement() {}
1717

1818
// CursorDefinition represents a cursor definition.
1919
type CursorDefinition struct {
20-
Options []*CursorOption `json:"Options,omitempty"`
21-
Select QueryExpression `json:"Select,omitempty"`
20+
Options []*CursorOption `json:"Options,omitempty"`
21+
Select *SelectStatement `json:"Select,omitempty"`
2222
}
2323

2424
// CursorOption represents a cursor option like SCROLL or DYNAMIC.

parser/marshal.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1663,7 +1663,7 @@ func booleanExpressionToJSON(expr ast.BooleanExpression) jsonNode {
16631663
return node
16641664
case *ast.BooleanLikeExpression:
16651665
node := jsonNode{
1666-
"$type": "BooleanLikeExpression",
1666+
"$type": "LikePredicate",
16671667
}
16681668
if e.FirstExpression != nil {
16691669
node["FirstExpression"] = scalarExpressionToJSON(e.FirstExpression)
@@ -1675,6 +1675,7 @@ func booleanExpressionToJSON(expr ast.BooleanExpression) jsonNode {
16751675
node["EscapeExpression"] = scalarExpressionToJSON(e.EscapeExpression)
16761676
}
16771677
node["NotDefined"] = e.NotDefined
1678+
node["OdbcEscape"] = e.OdbcEscape
16781679
return node
16791680
case *ast.BooleanTernaryExpression:
16801681
node := jsonNode{
@@ -2216,7 +2217,7 @@ func cursorDefinitionToJSON(cd *ast.CursorDefinition) jsonNode {
22162217
node["Options"] = opts
22172218
}
22182219
if cd.Select != nil {
2219-
node["Select"] = queryExpressionToJSON(cd.Select)
2220+
node["Select"] = selectStatementToJSON(cd.Select)
22202221
}
22212222
return node
22222223
}
@@ -7552,12 +7553,7 @@ func declareCursorDefinitionToJSON(d *ast.CursorDefinition) jsonNode {
75527553
node["Options"] = opts
75537554
}
75547555
if d.Select != nil {
7555-
// For DeclareCursorStatement, we need to wrap the QueryExpression in a SelectStatement format
7556-
selectNode := jsonNode{
7557-
"$type": "SelectStatement",
7558-
"QueryExpression": queryExpressionToJSON(d.Select),
7559-
}
7560-
node["Select"] = selectNode
7556+
node["Select"] = selectStatementToJSON(d.Select)
75617557
}
75627558
return node
75637559
}

parser/parse_statements.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,7 @@ func (p *Parser) parseSetVariableStatement() (ast.Statement, error) {
846846
if err != nil {
847847
return nil, err
848848
}
849-
cursorDef.Select = qe
849+
cursorDef.Select = &ast.SelectStatement{QueryExpression: qe}
850850
}
851851
stmt.CursorDefinition = cursorDef
852852
} else {
@@ -5838,13 +5838,12 @@ func (p *Parser) parseDeclareCursorStatementContinued(cursorName *ast.Identifier
58385838
p.nextToken()
58395839
}
58405840

5841-
// Parse SELECT statement and extract its QueryExpression
5841+
// Parse SELECT statement
58425842
selectStmt, err := p.parseSelectStatement()
58435843
if err != nil {
58445844
return nil, err
58455845
}
5846-
// CursorDefinition.Select is a QueryExpression, so we extract it from the SelectStatement
5847-
stmt.CursorDefinition.Select = selectStmt.QueryExpression
5846+
stmt.CursorDefinition.Select = selectStmt
58485847

58495848
// Skip optional semicolon
58505849
if p.curTok.Type == TokenSemicolon {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"todo": true}
1+
{}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"todo": true}
1+
{}

0 commit comments

Comments
 (0)