3
votes

I'm trying to reverse generate a schema from a MSSQL database using Propel 2. I've set up my YAML configuration file as usual:

dbname:
    adapter: mssql
    classname: Propel\Runtime\Connection\ConnectionWrapper
    dsn: "dblib:host=123.456.789.012;dbname=dbname"
    user: username
    password: password
    attributes:

When I run the command propel reverse 'dbname' I receive the error:

[Propel\Generator\Exception\EngineException]
Column "" declared twice in table "Status"

Which is obviously thrown here: https://github.com/propelorm/Propel2/blob/master/src/Propel/Generator/Model/Table.php#L499 @r499

Why does Propel attempt to add 'empty' columns? My SQL server management studio does not display empty columns at all when I look at the design of the DB table Status, it only displays the two columns it contains (uid and name).

Edit: So I went digging into the code of Propel, and it seems to go wrong here: https://github.com/propelorm/Propel2/blob/62859fd0ed3520b7d7afbbdeac113edaf160982b/src/Propel/Generator/Reverse/MssqlSchemaParser.php#L124

 protected function addColumns(Table $table)
    {
        $dataFetcher = $this->dbh->query("sp_columns '" . $table->getName() . "'");
        foreach ($dataFetcher as $row) {
            $name = $this->cleanDelimitedIdentifiers($row['COLUMN_NAME']);

$table->getName() correctly returns the right table name. When I print dataFetcher it's a PDO object. However: $row gives the following array:

Array(
    [0] => My DBname
    [1] => My DBprefix
    [2] => Status
    [3] => uid
    [4] => 4
    [5] => int identity
    etc. no string indices hence COLUMN_NAME is empty.
1
For the sake of purely backend guys like me,could you share the original table structure please? Which table is throwing error, and the columns?SouravA
I don't have access right now,but on top of my head the table contains 2 columns; uid of type int and name of type varchar. I suspect it might be due to the name of the table (Status) which might lead to an unexpected result when querying the DB for the tables and their columns. I'll try this out tomorrow and report back here.pbond
Renaming Status to any other name did not work, so I dropped the table and recreated it (this 'worked', but most likely since its now at the tail of the list of tables to work through), however now the same problem occurs for another table. Unfortunately I don't see any empty column names in my SQL server management studio.pbond
A quick google search yields this: stackoverflow.com/q/16212374/2993606 Can you see if this is of any help?SouravA
I think I did. It appears their dataFetcher always use FETCH_NUM hence this piece of code simply can't work, but I might be wrong. Anyways, I opened an issue on their git: github.com/propelorm/Propel2/issues/863pbond

1 Answers

1
votes

(Posted on behalf of the OP):

This is a bug in the Propel MSSQL schema parser: https://github.com/propelorm/Propel2/issues/863.