Ejemplo n.º 1
0
 public function testBasicDelete()
 {
     $query = new DeleteQuery();
     $query->delete('users', 'u')->partitions('p1', 'p2')->where()->equal('id', 3)->is('confirmed', true);
     $query->limit(1);
     $this->assertSqlStrings($query, [[new MySQLDriver(), 'DELETE FROM users AS u PARTITION (p1,p2) WHERE id = 3 AND confirmed IS TRUE LIMIT 1'], [new PgSQLDriver(), 'DELETE FROM users AS u WHERE id = 3 AND confirmed IS TRUE'], [new SQLiteDriver(), 'DELETE FROM users AS u WHERE id = 3 AND confirmed IS 1']]);
 }
Ejemplo n.º 2
0
 /**
  * Delete current record, the record should be loaded already.
  *
  * @return Result operation result (success or error)
  */
 public function delete($pkId = NULL)
 {
     $k = static::primary_key;
     if (!$k) {
         throw new Exception("primary key is not defined.");
     }
     if ($pkId == NULL && !isset($this->_data[$k])) {
         throw new Exception('Record is not loaded, Record delete failed.');
     }
     $kVal = $pkId ? $pkId : ($this->_data && isset($this->_data[$k]) ? $this->_data[$k] : NULL);
     if (!$this->currentUserCan($this->getCurrentUser(), 'delete')) {
         return $this->reportError(_('Permission denied. Can not delete record.'), array());
     }
     $dsId = $this->getWriteSourceId();
     $conn = $this->getWriteConnection();
     $this->beforeDelete($this->_data);
     $arguments = new ArgumentArray();
     $query = new DeleteQuery();
     $query->delete($this->getTable());
     $query->where()->equal($k, $kVal);
     $sql = $query->toSql($conn->createQueryDriver(), $arguments);
     $vars = $arguments->toArray();
     $validationResults = array();
     try {
         $this->dbPrepareAndExecute($conn, $sql, $arguments->toArray());
     } catch (PDOException $e) {
         throw new QueryException('Delete failed', $e, array('sql' => $sql, 'validations' => $validationResults));
     }
     $this->afterDelete($this->_data);
     $this->clear();
     return $this->reportSuccess('Record deleted', array('sql' => $sql));
 }
Ejemplo n.º 3
0
 /**
  * Delete current record, the record should be loaded already.
  *
  * @return Result operation result (success or error)
  */
 public function delete()
 {
     $k = static::PRIMARY_KEY;
     if (!isset($this->_data[$k])) {
         throw new Exception('Record is not loaded, Record delete failed.');
     }
     $kVal = $this->_data[$k];
     if (!$this->currentUserCan($this->getCurrentUser(), 'delete')) {
         return $this->reportError(_('Permission denied. Can not delete record.'), array());
     }
     $dsId = $this->writeSourceId;
     $conn = $this->getWriteConnection();
     $driver = $this->getWriteQueryDriver();
     $this->beforeDelete($this->_data);
     $arguments = new ArgumentArray();
     $query = new DeleteQuery();
     $query->delete($this->table);
     $query->where()->equal($k, $kVal);
     $sql = $query->toSql($driver, $arguments);
     $vars = $arguments->toArray();
     $validationResults = array();
     $stm = $conn->prepare($sql);
     $stm->execute($arguments->toArray());
     $this->afterDelete($this->_data);
     $this->clear();
     return $this->reportSuccess('Record deleted', array('sql' => $sql, 'type' => Result::TYPE_DELETE));
 }
Ejemplo n.º 4
0
 public function delete()
 {
     $schema = $this->getSchema();
     $dsId = $schema->getWriteSourceId();
     $conn = ConnectionManager::getInstance()->getConnection($dsId);
     $driver = $conn->createQueryDriver();
     $query = new DeleteQuery();
     $query->from($this->getTable());
     $query->setWhere(clone $this->getCurrentReadQuery()->getWhere());
     $arguments = new ArgumentArray();
     $sql = $query->toSql($driver, $arguments);
     try {
         $this->handle = $conn->prepareAndExecute($sql, $arguments->toArray());
     } catch (Exception $e) {
         return Result::failure('Collection delete failed: ' . $e->getMessage(), array('vars' => $arguments->toArray(), 'sql' => $sql, 'exception' => $e));
     }
     return Result::success('Deleted', array('sql' => $sql));
 }