Explorar el Código

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 hace 12 años
padre
commit
2274fdbcf8
Se han modificado 1 ficheros con 20 adiciones y 20 borrados
  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;
         $primary = (array) $this->_primary;
         $pkIdentity = $primary[(int)$this->_identity];
         $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
          * 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:
          * position of the data.  The following values are considered empty:
          *   null, false, true, '', array()
          *   null, false, true, '', array()
          */
          */
-        if (!isset($pkSuppliedBySequence) && array_key_exists($pkIdentity, $data)) {
+        if (array_key_exists($pkIdentity, $data)) {
             if ($data[$pkIdentity] === null                                        // null
             if ($data[$pkIdentity] === null                                        // null
                 || $data[$pkIdentity] === ''                                       // empty string
                 || $data[$pkIdentity] === ''                                       // empty string
                 || is_bool($data[$pkIdentity])                                     // boolean
                 || 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.
          * INSERT the new row.
          */
          */
         $tableSpec = ($this->_schema ? $this->_schema . '.' : '') . $this->_name;
         $tableSpec = ($this->_schema ? $this->_schema . '.' : '') . $this->_name;
@@ -1212,20 +1212,20 @@ abstract class Zend_Db_Table_Abstract
     {
     {
         // setup metadata
         // setup metadata
         $this->_setupMetadata();
         $this->_setupMetadata();
-        
+
         // get this class name
         // get this class name
         $thisClass = get_class($this);
         $thisClass = get_class($this);
         if ($thisClass === 'Zend_Db_Table') {
         if ($thisClass === 'Zend_Db_Table') {
             $thisClass = $this->_definitionConfigName;
             $thisClass = $this->_definitionConfigName;
         }
         }
-        
+
         $rowsAffected = 0;
         $rowsAffected = 0;
-        
+
         foreach ($this->_getReferenceMapNormalized() as $map) {
         foreach ($this->_getReferenceMapNormalized() as $map) {
             if ($map[self::REF_TABLE_CLASS] == $parentTableClassname && isset($map[self::ON_DELETE])) {
             if ($map[self::REF_TABLE_CLASS] == $parentTableClassname && isset($map[self::ON_DELETE])) {
-                
+
                 $where = array();
                 $where = array();
-                
+
                 // CASCADE or CASCADE_RECURSE
                 // CASCADE or CASCADE_RECURSE
                 if (in_array($map[self::ON_DELETE], array(self::CASCADE, self::CASCADE_RECURSE))) {
                 if (in_array($map[self::ON_DELETE], array(self::CASCADE, self::CASCADE_RECURSE))) {
                     for ($i = 0; $i < count($map[self::COLUMNS]); ++$i) {
                     for ($i = 0; $i < count($map[self::COLUMNS]); ++$i) {
@@ -1237,10 +1237,10 @@ abstract class Zend_Db_Table_Abstract
                             $primaryKey[$refCol], $type);
                             $primaryKey[$refCol], $type);
                     }
                     }
                 }
                 }
-                
+
                 // CASCADE_RECURSE
                 // CASCADE_RECURSE
                 if ($map[self::ON_DELETE] == self::CASCADE_RECURSE) {
                 if ($map[self::ON_DELETE] == self::CASCADE_RECURSE) {
-                    
+
                     /**
                     /**
                      * Execute cascading deletes against dependent tables
                      * 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))) {
                 if (in_array($map[self::ON_DELETE], array(self::CASCADE, self::CASCADE_RECURSE))) {
                     $rowsAffected += $this->delete($where);
                     $rowsAffected += $this->delete($where);
                 }
                 }
-                
+
             }
             }
         }
         }
         return $rowsAffected;
         return $rowsAffected;
@@ -1610,5 +1610,5 @@ abstract class Zend_Db_Table_Abstract
 
 
         return new $tableName($options);
         return new $tableName($options);
     }
     }
-    
+
 }
 }