示例#1
0
 /**
  * write
  *
  * @param string|int $id
  * @param string     $data
  *
  * @return  boolean
  */
 public function write($id, $data)
 {
     $data = array($this->options['data_col'] => $data, $this->options['time_col'] => (int) time(), $this->options['id_col'] => $id);
     $data = (object) $data;
     $this->db->updateObject($this->options['table'], $data, $this->options['id_col']);
     if ($this->db->getAffectedRows()) {
         return true;
     }
     $this->db->insertObject($this->options['table'], $data, $this->options['id_col']);
     return true;
 }
示例#2
0
 /**
  * Method to store a row in the database from the AbstractDatabaseTable instance properties.
  * If a primary key value is set the row with that primary key value will be
  * updated with the instance property values.  If no primary key value is set
  * a new row will be inserted into the database with the properties from the
  * AbstractDatabaseTable instance.
  *
  * @param boolean $updateNulls True to update fields even if they are null.
  *
  * @return  $this  Method allows chaining
  *
  * @since   1.0
  */
 public function store($updateNulls = false)
 {
     // If a primary key exists update the object, otherwise insert it.
     if ($this->hasPrimaryKey()) {
         $this->db->updateObject($this->tableName, $this->tableFields, $this->tableKeys, $updateNulls);
     } else {
         $this->db->insertObject($this->tableName, $this->tableFields, $this->tableKeys[0]);
     }
     return $this;
 }
示例#3
0
 /**
  * Do update action.
  *
  * @param mixed $dataset    Data set contain data we want to update.
  * @param array $condFields The where condition tell us record exists or not, if not set,
  *                          will use primary key instead.
  *
  * @throws \Exception
  * @return  mixed Updated data set.
  */
 protected function doUpdate($dataset, array $condFields)
 {
     $this->db->transactionStart(true);
     try {
         foreach ($dataset as &$data) {
             $entity = new Entity($this->getFields($this->table), $data);
             $this->db->updateObject($this->table, $entity, $condFields);
         }
     } catch (\Exception $e) {
         $this->db->transactionRollback(true);
         throw $e;
     }
     $this->db->transactionCommit(true);
     return $dataset;
 }