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(mysql): Handle simplified CASE statements #2852

Merged
merged 1 commit into from
Oct 13, 2023
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
1 change: 1 addition & 0 deletions internal/endtoend/testdata/case_value_param/issue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/sqlc-dev/sqlc/issues/2847
31 changes: 31 additions & 0 deletions internal/endtoend/testdata/case_value_param/mysql/go/db.go

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

14 changes: 14 additions & 0 deletions internal/endtoend/testdata/case_value_param/mysql/go/models.go

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

21 changes: 21 additions & 0 deletions internal/endtoend/testdata/case_value_param/mysql/go/query.sql.go

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

3 changes: 3 additions & 0 deletions internal/endtoend/testdata/case_value_param/mysql/query.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- name: Update :exec
UPDATE testing
SET value = CASE ? WHEN true THEN 'Hello' WHEN false THEN 'Goodbye' ELSE value END;
4 changes: 4 additions & 0 deletions internal/endtoend/testdata/case_value_param/mysql/schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CREATE TABLE testing (
id int PRIMARY KEY,
value text
);
9 changes: 9 additions & 0 deletions internal/endtoend/testdata/case_value_param/mysql/sqlc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: "2"
sql:
- engine: "mysql"
schema: "schema.sql"
queries: "query.sql"
gen:
go:
package: "querytest"
out: "go"
32 changes: 32 additions & 0 deletions internal/endtoend/testdata/case_value_param/postgresql/go/db.go

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

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

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
@@ -0,0 +1,3 @@
-- name: Update :exec
UPDATE testing
SET value = CASE $1 WHEN true THEN 'Hello' WHEN false THEN 'Goodbye' ELSE value END;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CREATE TABLE testing (
id int PRIMARY KEY,
value text
);
10 changes: 10 additions & 0 deletions internal/endtoend/testdata/case_value_param/postgresql/sqlc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: "2"
sql:
- engine: "postgresql"
schema: "schema.sql"
queries: "query.sql"
gen:
go:
package: "querytest"
out: "go"
sql_package: "pgx/v5"
1 change: 1 addition & 0 deletions internal/engine/dolphin/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,7 @@ func (c *cc) convertCaseExpr(n *pcast.CaseExpr) ast.Node {
list.Items = append(list.Items, c.convertWhenClause(n))
}
return &ast.CaseExpr{
Arg: c.convert(n.Value),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After looking at the test output, I think n.Value isn't correct here.

Args: list,
Defresult: c.convert(n.ElseClause),
Location: n.OriginTextPosition(),
Expand Down
Loading