[BUG]: Column::TYPE_BINARY and Column::TYPE_TINYINTEGER are both 26
Describe the bug Phalcon\Db\Column::TYPE_BINARY and Phalcon\Db\Column::TYPE_TINYINTEGER should not be equal
To Reproduce
Column::TYPE_BINARY === Column::TYPE_TINYINTEGER // true
Expected behavior
Column::TYPE_BINARY === Column::TYPE_TINYINTEGER // false
Additional context Column::TYPE_BINARY is not numeric Column::TYPE_TINYINTEGER is numeric Missing unit test for TYPE_BINARY
The biggest issue is when we are using casting (i.e. castOnHydrate) it will convert my binary into a int because it found the wrong type. Since I don't want to turn off casting on hydrate, and want to fix the bind type, tis is my temporary solution for now. I made my own Mysql adapter to get around the issue affected by the wrong Column type value.
use Phalcon\Db\Column;
class Mysql extends \Phalcon\Db\Adapter\Pdo\Mysql
{
public function describeColumns(string $table, string $schema = null): array
{
$definitions = parent::describeColumns($table, $schema);
if (Column::TYPE_TINYINTEGER !== Column::TYPE_BINARY) {
return $definitions;
}
foreach ($definitions as $key => $definition) {
if ($definition->getType() === Column::TYPE_TINYINTEGER && !$definition->isNumeric()) {
// probably a binary at this point
$newDefinition = [];
// protected to public
$prefix = chr(0).'*'.chr(0);
foreach ((array)$definition as $k => $value) {
$newDefinition[str_replace($prefix, '', $k)] = $value;
}
$newDefinition['bindType'] = Column::BIND_PARAM_BLOB;
$newDefinition['type'] = Column::TYPE_VARBINARY;
unset($newDefinition['scale']);
// reset definition
$definitions[$key] = new Column($definition->getName(), $newDefinition);
}
}
return $definitions;
}
}
This has been fixed in https://github.com/phalcon/cphalcon/pull/16564
Thank you @jturbide