Skip to content

GetBoolean might be called on a decimal #707

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

Merged
merged 2 commits into from
Sep 30, 2019

Conversation

lauxjpn
Copy link
Contributor

@lauxjpn lauxjpn commented Sep 30, 2019

The following test (and 1 more) currently fails in Pomelo.MySql:
https://github.com/aspnet/EntityFrameworkCore/blob/817aaea6ca1a24a29e8e9f3a7b2dd3748956d942/test/EFCore.Specification.Tests/Query/GearsOfWarQueryTestBase.cs#L1503-L1519

It gets translated to:

SELECT COALESCE(`w0`.`IsAutomatic`, FALSE)
FROM `Weapons` AS `w`
LEFT JOIN `Weapons` AS `w0` ON `w`.`SynergyWithId` = `w0`.`Id`
ORDER BY `w`.`Id`

It seems that COALESCE is returning a decimal for IsAutomatic, though the column is actually of type bit(1). The code expects a bool and calls GetBoolean, which then throws.

This fix allows the explicit conversion from decimal to bool within Row.GetBoolean().

This is not critical, so we don't need a quick release for this.

@bgrainger
Copy link
Member

FWIW, the promotion of the BIT(n) data type to DECIMAL when using COALESCE is another reason why I would strongly recommend BOOL (aka TINYINT(1)) as the preferred MySQL data type for Boolean data, not BIT(1).

The PR looks good, I will merge it.

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

Successfully merging this pull request may close these issues.

2 participants