php-crud-api icon indicating copy to clipboard operation
php-crud-api copied to clipboard

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

Open FD-ado opened this issue 1 year ago • 3 comments

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

FD-ado avatar May 29 '24 09:05 FD-ado

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 avatar May 29 '24 10:05 mevdschee

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

FD-ado avatar May 29 '24 11:05 FD-ado

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

mevdschee avatar May 30 '24 17:05 mevdschee