db-pgsql icon indicating copy to clipboard operation
db-pgsql copied to clipboard

Wrong return type in BitColumnSchema::phpTypecast

Open Gerych1984 opened this issue 1 year ago • 5 comments

Q A
Version current develop
PHP version 8.3
Operating system

Good afternoon. In BitColumnSchema::phpTypecast there is an error in the returned type. As you can see from the documentation, the bindec function can return int|float, while phpTypecast int|null. In my case, it is a field of type bit varying with the following content for exaple 1100000100011100100110001011000010100000001011001101111011100000 (p-hash images to find duplicates). And on the output I need a string in the same form. Maybe for this type it is not necessary to convert the type to a decimal number. Thanks

Gerych1984 avatar Nov 04 '24 15:11 Gerych1984

Need to add another column class for big bit types BigBitColumnSchema, where the typecasting will be to a string number using base_convert($value, 2, 10) or returning the string as is.

Tigrov avatar Nov 05 '24 02:11 Tigrov

Need to add another column class for big bit types BigBitColumnSchema, where the typecasting will be to a string number using base_convert($value, 2, 10) or returning the string as is.

It's no problem with float - just add right return type int|float|null https://onlinephp.io/c/89d1d example

Gerych1984 avatar Nov 05 '24 07:11 Gerych1984

If simply add float, the result may be incorrect since precision is lost.

Tigrov avatar Nov 07 '24 02:11 Tigrov

Need to add another column class for big bit types BigBitColumnSchema, where the typecasting will be to a string number using base_convert($value, 2, 10) or returning the string as is.

Should bigbit be added in yiisoft/db as new abstract column type?

vjik avatar Nov 14 '24 18:11 vjik

Should bigbit be added in yiisoft/db as new abstract column type?

I don't think it's necessary. There is no problem if we know only bit abstract type and its size.

Tigrov avatar Nov 15 '24 15:11 Tigrov

Fixed

Tigrov avatar Nov 06 '25 13:11 Tigrov