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.
uid
of type int andname
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. – pbondStatus
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. – pbondFETCH_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/863 – pbond