doctrine/dbal

sqlite id bigint

remco-pc opened this issue · 4 comments

Bug Report

Q A
Version 4.0.2

Summary

when doing a column lookup throught:

$tables = Table::all($object, $name, $environment);
        $sanitized_table = preg_replace('/[^a-zA-Z0-9_]/', '', $options->table);
        if (in_array($sanitized_table, $tables, true)) {
            $columns = $schema_manager->listTableColumns($sanitized_table);
            if($columns){
                $list = [];
                foreach($columns as $column){
                    $record = $column->toArray();
                    $record['type'] = File::basename(get_class($column->getType()));
                    $list[]= $record;
                }
                return $list;
            }
        }

i get an array of columns.
But the id column which is defined as a bigint is turning into an integer. if i disable autoincrement it is threated as an bigint.
So when a bigint column has an autoincrement=true it will become an integer in sqlite.

Current behaviour

The bigint becomes silently an integer without noticing the builder

Expected behaviour

the id column should become a bigint with autoincrement=true

Please try to reproduce your issue using only DBAL APIs.

When using doctrine schema manager i get an array of data describing the column definition of a sqlite db file. ($schema_manager->listTableColumns($sanitized_table))

When using a combination of bigint with auto increment it is of integer type. When i remove the auto increment, it becomes a bigint.

[
    {
        "name": "id",
        "type": "IntegerType",
        "default": null,
        "notnull": true,
        "length": null,
        "precision": null,
        "scale": 0,
        "fixed": false,
        "unsigned": false,
        "autoincrement": true,
        "columnDefinition": null,
        "comment": ""
    },
...

also i needed to do this:

$record = $column->toArray();
$record['type'] = File::basename(get_class($column->getType()));

the type doesnt have a to string defined which should and be the same as in the schema/ entitiy defined so we can validate the creation of the table

the unsigned is false where it should be true, because of the autoincrement.

{
        "name": "id",
        "type": "BigIntType",
        "default": null,
        "notnull": true,
        "length": null,
        "precision": null,
        "scale": 0,
        "fixed": false,
        "unsigned": true,
        "autoincrement": false,
        "columnDefinition": null,
        "comment": ""
    },

@derrabus its $schema_manager->listTableColumns($stable); should the type not be casted to string ?

Here #6411 is a PR with fix and test.