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

Clean way to prevent TypeConverter from casting values from TINYINT column into booleans #1034

Open
FD-ado opened this issue May 29, 2024 · 3 comments
Assignees

Comments

@FD-ado
Copy link

FD-ado commented May 29, 2024

Hi,

first of all, thanks a lot for your great work - we've been using the PHP CRUD API happily for quite a while now!

We've just now run into an issue that causes some trouble in one of our projects: we have a MySQL database and use TINYINT columns for some values. We now see that those values get converted into boolean values. - This is caused by the TypeConverterand specifically by the line 'tinyint(1)' => 'boolean', (toJdbc).

In our case, this is not only inconvenient but leads to veritable errors because we use TINYINTs intentionally (we cover more than just two states - i.e. the values can be other integers than just 0 and 1.

Is there a clean way to disable this specific type conversion? (For now, we switch the affected column types from TINYINT to INT - but we think that this conversion might cause trouble in other projects, too, and might be a bit too much of magic under the hood.)

Thanks a lot again!

Cheers,
Andreas

@mevdschee
Copy link
Owner

mevdschee commented May 29, 2024

Hi Andreas,

This is caused by the TypeConverterand specifically by the line 'tinyint(1)' => 'boolean', (toJdbc).

Yes, indeed.

Is there a clean way to disable this specific type conversion?

No, not at the moment.

but we think that this conversion might cause trouble in other projects, too, and might be a bit too much of magic under the hood

Probably, but there is no boolean type in MySQL, so what other type would map you map to boolean instead?

Kind regards,

Maurits

@mevdschee mevdschee self-assigned this May 29, 2024
@FD-ado
Copy link
Author

FD-ado commented May 29, 2024

A reply at lightning speed! -- Yes, I get your point and I agree with you. So, issue closed I guess (in lightning speed, too). :-)

Maybe, though, you could consider adding a hint to the README pointing out that the TINYINT column type is used as a stand-in for the non-existent BOOLEAN type. -- But then, seems that no-one else has had any problem with this.

Cheers,
Andreas

@mevdschee
Copy link
Owner

mevdschee commented May 30, 2024

Hi Andreas,

Thank you for your uplifting reply! I understand your reasoning.

But then, seems that no-one else has had any problem with this.

That is not true, if you search prior (closed) issues.

you could consider adding a hint to the README pointing out that the TINYINT column type is used as a stand-in for the non-existent BOOLEAN type.

Okay, but is that true? You may want to experiment with making the field 'tinyint(2)' instead, which may work around the problem (1 and 2 being the display size, not related to storage).

Kind regards,

Maurits

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

No branches or pull requests

2 participants