MCPcopy Create free account
hub / github.com/araddon/qlbridge / parseSqlSelect

Method parseSqlSelect

rel/parse_sql.go:170–278  ·  view source on GitHub ↗

First keyword was SELECT, so use the SELECT parser rule-set

()

Source from the content-addressed store, hash-verified

168
169// First keyword was SELECT, so use the SELECT parser rule-set
170func (m *Sqlbridge) parseSqlSelect() (*SqlSelect, error) {
171
172 req := NewSqlSelect()
173 req.Raw = m.l.RawInput()
174 m.Next() // Consume Select?
175
176 // Optional DISTINCT keyword always immediately after SELECT KW
177 if m.Cur().T == lex.TokenDistinct {
178 m.Next()
179 req.Distinct = true
180 }
181
182 // columns
183 if err := parseColumns(m, m.funcs, req); err != nil {
184 return nil, err
185 }
186
187 // select @@myvar limit 1
188 if m.Cur().T == lex.TokenLimit {
189 if err := m.parseLimit(req); err != nil {
190 return nil, err
191 }
192 if m.isEnd() {
193 return req, nil
194 }
195 }
196
197 // SPECIAL END CASE for simple selects
198 // SELECT last_insert_id();
199 if m.Cur().T == lex.TokenEOS || m.Cur().T == lex.TokenEOF {
200 // valid end
201 return req, nil
202 }
203
204 // INTO
205 discardComments(m)
206 if err := m.parseInto(req); err != nil {
207 return nil, err
208 }
209
210 // FROM
211 discardComments(m)
212 if err := m.parseSources(req); err != nil {
213 return nil, err
214 }
215
216 // WHERE
217 discardComments(m)
218 if err := m.parseWhereSelect(req); err != nil {
219 return nil, err
220 }
221
222 // GROUP BY
223 discardComments(m)
224 if err := m.parseGroupBy(req); err != nil {
225 return nil, err
226 }
227

Callers 4

parseMethod · 0.95
parseSqlInsertMethod · 0.95
parseSourceSubQueryMethod · 0.95
parseWhereSubSelectMethod · 0.95

Calls 15

parseLimitMethod · 0.95
isEndMethod · 0.95
parseIntoMethod · 0.95
parseSourcesMethod · 0.95
parseWhereSelectMethod · 0.95
parseGroupByMethod · 0.95
parseHavingMethod · 0.95
parseOrderByMethod · 0.95
parseOffsetMethod · 0.95
parseAliasMethod · 0.95
FinalizeMethod · 0.95
NewSqlSelectFunction · 0.85

Tested by

no test coverage detected