Example #1
0
 /**
  * Delete
  *
  * @return int
  */
 public function delete()
 {
     $this->initialize();
     if (!$this->rowExistsInDatabase()) {
         throw new Exception\RuntimeException('Cannot refresh the data not exists in database.');
     }
     $where = $this->processPrimaryKeyWhere();
     $statement = $this->sql->prepareStatement($this->sql->delete()->where($where));
     $result = $statement->execute();
     $rowsAffected = $result->getAffectedRows();
     if ($rowsAffected == 1) {
         // detach from database
         $this->primaryKeyData = null;
         $this->data = array();
         $this->cleanData = array();
     }
     return $rowsAffected;
 }
Example #2
0
 /**
  * get one row
  *
  * @param Where|\Closure|string|array $where
  * @param bool $returnArray
  * @throws Exception\InvalidArgumentException
  * @return null|array|AbstractRow
  */
 public function get($where = null, $returnArray = false)
 {
     $this->initialize();
     $select = $this->sql->select();
     if ($where instanceof \Closure) {
         $where($select);
     } elseif ($where !== null) {
         $select->where($where);
     }
     // prepare and execute
     $statement = $this->sql->prepareStatement($select);
     $result = $statement->execute();
     $rowData = $result->current();
     if (false === $rowData) {
         return null;
     }
     if ($returnArray) {
         return $rowData;
     }
     $row = clone $this->rowPrototype;
     $row->exchangeArray($rowData);
     return $row;
 }