ZF-2640: Warnings generated when MSSQL table has no primary keys in Zend_Db_Adapter_Pdo_Mssql::describeTable
Description
For tables that have no primary keys (don't blame me, I didn't write the horrifying SQL schema ;)), warnings will be thrown because array_key_exists is invoked against an undefined variable.
At/around line 225 in Zend/Db/Adapter/Pdo/Mssql.php is the offending bit of code:
$isPrimary = array_key_exists($row[$column_name], $primaryKeyColumn);
$primaryKeyColumn is never initialised, so somewhere around line 209 this change should be made:
$primaryKeysResult = $stmt->fetchAll(Zend_Db::FETCH_NUM);
$pkey_column_name = 3;
$pkey_key_seq = 4;
+
+ $primaryKeyColumn = array();
foreach ($primaryKeysResult as $pkeysRow) {
$primaryKeyColumn[$pkeysRow[$pkey_column_name]] = $pkeysRow[$pkey_key_seq];
}
Initially I thought it should be enough to just cast to an array, but that still threw a Notice. This actually addresses the issue.
Cheers,
Comments
Posted by C Snover (snover) on 2008-02-13T22:32:43.000+0000
Initially I thought that it should be enough just to cast to an array, but PHP still threw a Notice about the variable being undefined. So, let's actually define the variable. :)
Posted by Thomas Weidner (thomas) on 2008-02-16T13:09:55.000+0000
Fixed with revision 7671