AppendOperations implements the interface Statement.
(ops *[]InterpreterOperation, stack *InterpreterStack)
| 92 | |
| 93 | // AppendOperations implements the interface Statement. |
| 94 | func (stmt Block) AppendOperations(ops *[]InterpreterOperation, stack *InterpreterStack) error { |
| 95 | stack.PushScope() |
| 96 | stack.SetLabel(stmt.Label) // If the label is empty, then this won't change anything |
| 97 | var loop string |
| 98 | if stmt.IsLoop { |
| 99 | loop = "_" |
| 100 | // All loops need a label, so we'll make an anonymous one if an explicit one hasn't been given |
| 101 | if len(stmt.Label) == 0 { |
| 102 | stack.SetAnonymousLabel() |
| 103 | stmt.Label = stack.GetCurrentLabel() |
| 104 | } |
| 105 | } |
| 106 | *ops = append(*ops, InterpreterOperation{ |
| 107 | OpCode: OpCode_ScopeBegin, |
| 108 | PrimaryData: stmt.Label, |
| 109 | Target: loop, |
| 110 | }) |
| 111 | for _, variable := range stmt.Variables { |
| 112 | op := InterpreterOperation{ |
| 113 | OpCode: OpCode_Declare, |
| 114 | PrimaryData: variable.Type, |
| 115 | Target: variable.Name, |
| 116 | } |
| 117 | var val any |
| 118 | if variable.Default != "" { |
| 119 | op.SecondaryData = []string{variable.Default} |
| 120 | val = variable.Default |
| 121 | } |
| 122 | if !variable.IsParameter { |
| 123 | *ops = append(*ops, op) |
| 124 | } |
| 125 | stack.NewVariableWithValue(variable.Name, nil, val) |
| 126 | } |
| 127 | for _, record := range stmt.Records { |
| 128 | var fakeSch sql.Schema |
| 129 | for _, fieldName := range record.Fields { |
| 130 | fakeSch = append(fakeSch, &sql.Column{Name: fieldName}) |
| 131 | } |
| 132 | stack.NewRecord(record.Name, fakeSch, nil) |
| 133 | } |
| 134 | for _, innerStmt := range stmt.Body { |
| 135 | if err := innerStmt.AppendOperations(ops, stack); err != nil { |
| 136 | return err |
| 137 | } |
| 138 | } |
| 139 | *ops = append(*ops, InterpreterOperation{ |
| 140 | OpCode: OpCode_ScopeEnd, |
| 141 | }) |
| 142 | stack.PopScope() |
| 143 | return nil |
| 144 | } |
| 145 | |
| 146 | // ExecuteSQL represents a standard SQL statement's execution (including the INTO syntax). |
| 147 | type ExecuteSQL struct { |
nothing calls this directly
no test coverage detected