Skip to content

Fix for casting boolean values in MySQL#538

Merged
josevalim merged 2 commits into
elixir-ecto:masterfrom
m1dnight:master
Jul 19, 2023
Merged

Fix for casting boolean values in MySQL#538
josevalim merged 2 commits into
elixir-ecto:masterfrom
m1dnight:master

Conversation

@m1dnight

Copy link
Copy Markdown
Contributor

I'm not sure if this fix is sufficient enough. I've tried it locally and it solves my problem.

One thing I'm not sure is covered is, what if you pass a value that's not true or false to the cast expression? I assume that's just invalid SQL?

@greg-rychlewski

Copy link
Copy Markdown
Member

I have a suspicion this will create discrepancies between psql/mysql but not 100% sure. Do you know what type("true", :boolean) and type("false", :boolean) would return for mysql?

@m1dnight

Copy link
Copy Markdown
Contributor Author
select if("true", TRUE, FALSE); -- false
select if("false", TRUE, FALSE);-- false
select if(False, TRUE, FALSE);-- false
select if(TruE, TRUE, FALSE);-- true
select if(TRUE, TRUE, FALSE);-- true
select if(true, TRUE, FALSE);-- true
select if(0, TRUE, FALSE);-- false
select if(1, TRUE, FALSE);-- true

As far as I understand, there is not really a boolean type in MySQL, much like in C. So anything is false unless it's 1 or true, or TRUE.

@greg-rychlewski

Copy link
Copy Markdown
Member

Ah I get it now. Thank you. LGTM!

Comment thread lib/ecto/adapters/myxql/connection.ex Outdated
@josevalim josevalim merged commit cfb3dad into elixir-ecto:master Jul 19, 2023
@josevalim

Copy link
Copy Markdown
Member

💚 💙 💜 💛 ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants