ZF-2640: Warnings generated when MSSQL table has no primary keys in Zend_Db_Adapter_Pdo_Mssql::describeTable

Issue Type: Bug Created: 2008-02-13T03:36:00.000+0000 Last Updated: 2008-03-21T16:25:26.000+0000 Status: Resolved Fix version(s): - 1.5.0 (17/Mar/08)

Reporter: C Snover (snover) Assignee: Thomas Weidner (thomas) Tags: - Zend_Db

Related issues: Attachments:


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:

<pre class="highlight">
$isPrimary = array_key_exists($row[$column_name], $primaryKeyColumn);

$primaryKeyColumn is never initialised, so somewhere around line 209 this change should be made:

<pre class="highlight">
$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.



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

Have you found an issue?

See the Overview section for more details.


© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.