Zend Framework

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

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: None
  • Fix Version/s: 1.5.0
  • Component/s: Zend_Db
  • Labels:
    None

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,

Activity

Hide
C Snover added a comment -

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.

Show
C Snover added a comment - 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.
Hide
Thomas Weidner added a comment -

Fixed with revision 7671

Show
Thomas Weidner added a comment - Fixed with revision 7671

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: