Next returns the next command in the batch.
()
| 150 | |
| 151 | // Next returns the next command in the batch. |
| 152 | func (b *Batcher) Next() (Command, error) { |
| 153 | var i int |
| 154 | |
| 155 | if b.rawLen == 0 { |
| 156 | s, firstByteOffset, err := b.read() |
| 157 | if err != nil { |
| 158 | return nil, err |
| 159 | } |
| 160 | b.firstByteOffset = firstByteOffset |
| 161 | b.raw = []rune(s) |
| 162 | b.rawLen = len(b.raw) |
| 163 | } |
| 164 | |
| 165 | var command Command |
| 166 | var ok bool |
| 167 | var scannedCommand bool |
| 168 | |
| 169 | parse: |
| 170 | for ; i < b.rawLen; i++ { |
| 171 | c, next := b.raw[i], grab(b.raw, i+1, b.rawLen) |
| 172 | switch { |
| 173 | // we're in a quoted string |
| 174 | case b.quote != 0: |
| 175 | i, ok = b.readString(b.raw, i, b.rawLen, b.quote) |
| 176 | if ok { |
| 177 | b.quote = 0 |
| 178 | } |
| 179 | // inside a multiline comment |
| 180 | case b.comment: |
| 181 | i, ok = readMultilineComment(b.raw, i, b.rawLen) |
| 182 | b.comment = !ok |
| 183 | // start of a string |
| 184 | case c == '\'' || c == '"' || c == '[': |
| 185 | b.quote = c |
| 186 | // inline sql comment, skip to end of line |
| 187 | case c == '-' && next == '-': |
| 188 | i = b.rawLen |
| 189 | // start a multi-line comment |
| 190 | case c == '/' && next == '*': |
| 191 | b.comment = true |
| 192 | i++ |
| 193 | // continue processing quoted string or multiline comment |
| 194 | case b.quote != 0 || b.comment: |
| 195 | |
| 196 | // We do not care about the variable reference for now. |
| 197 | // Handle variable references |
| 198 | // case c == '$' && next == '(': |
| 199 | // vi, ok := readVariableReference(b.raw, i+2, b.rawLen) |
| 200 | // if ok { |
| 201 | // b.addVariableLocation(i, string(b.raw[i+2:vi])) |
| 202 | // i = vi |
| 203 | |
| 204 | // } else { |
| 205 | // err = syntaxError(b.linecount) |
| 206 | // break parse |
| 207 | // } |
| 208 | |
| 209 | // Commands have to be alone on the line |