Skip to content
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

[BUG]: Column::TYPE_BINARY and Column::TYPE_TINYINTEGER are both 26 #16532

Closed
jturbide opened this issue Feb 18, 2024 · 2 comments
Closed

[BUG]: Column::TYPE_BINARY and Column::TYPE_TINYINTEGER are both 26 #16532

jturbide opened this issue Feb 18, 2024 · 2 comments
Assignees
Labels
5.0 The issues we want to solve in the 5.0 release bug A bug report status: medium Medium

Comments

@jturbide
Copy link
Sponsor Contributor

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

@jturbide jturbide added bug A bug report status: unverified Unverified labels Feb 18, 2024
@jturbide
Copy link
Sponsor Contributor Author

jturbide commented Feb 18, 2024

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;
    }
}

jturbide added a commit to zemit-cms/core that referenced this issue Feb 20, 2024
@niden niden mentioned this issue Apr 5, 2024
5 tasks
@niden niden self-assigned this Apr 5, 2024
@niden niden added status: medium Medium 5.0 The issues we want to solve in the 5.0 release and removed status: unverified Unverified labels Apr 5, 2024
@niden
Copy link
Sponsor Member

niden commented Apr 5, 2024

This has been fixed in #16564

Thank you @jturbide

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
5.0 The issues we want to solve in the 5.0 release bug A bug report status: medium Medium
Projects
Status: Implemented
Development

No branches or pull requests

2 participants