@@ -39,42 +39,6 @@ type Parameter struct {
3939 Value any
4040}
4141
42- func unreplaceVariablesInExpr (stack * InterpreterStack , expr ast.SQLNode ) ast.SQLNode {
43- switch e := expr .(type ) {
44- case * ast.AliasedExpr :
45- newExpr := unreplaceVariablesInExpr (stack , e .Expr )
46- e .Expr = newExpr .(ast.Expr )
47- case * ast.BinaryExpr :
48- newLeftExpr := unreplaceVariablesInExpr (stack , e .Left )
49- newRightExpr := unreplaceVariablesInExpr (stack , e .Right )
50- e .Left = newLeftExpr .(ast.Expr )
51- e .Right = newRightExpr .(ast.Expr )
52- case * ast.ComparisonExpr :
53- newLeftExpr := unreplaceVariablesInExpr (stack , e .Left )
54- newRightExpr := unreplaceVariablesInExpr (stack , e .Right )
55- e .Left = newLeftExpr .(ast.Expr )
56- e .Right = newRightExpr .(ast.Expr )
57- case * ast.FuncExpr :
58- for i := range e .Exprs {
59- newExpr := unreplaceVariablesInExpr (stack , e .Exprs [i ])
60- e .Exprs [i ] = newExpr .(ast.SelectExpr )
61- }
62- case * ast.NotExpr :
63- newExpr := unreplaceVariablesInExpr (stack , e .Expr )
64- e .Expr = newExpr .(ast.Expr )
65- case * ast.Set :
66- for _ , setExpr := range e .Exprs {
67- newExpr := unreplaceVariablesInExpr (stack , setExpr .Expr )
68- setExpr .Expr = newExpr .(ast.Expr )
69- }
70- case * ast.SQLVal :
71- if oldVal , ok := stack .replaceMap [expr ]; ok {
72- return oldVal
73- }
74- }
75- return expr
76- }
77-
7842func replaceVariablesInExpr (stack * InterpreterStack , expr ast.SQLNode ) (ast.SQLNode , error ) {
7943 switch e := expr .(type ) {
8044 case * ast.AliasedExpr :
@@ -136,8 +100,11 @@ func replaceVariablesInExpr(stack *InterpreterStack, expr ast.SQLNode) (ast.SQLN
136100 return expr , nil
137101 }
138102 newExpr := iv .ToAST ()
139- stack .replaceMap [newExpr ] = e
140- return newExpr , nil
103+ return & ast.ColName {
104+ Name : e .Name ,
105+ Qualifier : e .Qualifier ,
106+ StoredProcVal : newExpr ,
107+ }, nil
141108 }
142109 return expr , nil
143110}
@@ -207,12 +174,6 @@ func Call(ctx *sql.Context, iNode InterpreterNode, params []*Parameter) (any, er
207174 }
208175 rowIters = append (rowIters , rowIter )
209176
210- for i := range selectStmt .SelectExprs {
211- newNode := unreplaceVariablesInExpr (& stack , selectStmt .SelectExprs [i ])
212- selectStmt .SelectExprs [i ] = newNode .(ast.SelectExpr )
213- }
214- stack .replaceMap = map [ast.SQLNode ]ast.SQLNode {}
215-
216177 case OpCode_Declare :
217178 declareStmt := operation .PrimaryData .(* ast.Declare )
218179 for _ , decl := range declareStmt .Variables .Names {
@@ -259,14 +220,9 @@ func Call(ctx *sql.Context, iNode InterpreterNode, params []*Parameter) (any, er
259220 return nil , err
260221 }
261222
262- for i := range selectStmt .SelectExprs {
263- newNode := unreplaceVariablesInExpr (& stack , selectStmt .SelectExprs [i ])
264- selectStmt .SelectExprs [i ] = newNode .(ast.SelectExpr )
265- }
266- stack .replaceMap = map [ast.SQLNode ]ast.SQLNode {}
267-
268223 case OpCode_Exception :
269- // TODO: implement
224+ return nil , operation .Error
225+
270226 case OpCode_Execute :
271227 // TODO: replace variables
272228 stmt , err := replaceVariablesInExpr (& stack , operation .PrimaryData )
@@ -279,9 +235,6 @@ func Call(ctx *sql.Context, iNode InterpreterNode, params []*Parameter) (any, er
279235 }
280236 rowIters = append (rowIters , rowIter )
281237
282- stmt = unreplaceVariablesInExpr (& stack , stmt )
283- stack .replaceMap = map [ast.SQLNode ]ast.SQLNode {}
284-
285238 case OpCode_Goto :
286239 // We must compare to the index - 1, so that the increment hits our target
287240 if counter <= operation .Index {
@@ -341,12 +294,6 @@ func Call(ctx *sql.Context, iNode InterpreterNode, params []*Parameter) (any, er
341294 counter = operation .Index - 1 // index of the else block, offset by 1
342295 }
343296
344- for i := range selectStmt .SelectExprs {
345- newNode := unreplaceVariablesInExpr (& stack , selectStmt .SelectExprs [i ])
346- selectStmt .SelectExprs [i ] = newNode .(ast.SelectExpr )
347- }
348- stack .replaceMap = map [ast.SQLNode ]ast.SQLNode {}
349-
350297 case OpCode_ScopeBegin :
351298 stack .PushScope ()
352299 case OpCode_ScopeEnd :
0 commit comments