sqlc
sqlc copied to clipboard
Fix `ORDER BY` arg parsing in sqlite
sqlc currently doesn't handle bound ORDER BY clauses in sqlite, nor does it have tests for this behavior. This PR attempts for rectify this. Closes https://github.com/sqlc-dev/sqlc/issues/3788.
currently, base behavior works but mixing params like so:
-- name: ListAuthorsColumnSortDirection :many
SELECT * FROM authors
WHERE id > ?
ORDER BY
CASE
WHEN @order_by = 'asc' THEN name
END ASC,
CASE
WHEN @order_by = 'desc' OR @order_by IS NULL THEN name
END DESC;
produces this incorrect output (question marks in CASE clauses should instead be same variable)
-- name: ListAuthorsColumnSortDirection :many
SELECT id, name, bio FROM authors
WHERE id > ?
ORDER BY
CASE
WHEN ? = 'asc' THEN name
END ASC,
CASE
WHEN ? = 'desc' OR ? IS NULL THEN name
END DESC
this can still be worked around by using named params in this case.
How can we get this PR merged? I'm currently running into this issue :(