Repository navigation
Description
Describe the bug
Phalcon\Db\Adapter\Pdo\Sqlite::describeColumns() has no case for the blob types. A blob column goes to the default case and getType() gives Column::TYPE_VARCHAR.
The SQLite dialect writes these types (phalcon/Db/Dialect/Sqlite.zep:468, :539, :546, :567), so a column created with Column::TYPE_BLOB does not come back as Column::TYPE_BLOB. The MySQL and PostgreSQL adapters have a case for each blob type.
To Reproduce
use Phalcon\Db\Adapter\Pdo\Sqlite;
$adapter = new Sqlite(['dbname' => ':memory:']);
$adapter->execute(
'CREATE TABLE t (id INTEGER PRIMARY KEY, a BLOB, b TINYBLOB, c MEDIUMBLOB, d LONGBLOB, e blob)'
);
foreach ($adapter->describeColumns('t') as $column) {
echo $column->getName(), ' ', $column->getType(), PHP_EOL;
}Output (2 is Column::TYPE_VARCHAR):
id 0
a 2
b 2
c 2
d 2
e 2
Expected behavior
| Column | Declared type | Expected getType() |
|---|---|---|
a |
BLOB |
Column::TYPE_BLOB (11) |
b |
TINYBLOB |
Column::TYPE_TINYBLOB (10) |
c |
MEDIUMBLOB |
Column::TYPE_MEDIUMBLOB (12) |
d |
LONGBLOB |
Column::TYPE_LONGBLOB (13) |
e |
blob |
Column::TYPE_BLOB (11) |
Where to fix
Add four cases before the default case. blob must come last of the four, because the other three names contain it. None of the four names contains a name that the method checks earlier, so the new cases do not change the other types.
- cphalcon:
phalcon/Db/Adapter/Pdo/Sqlite.zep:240-245 - phalcon:
src/Db/Adapter/Pdo/Sqlite.php:284-288
The blob cases in the MySQL and PostgreSQL adapters set only the type. The new cases can do the same.
Tests and changelog
- Add a SQLite database test for the five columns above, in both repositories.
- Add a CHANGELOG line. Code that reads
getType()for a SQLite blob column gets a different value after the fix.
Details
- Run on:
phalcon/phalcon(v6). - cphalcon: the same code path, from the source. Not run.
- Found by:
phalcon/crest#56.make:scaffoldmust leave binary columns out of the form that it generates. On SQLite it cannot find them throughgetType(), so it generates a text field.
Other problems in the same code
- tinyint(1) branch: this branch cannot run, because the int check matches first. So a tinyint(1) column reports as TYPE_INTEGER, not boolean (Sqlite.zep:145 and :156, Sqlite.php:168 and :181).
- SQLite float bind type: the branch sets bindType to Column::TYPE_DECIMAL, while the decimal and real branches use Column::BIND_PARAM_DECIMAL (Sqlite.zep:203, Sqlite.php:238).
- PostgreSQL mediumblob: this type gives Column::TYPE_TEXT, while the other blob types give their own type (Postgresql.zep:346-347).
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsReleased
Activity
niden commentedon Nov 4, 2026
Resolved in #17726