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

Method MakeExecSqlStmt

pkg/sql/plpgsql/parser/lexer.go:119–191  ·  view source on GitHub ↗

MakeExecSqlStmt makes an Execute node.

()

Source from the content-addressed store, hash-verified

117
118// MakeExecSqlStmt makes an Execute node.
119func (l *lexer) MakeExecSqlStmt() (*plpgsqltree.Execute, error) {
120 if l.parser.Lookahead() != -1 {
121 // Push back the lookahead token so that it can be included.
122 l.PushBack(1)
123 }
124 // Push back the first token so that it's included in the SQL string.
125 l.PushBack(1)
126 startPos, endPos, _, err := l.readSQLConstruct(false /* isExpr */, false /* allowEmpty */, ';')
127 if err != nil {
128 return nil, err
129 }
130 // Move past the semicolon.
131 l.lastPos++
132
133 var haveInto, haveStrict bool
134 var intoStartPos, intoEndPos int
135 var target []plpgsqltree.Variable
136 firstTok := l.tokens[startPos]
137 tok := firstTok
138 for pos := startPos; pos < endPos; pos++ {
139 prevTok := tok
140 tok = l.tokens[pos]
141 if tok.id == INTO {
142 if prevTok.id == INSERT || prevTok.id == UPSERT ||
143 prevTok.id == MERGE || firstTok.id == IMPORT {
144 // INSERT INTO, UPSERT INTO, MERGE INTO, and IMPORT ... INTO are not
145 // INTO-targets.
146 continue
147 }
148 if haveInto {
149 return nil, errors.New("INTO specified more than once")
150 }
151 haveInto = true
152 intoStartPos = pos
153 pos++
154 if pos+1 < endPos && l.tokens[pos].id == STRICT {
155 haveStrict = true
156 pos++
157 }
158 // Read in one or more comma-separated variables as the INTO target.
159 target, intoEndPos, err = l.readTarget(pos, endPos)
160 if err != nil {
161 return nil, err
162 }
163 }
164 }
165
166 var sql string
167 if haveInto {
168 sql = l.getStr(startPos, intoStartPos) + l.getStr(intoEndPos, endPos)
169 } else {
170 sql = l.getStr(startPos, endPos)
171 }
172 sqlStmt, err := parser.ParseOne(sql)
173 if err != nil {
174 return nil, err
175 }
176

Callers 1

ParseMethod · 0.80

Calls 9

PushBackMethod · 0.95
readSQLConstructMethod · 0.95
readTargetMethod · 0.95
getStrMethod · 0.95
ParseOneFunction · 0.92
NewFunction · 0.92
MakeAnnotationsFunction · 0.92
LookaheadMethod · 0.65
StatementReturnTypeMethod · 0.65

Tested by

no test coverage detected