Beispiel #1
0
 public function delete(PostInterface $postObject)
 {
     $action = new Delete('posts');
     $action->where(array('id = ?' => $postObject->getId()));
     $sql = new Sql($this->dbAdapter);
     $stmt = $sql->prepareStatementForSqlObject($action);
     $result = $stmt->execute();
     return (bool) $result->getAffectedRows();
 }
Beispiel #2
0
 /**
  * @covers Zend\Db\Sql\Delete::where
  *
  * @todo REMOVE THIS IN 3.x
  */
 public function testWhere()
 {
     $this->delete->where('x = y');
     $this->delete->where(array('foo > ?' => 5));
     $this->delete->where(array('id' => 2));
     $this->delete->where(array('a = b'), Where::OP_OR);
     $this->delete->where(array('c1' => null));
     $this->delete->where(array('c2' => array(1, 2, 3)));
     $this->delete->where(array(new IsNotNull('c3')));
     $this->delete->where(array('one' => 1, 'two' => 2));
     $where = $this->delete->where;
     $predicates = $this->readAttribute($where, 'predicates');
     $this->assertEquals('AND', $predicates[0][0]);
     $this->assertInstanceOf('Zend\\Db\\Sql\\Predicate\\Literal', $predicates[0][1]);
     $this->assertEquals('AND', $predicates[1][0]);
     $this->assertInstanceOf('Zend\\Db\\Sql\\Predicate\\Expression', $predicates[1][1]);
     $this->assertEquals('AND', $predicates[2][0]);
     $this->assertInstanceOf('Zend\\Db\\Sql\\Predicate\\Operator', $predicates[2][1]);
     $this->assertEquals('OR', $predicates[3][0]);
     $this->assertInstanceOf('Zend\\Db\\Sql\\Predicate\\Literal', $predicates[3][1]);
     $this->assertEquals('AND', $predicates[4][0]);
     $this->assertInstanceOf('Zend\\Db\\Sql\\Predicate\\IsNull', $predicates[4][1]);
     $this->assertEquals('AND', $predicates[5][0]);
     $this->assertInstanceOf('Zend\\Db\\Sql\\Predicate\\In', $predicates[5][1]);
     $this->assertEquals('AND', $predicates[6][0]);
     $this->assertInstanceOf('Zend\\Db\\Sql\\Predicate\\IsNotNull', $predicates[6][1]);
     $this->assertEquals('AND', $predicates[7][0]);
     $this->assertInstanceOf('Zend\\Db\\Sql\\Predicate\\Operator', $predicates[7][1]);
     $this->assertEquals('AND', $predicates[8][0]);
     $this->assertInstanceOf('Zend\\Db\\Sql\\Predicate\\Operator', $predicates[8][1]);
     $where = new Where();
     $this->delete->where($where);
     $this->assertSame($where, $this->delete->where);
     $test = $this;
     $this->delete->where(function ($what) use($test, $where) {
         $test->assertSame($where, $what);
     });
 }
Beispiel #3
0
 public function delete()
 {
     $delete = new ZfSql\Delete($this->tableName);
     $adapter = $this->sql->getAdapter();
     if ($this->select->where) {
         $delete->where($this->select->where);
     }
     $sqlString = $this->sql->getSqlStringForSqlObject($delete);
     try {
         $result = $adapter->query($sqlString, $adapter::QUERY_MODE_EXECUTE);
     } catch (AdapterException\ExceptionInterface $e) {
         throw new Exception\RecordNotDestroyedException($e->getMessage(), 0, $e);
     }
     if (!$result->count()) {
         throw new Exception\RecordNotDestroyedException("No rows were affected");
     }
     return true;
 }
 public function deleteProduct($id)
 {
     $action = new Delete('products');
     $action->where(array('id=?' => $id));
     $sql = new Sql($this->dbAdapter);
     $stmt = $sql->prepareStatementForSqlObject($action);
     $result = $stmt->execute();
     return (bool) $result->getAffectedRows();
 }
Beispiel #5
0
 /**
  * {@inheritDoc}
  */
 public function unsetRefreshToken($refreshToken)
 {
     $delete = new Delete($this->config['refresh_token_table']);
     $delete->where(array('refresh_token' => $refreshToken));
     return $this->execute($delete);
 }
