Open alotacents opened 6 years ago
seems related or in scope of #15455 but on MSSQL.
That one seem related to MSSQL loadColumnSchema is getting the SQL raw default value. Which in the issue states it has parentheses around it. Maybe for MSSQL loadColumnSchema needs to detect bit and do bindec(trim($info['default'], '()'));
to the default value like in MySQL it does bindec(trim($info['default'], 'b\''));
This issue is more related that the yii/db/Schema typecasting it's not even trying to convert the raw database bit binary string to a integer string.
What steps will reproduce the problem?
In 64bit PHP create a Bit(34) column set a value for example to 75 when you query the result via ActiveRecord result is 0;
What is the expected result?
Expect result is either a binary string value \0\0\0\0K like from PDO sql query, or after typecasting a integer value 75.
What do you get instead?
integer value 0.
Seems that the yii/mysql/schema set bit to integer if the size is equal 32 or less and bigint greater than 32. Then when the getColumnPhpType determines string or integer based on PHP_INT_SIZE it is looking at unsigned values which bit don't have.
How I fixed the issue was in the \yii\db\ColumnSchema file where it does typecasting I modified the two functions phpType and dbType
also took the first 2 if statements in typecast function
and modified \yii\db\Schema getColumnPhpType for handling bit
Also saw some code on setting bit(1) to boolean I would like to recommend determining boolean if the column comment contains the word boolean. I know that is a extra step to make sure someone writes boolean in the column comment but I rather make the choice on what I want to be returned in a active record then for the code to always change a column of certain setup. Also having a comment saying boolean helps someone determine hey this field is being used for a boolean value. So say it was used on tinyint(1) I can know only values expect are NULL, 0, and 1.
Additional info