MCPcopy Create free account
hub / github.com/cockroachdb/cockroachdb-parser / MakeFetchOrMoveStmt

Method MakeFetchOrMoveStmt

pkg/sql/plpgsql/parser/lexer.go:248–307  ·  view source on GitHub ↗
(isMove bool)

Source from the content-addressed store, hash-verified

246}
247
248func (l *lexer) MakeFetchOrMoveStmt(isMove bool) (plpgsqltree.Statement, error) {
249 if l.parser.Lookahead() != -1 {
250 // Push back the lookahead token so that it can be included.
251 l.PushBack(1)
252 }
253 prefix := "FETCH "
254 if isMove {
255 prefix = "MOVE "
256 }
257 sqlStr, terminator, err := l.ReadSqlStatement(INTO, ';')
258 if err != nil {
259 return nil, err
260 }
261 sqlStr = prefix + sqlStr
262 sqlStmt, err := parser.ParseOne(sqlStr)
263 if err != nil {
264 return nil, err
265 }
266 var cursor tree.CursorStmt
267 switch t := sqlStmt.AST.(type) {
268 case *tree.FetchCursor:
269 cursor = t.CursorStmt
270 case *tree.MoveCursor:
271 cursor = t.CursorStmt
272 default:
273 return nil, errors.Newf("invalid FETCH or MOVE syntax")
274 }
275 var target []plpgsqltree.Variable
276 if !isMove {
277 if terminator != INTO {
278 return nil, errors.Newf("invalid syntax for FETCH")
279 }
280 // Read past the INTO.
281 l.lastPos++
282 startPos, endPos, _, err := l.readSQLConstruct(true /* isExpr */, false /* allowEmpty */, ';')
283 if err != nil {
284 return nil, err
285 }
286 var targetEnd int
287 target, targetEnd, err = l.readTarget(startPos, endPos)
288 if err != nil {
289 return nil, err
290 }
291 if targetEnd != endPos {
292 return nil, errors.Newf("expected INTO target to be a comma-separated list")
293 }
294 if len(target) == 0 {
295 return nil, errors.Newf("expected INTO target")
296 }
297 }
298 // Move past the semicolon.
299 l.lastPos++
300 ann := tree.MakeAnnotations(sqlStmt.NumAnnotations)
301 return &plpgsqltree.Fetch{
302 Cursor: cursor,
303 Target: target,
304 IsMove: isMove,
305 Annotations: &ann,

Callers 1

ParseMethod · 0.80

Calls 7

PushBackMethod · 0.95
ReadSqlStatementMethod · 0.95
readSQLConstructMethod · 0.95
readTargetMethod · 0.95
ParseOneFunction · 0.92
MakeAnnotationsFunction · 0.92
LookaheadMethod · 0.65

Tested by

no test coverage detected