Skip to content

Commit

Permalink
temporary workaround phalcon models meta data mysql binary issue
Browse files Browse the repository at this point in the history
  • Loading branch information
jturbide committed Feb 20, 2024
1 parent e02a1b8 commit 4a7187e
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/Db/Adapter/Pdo/Mysql.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

/**
* This file is part of the Zemit Framework.
*
* (c) Zemit Team <contact@zemit.com>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/

namespace Zemit\Db\Adapter\Pdo;

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 $definitionKey => $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 $key => $value) {
$newDefinition[str_replace($prefix, '', $key)] = $value;
}

$newDefinition['bindType'] = Column::BIND_PARAM_BLOB;
$newDefinition['type'] = Column::TYPE_VARBINARY;
unset($newDefinition['scale']);

// reset definition
$definitions[$definitionKey] = new Column($definition->getName(), $newDefinition);
}
}

return $definitions;
}
}

0 comments on commit 4a7187e

Please sign in to comment.