Skip to content

Commit 4e5e399

Browse files
author
James Cor
committed
cleaning up
1 parent 8c87be3 commit 4e5e399

File tree

2 files changed

+21
-45
lines changed

2 files changed

+21
-45
lines changed

sql/procedures/interpreter_logic.go

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,6 @@ type InterpreterNode interface {
4040
SetSchema(sch sql.Schema)
4141
}
4242

43-
type Parameter struct {
44-
Name string
45-
Type sql.Type
46-
Value any
47-
}
48-
4943
func replaceVariablesInExpr(ctx *sql.Context, stack *InterpreterStack, expr ast.SQLNode, asOf *ast.AsOf) (ast.SQLNode, error) {
5044
switch e := expr.(type) {
5145
case *ast.ColName:
@@ -797,22 +791,10 @@ func execOp(ctx *sql.Context, runner sql.StatementRunner, stack *InterpreterStac
797791
}
798792

799793
// Call runs the contained operations on the given runner.
800-
func Call(ctx *sql.Context, iNode InterpreterNode, params []*Parameter) (sql.RowIter, *InterpreterStack, error) {
801-
for _, param := range params {
802-
var spp *sql.StoredProcParam
803-
spp = ctx.Session.GetStoredProcParam(param.Name)
804-
for spp != nil {
805-
spp.Value = param.Value
806-
spp = spp.Reference
807-
}
808-
}
809-
794+
func Call(ctx *sql.Context, iNode InterpreterNode) (sql.RowIter, *InterpreterStack, error) {
810795
// Set up the initial state of the function
811796
counter := -1 // We increment before accessing, so start at -1
812797
stack := NewInterpreterStack()
813-
//for _, param := range params {
814-
// stack.NewVariableWithValue(param.Name, param.Type, param.Value)
815-
//}
816798

817799
var asOf *ast.AsOf
818800
if asOfExpr := iNode.GetAsOf(); asOfExpr != nil {

sql/rowexec/proc.go

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -209,31 +209,25 @@ func (b *BaseBuilder) buildCall(ctx *sql.Context, n *plan.Call, row sql.Row) (sq
209209
}, nil
210210
}
211211

212-
// TODO: replace with direct ctx modification
213-
procParams := make([]*procedures.Parameter, len(n.Params))
212+
// Initialize parameters
214213
for i, paramExpr := range n.Params {
215214
param := n.Procedure.Params[i]
216-
paramName := strings.ToLower(param.Name)
217-
paramType := param.Type
218215
paramVal, err := paramExpr.Eval(ctx, row)
219216
if err != nil {
220217
return nil, err
221218
}
222-
paramVal, _, err = paramType.Convert(ctx, paramVal)
219+
paramVal, _, err = param.Type.Convert(ctx, paramVal)
223220
if err != nil {
224221
return nil, err
225222
}
226-
procParams[i] = &procedures.Parameter{
227-
Name: paramName,
228-
Value: paramVal,
229-
Type: paramType,
223+
paramName := strings.ToLower(param.Name)
224+
for spp := ctx.Session.GetStoredProcParam(paramName); spp != nil; {
225+
spp.Value = paramVal
226+
spp = spp.Reference
230227
}
231228
}
232229

233-
rowIter, _, err := procedures.Call(ctx, n, procParams)
234-
if err != nil && err.Error() == "context canceled" {
235-
print()
236-
}
230+
rowIter, _, err := procedures.Call(ctx, n)
237231
if err != nil {
238232
return nil, err
239233
}
@@ -244,25 +238,25 @@ func (b *BaseBuilder) buildCall(ctx *sql.Context, n *plan.Call, row sql.Row) (sq
244238
continue
245239
}
246240
// Set all user and system variables from INOUT and OUT params
247-
stackVar := ctx.Session.GetStoredProcParam(procParam.Name) // TODO: ToLower?
241+
paramName := strings.ToLower(procParam.Name)
242+
spp := ctx.Session.GetStoredProcParam(paramName)
243+
if spp == nil {
244+
return nil, fmt.Errorf("parameter `%s` not found", paramName)
245+
}
248246
switch p := param.(type) {
249247
case *expression.ProcedureParam:
250-
err = p.Set(ctx, stackVar.Value, stackVar.Type)
251-
if err != nil {
252-
return nil, err
253-
}
248+
err = p.Set(ctx, spp.Value, spp.Type)
254249
case *expression.UserVar:
255-
val := stackVar.Value
256-
if procParam.Direction == plan.ProcedureParamDirection_Out && !stackVar.HasBeenSet {
250+
val := spp.Value
251+
if procParam.Direction == plan.ProcedureParamDirection_Out && !spp.HasBeenSet {
257252
val = nil
258253
}
259-
err = ctx.SetUserVariable(ctx, p.Name, val, stackVar.Type)
260-
if err != nil {
261-
return nil, err
262-
}
254+
err = ctx.SetUserVariable(ctx, p.Name, val, spp.Type)
263255
case *expression.SystemVar:
264-
// This should have been caught by the analyzer, so a major bug exists somewhere
265-
return nil, fmt.Errorf("unable to set `%s` as it is a system variable", p.Name)
256+
err = fmt.Errorf("unable to set `%s` as it is a system variable", p.Name)
257+
}
258+
if err != nil {
259+
return nil, err
266260
}
267261
}
268262

0 commit comments

Comments
 (0)