1039 * it's the _first_ column in the compound key. |
1039 * it's the _first_ column in the compound key. |
1040 */ |
1040 */ |
1041 $primary = (array) $this->_primary; |
1041 $primary = (array) $this->_primary; |
1042 $pkIdentity = $primary[(int)$this->_identity]; |
1042 $pkIdentity = $primary[(int)$this->_identity]; |
1043 |
1043 |
|
1044 |
|
1045 /** |
|
1046 * If the primary key can be generated automatically, and no value was |
|
1047 * specified in the user-supplied data, then omit it from the tuple. |
|
1048 * |
|
1049 * Note: this checks for sensible values in the supplied primary key |
|
1050 * position of the data. The following values are considered empty: |
|
1051 * null, false, true, '', array() |
|
1052 */ |
|
1053 if (array_key_exists($pkIdentity, $data)) { |
|
1054 if ($data[$pkIdentity] === null // null |
|
1055 || $data[$pkIdentity] === '' // empty string |
|
1056 || is_bool($data[$pkIdentity]) // boolean |
|
1057 || (is_array($data[$pkIdentity]) && empty($data[$pkIdentity]))) { // empty array |
|
1058 unset($data[$pkIdentity]); |
|
1059 } |
|
1060 } |
|
1061 |
1044 /** |
1062 /** |
1045 * If this table uses a database sequence object and the data does not |
1063 * If this table uses a database sequence object and the data does not |
1046 * specify a value, then get the next ID from the sequence and add it |
1064 * specify a value, then get the next ID from the sequence and add it |
1047 * to the row. We assume that only the first column in a compound |
1065 * to the row. We assume that only the first column in a compound |
1048 * primary key takes a value from a sequence. |
1066 * primary key takes a value from a sequence. |
1049 */ |
1067 */ |
1050 if (is_string($this->_sequence) && !isset($data[$pkIdentity])) { |
1068 if (is_string($this->_sequence) && !isset($data[$pkIdentity])) { |
1051 $data[$pkIdentity] = $this->_db->nextSequenceId($this->_sequence); |
1069 $data[$pkIdentity] = $this->_db->nextSequenceId($this->_sequence); |
1052 $pkSuppliedBySequence = true; |
|
1053 } |
|
1054 |
|
1055 /** |
|
1056 * If the primary key can be generated automatically, and no value was |
|
1057 * specified in the user-supplied data, then omit it from the tuple. |
|
1058 * |
|
1059 * Note: this checks for sensible values in the supplied primary key |
|
1060 * position of the data. The following values are considered empty: |
|
1061 * null, false, true, '', array() |
|
1062 */ |
|
1063 if (!isset($pkSuppliedBySequence) && array_key_exists($pkIdentity, $data)) { |
|
1064 if ($data[$pkIdentity] === null // null |
|
1065 || $data[$pkIdentity] === '' // empty string |
|
1066 || is_bool($data[$pkIdentity]) // boolean |
|
1067 || (is_array($data[$pkIdentity]) && empty($data[$pkIdentity]))) { // empty array |
|
1068 unset($data[$pkIdentity]); |
|
1069 } |
|
1070 } |
1070 } |
1071 |
1071 |
1072 /** |
1072 /** |
1073 * INSERT the new row. |
1073 * INSERT the new row. |
1074 */ |
1074 */ |
1210 */ |
1212 */ |
1211 public function _cascadeDelete($parentTableClassname, array $primaryKey) |
1213 public function _cascadeDelete($parentTableClassname, array $primaryKey) |
1212 { |
1214 { |
1213 // setup metadata |
1215 // setup metadata |
1214 $this->_setupMetadata(); |
1216 $this->_setupMetadata(); |
1215 |
1217 |
1216 // get this class name |
1218 // get this class name |
1217 $thisClass = get_class($this); |
1219 $thisClass = get_class($this); |
1218 if ($thisClass === 'Zend_Db_Table') { |
1220 if ($thisClass === 'Zend_Db_Table') { |
1219 $thisClass = $this->_definitionConfigName; |
1221 $thisClass = $this->_definitionConfigName; |
1220 } |
1222 } |
1221 |
1223 |
1222 $rowsAffected = 0; |
1224 $rowsAffected = 0; |
1223 |
1225 |
1224 foreach ($this->_getReferenceMapNormalized() as $map) { |
1226 foreach ($this->_getReferenceMapNormalized() as $map) { |
1225 if ($map[self::REF_TABLE_CLASS] == $parentTableClassname && isset($map[self::ON_DELETE])) { |
1227 if ($map[self::REF_TABLE_CLASS] == $parentTableClassname && isset($map[self::ON_DELETE])) { |
1226 |
1228 |
1227 $where = array(); |
1229 $where = array(); |
1228 |
1230 |
1229 // CASCADE or CASCADE_RECURSE |
1231 // CASCADE or CASCADE_RECURSE |
1230 if (in_array($map[self::ON_DELETE], array(self::CASCADE, self::CASCADE_RECURSE))) { |
1232 if (in_array($map[self::ON_DELETE], array(self::CASCADE, self::CASCADE_RECURSE))) { |
1231 for ($i = 0; $i < count($map[self::COLUMNS]); ++$i) { |
1233 for ($i = 0; $i < count($map[self::COLUMNS]); ++$i) { |
1232 $col = $this->_db->foldCase($map[self::COLUMNS][$i]); |
1234 $col = $this->_db->foldCase($map[self::COLUMNS][$i]); |
1233 $refCol = $this->_db->foldCase($map[self::REF_COLUMNS][$i]); |
1235 $refCol = $this->_db->foldCase($map[self::REF_COLUMNS][$i]); |
1235 $where[] = $this->_db->quoteInto( |
1237 $where[] = $this->_db->quoteInto( |
1236 $this->_db->quoteIdentifier($col, true) . ' = ?', |
1238 $this->_db->quoteIdentifier($col, true) . ' = ?', |
1237 $primaryKey[$refCol], $type); |
1239 $primaryKey[$refCol], $type); |
1238 } |
1240 } |
1239 } |
1241 } |
1240 |
1242 |
1241 // CASCADE_RECURSE |
1243 // CASCADE_RECURSE |
1242 if ($map[self::ON_DELETE] == self::CASCADE_RECURSE) { |
1244 if ($map[self::ON_DELETE] == self::CASCADE_RECURSE) { |
1243 |
1245 |
1244 /** |
1246 /** |
1245 * Execute cascading deletes against dependent tables |
1247 * Execute cascading deletes against dependent tables |
1246 */ |
1248 */ |
1247 $depTables = $this->getDependentTables(); |
1249 $depTables = $this->getDependentTables(); |
1248 if (!empty($depTables)) { |
1250 if (!empty($depTables)) { |
1575 $stmt = $this->_db->query($select); |
1577 $stmt = $this->_db->query($select); |
1576 $data = $stmt->fetchAll(Zend_Db::FETCH_ASSOC); |
1578 $data = $stmt->fetchAll(Zend_Db::FETCH_ASSOC); |
1577 return $data; |
1579 return $data; |
1578 } |
1580 } |
1579 |
1581 |
|
1582 /** |
|
1583 * Get table gateway object from string |
|
1584 * |
|
1585 * @param string $tableName |
|
1586 * @param Zend_Db_Table_Abstract $referenceTable |
|
1587 * @throws Zend_Db_Table_Row_Exception |
|
1588 * @return Zend_Db_Table_Abstract |
|
1589 */ |
1580 public static function getTableFromString($tableName, Zend_Db_Table_Abstract $referenceTable = null) |
1590 public static function getTableFromString($tableName, Zend_Db_Table_Abstract $referenceTable = null) |
1581 { |
1591 { |
1582 if ($referenceTable instanceof Zend_Db_Table_Abstract) { |
1592 if ($referenceTable instanceof Zend_Db_Table_Abstract) { |
1583 $tableDefinition = $referenceTable->getDefinition(); |
1593 $tableDefinition = $referenceTable->getDefinition(); |
1584 |
1594 |