/** * Saves the record in memory * */ public function save() { if (!$this->bound) { if ($this->keyAssignedBy == self::keyAssignedBy_db) { // if($this->useUuidPrimaryKey) // { // $uuid = self::_getConnection(get_class($this))->getUUID(); // $this->setScalar($this->primaryKey[0], $uuid); // self::_getConnection(get_class($this))->insertArray($this->tableName, $this->scalars, $serial = false); // } // else // { $this->setScalar($this->primaryKey[0], self::_getConnection(get_class($this))->insertArray($this->tableName, $this->scalars)); // } } else { if ($this->keyAssignedBy == self::keyAssignedBy_dev) { if (method_exists($this, 'getPrimaryKeyValuesForNewObject')) { $uuid = self::_getConnection(get_class($this))->getUUID(); $primaryKeyValues = $this->getPrimaryKeyValuesForNewObject(); if (count($this->primaryKey) == 1 && !is_array($primaryKeyValues)) { $this->setScalar($this->primaryKey[0], $uuid); } else { assert(is_array($primaryKeyValues) && count($primaryKeyValues) == count($this->primaryKey)); foreach ($primaryKeyValues as $key => $value) { $this->setScalar($key, $value); } } self::_getConnection(get_class($this))->insertArray($this->tableName, $this->scalars, $serial = false); } else { trigger_error("you must define all primary key fields in order by save this object"); } } else { trigger_error("you must define all primary key fields in order by save this object"); } } } else { if ($this->keyAssignedBy == self::keyAssignedBy_db) { $updateInfo = DbConnection::generateUpdateInfo($this->tableName, $this->getKeyConditions(), $this->getScalarsWithModifiers()); self::_getConnection(get_class($this))->updateRow($updateInfo['sql'], $updateInfo['params']); } else { if (!$this->persisted()) { self::_getConnection(get_class($this))->insertArray($this->tableName, $this->getScalarsWithModifiers(), false); } else { $updateInfo = DbConnection::generateUpdateInfo($this->tableName, $this->getKeyConditions(), $this->getScalarsWithModifiers()); self::_getConnection(get_class($this))->updateRow($updateInfo['sql'], $updateInfo['params']); } } } }
public function updateArray($tableName, $conditions, $values) { $updateInfo = DbConnection::generateUpdateInfo($tableName, $conditions, $values); return $this->updateRow($updateInfo['sql'], $updateInfo['params']); }
/** * Saves the record in memory * */ public function save() { if (!$this->bound) { if ($this->keyAssignedBy == self::keyAssignedBy_db) { $this->setScalar($this->primaryKey[0], self::_getConnection(get_class($this))->insertArray($this->tableName, $this->scalars)); } else { trigger_error("you must define all foreign key fields in order by save this object"); } } else { if ($this->keyAssignedBy == self::keyAssignedBy_db) { $updateInfo = DbConnection::generateUpdateInfo($this->tableName, $this->getKeyConditions(), $this->scalars); self::_getConnection(get_class($this))->updateRow($updateInfo['sql'], $updateInfo['params']); } else { if (!$this->persisted()) { self::_getConnection(get_class($this))->insertArray($this->tableName, $this->scalars, false); } else { $updateInfo = DbConnection::generateUpdateInfo($this->tableName, $this->getKeyConditions(), $this->scalars); self::_getConnection(get_class($this))->updateRow($updateInfo['sql'], $updateInfo['params']); } } } }