Beispiel #6
0
 protected function _importXhbData($data, $xhbId)
 {
     try {
         // First delete existing XHB unconditionally
         $deleteStmt = new Delete(Xhb::MAIN_TABLE);
         $deleteStmt->where(array('id' => $xhbId));
         $this->_db->query($this->_sql->buildSqlString($deleteStmt), Adapter::QUERY_MODE_EXECUTE);
         $this->_insertInto(Account::MAIN_TABLE, $this->_addAdditionalFields($data['accounts'], $xhbId), null);
         $this->_insertInto(Category::MAIN_TABLE, $this->_addAdditionalFields($data['categories'], $xhbId), null);
         $this->_insertInto(Payee::MAIN_TABLE, $this->_addAdditionalFields($data['payees'], $xhbId), null);
         $this->_insertInto(Operation::MAIN_TABLE, $this->_addAdditionalFields($data['operations'], $xhbId), null);
         $this->_insertOperationSplitAmount($data['operations'], $xhbId);
         // Insert XHB row at the end, so that in case something's gone wrong before, next request may try to
         // create schema and insert data again, without risking to use invalid or incomplete data instead
         $xhbTableData = array_merge($data['properties'], array('id' => $xhbId, 'updated_at' => time()));
         $this->_insertInto(Xhb::MAIN_TABLE, array($xhbTableData));
     } catch (\Exception $e) {
         setlocale(LC_ALL, $oldLocale);
         // If something's gone wrong, destroy everything
         $this->_destroySchema(true);
         throw $e;
     }
     return $this;
 }
Beispiel #7
0
 /**
  * Save document type model
  *
  * @return integer
  */
 public function save()
 {
     $this->events()->trigger(__CLASS__, 'before.save', $this);
     $arraySave = array('name' => $this->getName(), 'updated_at' => new Expression('NOW()'), 'description' => $this->getDescription(), 'icon_id' => $this->getIconId(), 'default_view_id' => $this->getDefaultViewId(), 'user_id' => $this->getUserId());
     try {
         $id = $this->getId();
         if (empty($id)) {
             $arraySave['created_at'] = new Expression('NOW()');
             $this->insert($arraySave);
             $this->setId($this->getLastInsertId());
         } else {
             $this->update($arraySave, array('id' => (int) $this->getId()));
         }
         $delete = new Sql\Delete();
         $delete->from('document_type_view');
         $delete->where(array('document_type_id' => (int) $this->getId()));
         $this->execute($delete);
         foreach ($this->views as $viewId) {
             if (empty($viewId)) {
                 continue;
             }
             $insert = new Sql\Insert();
             $insert->into('document_type_view')->values(array('document_type_id' => $this->getId(), 'view_id' => $viewId));
             $this->execute($insert);
         }
         $delete = new Sql\Delete();
         $delete->from('document_type_dependency');
         $delete->where->equalTo('parent_id', (int) $this->getId());
         $this->execute($delete);
         $dependencies = $this->getDependencies();
         if (!empty($dependencies)) {
             foreach ($dependencies as $childrenId) {
                 $insert = new Sql\Insert();
                 $insert->into('document_type_dependency')->values(array('parent_id' => $this->getId(), 'children_id' => $childrenId));
                 $this->execute($insert);
             }
         }
         $this->events()->trigger(__CLASS__, 'after.save', $this);
         return $this->getId();
     } catch (\Exception $e) {
         $this->events()->trigger(__CLASS__, 'after.save.failed', $this);
         throw new \Gc\Exception($e->getMessage(), $e->getCode(), $e);
     }
 }
Beispiel #8
0
 public function deleteSkillByTopic($topic_id = NULL)
 {
     $sql = new Sql($this->adapter);
     $delete = new Delete($this->topicSkill);
     $delete->where(array("topic_id" => $topic_id));
     $selectString = $sql->getSqlStringForSqlObject($delete);
     $results = $this->adapter->query($selectString, Adapter::QUERY_MODE_EXECUTE);
 }
Beispiel #9
0
 public function deletePermissionByUserId($user_id = NULL)
 {
     $sql = new Sql($this->adapter);
     $delete = new Delete($this->user_permission);
     $delete->where(array("user_id" => $user_id));
     $selectString = $sql->getSqlStringForSqlObject($delete);
     $results = $this->adapter->query($selectString, Adapter::QUERY_MODE_EXECUTE);
 }
 public function deleteData($table, $where)
 {
     $sql = new Sql($this->dbAdapter);
     $action = new Delete();
     $action->from($table);
     $action->where($where);
     $stmt = $sql->prepareStatementForSqlObject($action);
     $result = $stmt->execute();
     return $result;
 }