MCPcopy
hub / github.com/sqlc-dev/sqlc / convertMultiSelect_stmtContext

Method convertMultiSelect_stmtContext

internal/engine/sqlite/convert.go:376–522  ·  view source on GitHub ↗
(n *parser.Select_stmtContext)

Source from the content-addressed store, hash-verified

374}
375
376func (c *cc) convertMultiSelect_stmtContext(n *parser.Select_stmtContext) ast.Node {
377 var ctes ast.List
378 if ct := n.Common_table_stmt(); ct != nil {
379 recursive := ct.RECURSIVE_() != nil
380 for _, cte := range ct.AllCommon_table_expression() {
381 tableName := identifier(cte.Table_name().GetText())
382 var cteCols ast.List
383 for _, col := range cte.AllColumn_name() {
384 cteCols.Items = append(cteCols.Items, NewIdentifier(col.GetText()))
385 }
386 ctes.Items = append(ctes.Items, &ast.CommonTableExpr{
387 Ctename: &tableName,
388 Ctequery: c.convert(cte.Select_stmt()),
389 Location: cte.GetStart().GetStart(),
390 Cterecursive: recursive,
391 Ctecolnames: &cteCols,
392 })
393 }
394 }
395
396 var selectStmt *ast.SelectStmt
397 for s, icore := range n.AllSelect_core() {
398 core, ok := icore.(*parser.Select_coreContext)
399 if !ok {
400 continue
401 }
402 cols := c.getCols(core)
403 tables := c.getTables(core)
404
405 var where ast.Node
406 i := 0
407 if core.WHERE_() != nil {
408 where = c.convert(core.Expr(i))
409 i++
410 }
411
412 var groups ast.List
413 var having ast.Node
414 if core.GROUP_() != nil {
415 l := len(core.AllExpr()) - i
416 if core.HAVING_() != nil {
417 having = c.convert(core.Expr(l))
418 l--
419 }
420
421 for i < l {
422 groups.Items = append(groups.Items, c.convert(core.Expr(i)))
423 i++
424 }
425 }
426 var window ast.List
427 if core.WINDOW_() != nil {
428 for w, windowNameCtx := range core.AllWindow_name() {
429 windowName := identifier(windowNameCtx.GetText())
430 windowDef := core.Window_defn(w)
431
432 _ = windowDef.Base_window_name()
433 var partitionBy ast.List

Callers 1

convertMethod · 0.95

Calls 15

convertMethod · 0.95
getColsMethod · 0.95
getTablesMethod · 0.95
GetTextMethod · 0.80
GetStartMethod · 0.80
identifierFunction · 0.70
NewIdentifierFunction · 0.70
Common_table_stmtMethod · 0.65
RECURSIVE_Method · 0.65
Table_nameMethod · 0.65

Tested by

no test coverage detected