Skip to content
New issue

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

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

Already on GitHub? # to your account

fix(mysql): Handle simplified CASE statements #2852

Merged
merged 1 commit into from
Oct 13, 2023
Merged

Conversation

kyleconroy
Copy link
Collaborator

@kyleconroy kyleconroy commented Oct 13, 2023

MySQL and PostgreSQL now have the same behavior, generating a nullable string parameter. That behavior isn't right, as we'd expect the parameter to be a boolean. This can be fixed by using a type case or the new annotations in #2800.

Fixes #2847

SET value = CASE ? WHEN true THEN 'Hello' WHEN false THEN 'Goodbye' ELSE value END
`

func (q *Queries) Update(ctx context.Context, value sql.NullString) error {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't this generated func parameter be a boolean to match the cases and not a string which matches the output?

@@ -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.

@kyleconroy kyleconroy merged commit 9313007 into main Oct 13, 2023
7 checks passed
@kyleconroy kyleconroy deleted the kyle/mysql-case-value branch October 13, 2023 18:37
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

No parameter gets generated for CASE ? WHEN...
2 participants