Skip to content

fix(engine/sqlite): fixed to be able to find relation from WITH clause #2444

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 24, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix(engine/sqlite): fixed to be able to find relation from WITH clause
fix #2136
  • Loading branch information
orisano committed Jul 15, 2023
commit 5f27e7c8289e5835e55a1fc4d2b70aa1c8beea8c
22 changes: 22 additions & 0 deletions internal/engine/sqlite/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,25 @@ func (c *cc) convertMultiSelect_stmtContext(n *parser.Select_stmtContext) ast.No
var where ast.Node
var groups = []ast.Node{}
var having ast.Node
var ctes []ast.Node

if ct := n.Common_table_stmt(); ct != nil {
recursive := ct.RECURSIVE_() != nil
for _, cte := range ct.AllCommon_table_expression() {
tableName := identifier(cte.Table_name().GetText())
var cteCols ast.List
for _, col := range cte.AllColumn_name() {
cteCols.Items = append(cteCols.Items, NewIdentifer(col.GetText()))
}
ctes = append(ctes, &ast.CommonTableExpr{
Ctename: &tableName,
Ctequery: c.convert(cte.Select_stmt()),
Location: cte.GetStart().GetStart(),
Cterecursive: recursive,
Ctecolnames: &cteCols,
})
}
}

for _, icore := range n.AllSelect_core() {
core, ok := icore.(*parser.Select_coreContext)
Expand Down Expand Up @@ -377,6 +396,9 @@ func (c *cc) convertMultiSelect_stmtContext(n *parser.Select_stmtContext) ast.No
LimitCount: limitCount,
LimitOffset: limitOffset,
ValuesLists: &ast.List{},
WithClause: &ast.WithClause{
Ctes: &ast.List{Items: ctes},
},
}
}

Expand Down