-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Phalcon 4 issue with TINYINT(1) #14708
Comments
Can you give us a dump of your database structure and some basic code to reproduce this? |
DB table
Code used:
After the save, both the |
Thnx for the info. https://github.com/phalcon/cphalcon/blob/master/phalcon/Db/Adapter/Pdo/Mysql.zep#L141 Looks like we made the assumption tinyint(1) is a boolean. Something I assumed as wel since MySql will save a boolean column as tinyint(1). Just looked up the specs but tinyint is handled as a normal tinyint (-128 through 127) but will only display 1 digit. |
You are correct. It's being treated as a boolean value but it shouldn't be. As you've pointed out, it can go all the way up to 127 when signed and 255 when unsigned. It's worth noting that the Key point from the the MySQL docs: Therefore, this is a bug. This has been brought up before on Phalcon too. See #2012 |
If anyone else is experiencing this issue, remove the mask from the integer data type to solve it your end before a fix is in place. i.e. Remove |
Resolved in #14709 Thank you @daniel18387 |
On the other hand, those who used TINYINT(1) as a BOOLEAN (because declaring a column as BOOL in MySQL Workbench outputs a TINYINT(1)) may have welcomed the v4.0.0 behavior. Wouldn't a setting to specify the wished behavior be a better option in the long run? |
That doesn't make sense. Phalcon should work with MySQL, not necessarily MySQL Workbench (Third party product). i.e. Follow MySQLs documentation. MySQL Workbench (Which I use) should adhere to the standards, as should Phalcon. Any other suggestion is pure conjecture. |
MySQL Workbench is made by Oracle, so it's a first-party product (relative to MySQL Server). The documentation for the numeric types says indeed:
But it also says just above:
If you agree that "let the application do what it wants with it" is a standard, as it's what's written in the MySQL docs, then it's precisely what I'm suggesting in order to avoid said conjectures. In the same documentation they mention the mapping they're doing from BOOLEAN to TINYINT, which is what their other own product Workbench does (to TINYINT(1)) and how the DB works: if you INSERT a TRUE (without '') into a TINYINT column it's understood (...and stored) as a 1. If I can make my position more clear, the same way we have a: |
Thank you for clarifying. While the above sounds like a good idea to cover all bases, it's also redundant with this now in place. I use both boolean and integer values with TINYINT, which as mentioned above MySQL advocates. However, it begs the question why Phalcon should be more restrictive when it already allows the functionality for both. In my personal opinion, I would prefer Phalcon's product to be more flexible. |
I have noticed an issue when saving records to tables in MySQL. Of the tables which have field columns with the data type TINYINT(1), I can see the values in the rows default to 1 when a row gets saved, regardless of the value given.
This only occurs when the mask is set to 1.
The text was updated successfully, but these errors were encountered: