Преглед на файлове

Do empty-PK detection before we try to obtain nextSequenceId, so it works properly also for the values considered empty

(cherry picked from commit 0d79c0e6cf912a63502285073e8cf041a0597282)
Ondřej Machulda преди 12 години
родител
ревизия
2274fdbcf8
променени са 1 файла, в които са добавени 20 реда и са изтрити 20 реда
  1. 20 20
      library/Zend/Db/Table/Abstract.php

+ 20 - 20
library/Zend/Db/Table/Abstract.php

@@ -1041,16 +1041,6 @@ abstract class Zend_Db_Table_Abstract
         $primary = (array) $this->_primary;
         $pkIdentity = $primary[(int)$this->_identity];
 
-        /**
-         * If this table uses a database sequence object and the data does not
-         * specify a value, then get the next ID from the sequence and add it
-         * to the row.  We assume that only the first column in a compound
-         * primary key takes a value from a sequence.
-         */
-        if (is_string($this->_sequence) && !isset($data[$pkIdentity])) {
-            $data[$pkIdentity] = $this->_db->nextSequenceId($this->_sequence);
-            $pkSuppliedBySequence = true;
-        }
 
         /**
          * If the primary key can be generated automatically, and no value was
@@ -1060,7 +1050,7 @@ abstract class Zend_Db_Table_Abstract
          * position of the data.  The following values are considered empty:
          *   null, false, true, '', array()
          */
-        if (!isset($pkSuppliedBySequence) && array_key_exists($pkIdentity, $data)) {
+        if (array_key_exists($pkIdentity, $data)) {
             if ($data[$pkIdentity] === null                                        // null
                 || $data[$pkIdentity] === ''                                       // empty string
                 || is_bool($data[$pkIdentity])                                     // boolean
@@ -1070,6 +1060,16 @@ abstract class Zend_Db_Table_Abstract
         }
 
         /**
+         * If this table uses a database sequence object and the data does not
+         * specify a value, then get the next ID from the sequence and add it
+         * to the row.  We assume that only the first column in a compound
+         * primary key takes a value from a sequence.
+         */
+        if (is_string($this->_sequence) && !isset($data[$pkIdentity])) {
+            $data[$pkIdentity] = $this->_db->nextSequenceId($this->_sequence);
+        }
+
+        /**
          * INSERT the new row.
          */
         $tableSpec = ($this->_schema ? $this->_schema . '.' : '') . $this->_name;
@@ -1212,20 +1212,20 @@ abstract class Zend_Db_Table_Abstract
     {
         // setup metadata
         $this->_setupMetadata();
-        
+
         // get this class name
         $thisClass = get_class($this);
         if ($thisClass === 'Zend_Db_Table') {
             $thisClass = $this->_definitionConfigName;
         }
-        
+
         $rowsAffected = 0;
-        
+
         foreach ($this->_getReferenceMapNormalized() as $map) {
             if ($map[self::REF_TABLE_CLASS] == $parentTableClassname && isset($map[self::ON_DELETE])) {
-                
+
                 $where = array();
-                
+
                 // CASCADE or CASCADE_RECURSE
                 if (in_array($map[self::ON_DELETE], array(self::CASCADE, self::CASCADE_RECURSE))) {
                     for ($i = 0; $i < count($map[self::COLUMNS]); ++$i) {
@@ -1237,10 +1237,10 @@ abstract class Zend_Db_Table_Abstract
                             $primaryKey[$refCol], $type);
                     }
                 }
-                
+
                 // CASCADE_RECURSE
                 if ($map[self::ON_DELETE] == self::CASCADE_RECURSE) {
-                    
+
                     /**
                      * Execute cascading deletes against dependent tables
                      */
@@ -1259,7 +1259,7 @@ abstract class Zend_Db_Table_Abstract
                 if (in_array($map[self::ON_DELETE], array(self::CASCADE, self::CASCADE_RECURSE))) {
                     $rowsAffected += $this->delete($where);
                 }
-                
+
             }
         }
         return $rowsAffected;
@@ -1610,5 +1610,5 @@ abstract class Zend_Db_Table_Abstract
 
         return new $tableName($options);
     }
-    
+
 }