Skip to content
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

fix variables not resolving in mysql ORDER BY statements #3115

Merged
merged 1 commit into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
28 changes: 28 additions & 0 deletions internal/endtoend/testdata/order_by_binds/mysql/go/query.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions internal/endtoend/testdata/order_by_binds/mysql/query.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ SELECT * FROM authors
WHERE id > sqlc.arg(min_id)
ORDER BY CASE WHEN sqlc.arg(sort_column) = 'name' THEN name END;

-- name: ListAuthorsColumnSortFnWtihArg :many
SELECT * FROM authors
ORDER BY MOD(id, sqlc.arg(mod_arg));

-- name: ListAuthorsNameSort :many
SELECT * FROM authors
WHERE id > sqlc.arg(min_id)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ SELECT * FROM authors
WHERE id > sqlc.arg(min_id)
ORDER BY CASE WHEN sqlc.arg(sort_column) = 'name' THEN name END;

-- name: ListAuthorsColumnSortFnWtihArg :many
SELECT * FROM authors
ORDER BY MOD(id, $1);

-- name: ListAuthorsNameSort :many
SELECT * FROM authors
WHERE id > sqlc.arg(min_id)
Expand Down
13 changes: 1 addition & 12 deletions internal/engine/dolphin/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -1025,18 +1025,7 @@ func (c *cc) convertOrderByClause(n *pcast.OrderByClause) ast.Node {
}
list := &ast.List{Items: []ast.Node{}}
for _, item := range n.Items {
switch item.Expr.(type) {
case *pcast.CaseExpr:
list.Items = append(list.Items, &ast.CaseWhen{
Expr: c.convert(item.Expr),
Location: item.Expr.OriginTextPosition(),
})
case *pcast.ColumnNameExpr:
list.Items = append(list.Items, &ast.CaseExpr{
Xpr: c.convert(item.Expr),
Location: item.Expr.OriginTextPosition(),
})
}
list.Items = append(list.Items, c.convert(item.Expr))
}
return list
}
Expand Down
Loading