diff --git a/src/Db/Adapter/Pdo/Mysql.php b/src/Db/Adapter/Pdo/Mysql.php new file mode 100644 index 00000000..86db7cbe --- /dev/null +++ b/src/Db/Adapter/Pdo/Mysql.php @@ -0,0 +1,50 @@ + + * + * 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; + } +}