delete() 공개 메소드

Table expression and columns are not escaped and are not safe for user-input.
public delete ( string $tableExpression, array $identifier, array $types = [] ) : integer
$tableExpression string The expression of the table on which to delete.
$identifier array The deletion criteria. An associative array containing column-value pairs.
$types array The types of identifiers.
리턴 integer The number of affected rows.
예제 #1
0
 /**
  * Update system data on databse
  *
  * @param array $system
  */
 public function update($system)
 {
     foreach ($system as $key => $value) {
         $this->databaseConnection->delete($this->systemTable, ['`key`' => $key]);
         $this->insert($key, $value);
     }
 }
예제 #2
0
 public function restorePortfolioTitle()
 {
     $totalPortfolioProcessed = 0;
     $nbPortfolioProcessed = 0;
     if ($this->connection->getSchemaManager()->tablesExist(array('icap__portfolio_widget_title'))) {
         $this->log('Restoring portfolio titles...');
         $rowPortfolioTitles = $this->connection->query('SELECT * FROM icap__portfolio_widget_title');
         $sql = 'SELECT aw.id, aw.user_id FROM icap__portfolio_abstract_widget aw WHERE id = :id';
         $stmt = $this->connection->prepare($sql);
         foreach ($rowPortfolioTitles as $rowPortfolioTitle) {
             $stmt->bindValue('id', $rowPortfolioTitle['id']);
             $stmt->execute();
             foreach ($stmt->fetchAll() as $rowAbstractWidget) {
                 $this->connection->update('icap__portfolio', ['title' => $rowPortfolioTitle['title'], 'slug' => $rowPortfolioTitle['slug']], ['id' => $rowAbstractWidget['user_id']]);
             }
             $this->connection->delete('icap__portfolio_abstract_widget', ['id' => $rowPortfolioTitle['id']]);
             ++$nbPortfolioProcessed;
             if ($nbPortfolioProcessed >= 10) {
                 $totalPortfolioProcessed += $nbPortfolioProcessed;
                 $nbPortfolioProcessed = 0;
                 $this->log('    processing portfolio...');
             }
         }
         $this->log(sprintf('  %d portfolio processed', $totalPortfolioProcessed + $nbPortfolioProcessed));
         $this->connection->delete('icap__portfolio_widget_type', ['name' => 'title']);
         $this->connection->getSchemaManager()->dropTable('icap__portfolio_widget_title');
     }
 }
 /**
  * @param ReminderWasAddedToTodo $event
  * @return void
  */
 public function onReminderWasAddedToTodo(ReminderWasAddedToTodo $event)
 {
     // remove other reminder for todo first
     $this->connection->delete(Table::TODO_REMINDER, ['todo_id' => $event->todoId()->toString()]);
     $reminder = $event->reminder();
     $this->connection->insert(Table::TODO_REMINDER, ['todo_id' => $event->todoId()->toString(), 'reminder' => $reminder->toString(), 'status' => $reminder->status()->toString()]);
 }
 public function delete($id)
 {
     $count = $this->db->delete($this->entityTable, array("id" => $id));
     if ($count <= 0) {
         throw new InvalidArgumentException("The delete failed.");
     }
 }
예제 #5
0
 /**
  * @param array $criteria Criterios de la consulta DELETE adoptados en el WHERE
  *
  * @return int Filas afectadas
  */
 protected function _delete(array $criteria = array())
 {
     if (!is_null($this->_table)) {
         $this->_affectedRows = $this->_db->delete($this->_table, $criteria);
         return $this->_affectedRows;
     }
 }
예제 #6
0
 /**
  * Deletes the order.
  *
  * @param \MusicBox\Entity\order $order
  */
 public function delete($order)
 {
     // If the order had an image, delete it.
     $image = $order->getImage();
     if ($image) {
         unlink('images/orders/' . $image);
     }
     return $this->db->delete('orders', array('order_id' => $order->getId()));
 }
예제 #7
0
 public function delete(IEntity $entity)
 {
     $eventPre = new GenericEvent($entity);
     $this->eventDispatcher->dispatch("pre-delete-" . $this->entityName, $eventPre);
     $return = $this->db->delete($this->table, array("id" => $eventPre->getSubject()->getId()));
     $eventPost = new GenericEvent($eventPre->getSubject());
     $this->eventDispatcher->dispatch("post-delete-" . $this->entityName, new GenericEvent($eventPost));
     return $return;
 }
예제 #8
0
 /**
  * Deletes the artist.
  *
  * @param \MusicBox\Entity\Artist $artist
  * @return boolean
  */
 public function delete($artist)
 {
     // If the artist had an image, delete it.
     $image = $artist->getImage();
     if ($image) {
         unlink('images/artists/' . $image);
     }
     return $this->db->delete('artists', array('artist_id' => $artist->getId()));
 }
 /**
  * {@inheritDoc}
  */
 public function remove($key)
 {
     if (!$this->tableExists()) {
         return;
     }
     $this->conn->delete(self::TABLE, array($this->keyColumn => $this->generateKey($key)));
 }
예제 #10
0
 /**
  * {@inheritDoc}
  */
 public function unregisterNamespace($prefix)
 {
     $this->conn->delete('phpcr_namespaces', array('prefix' => $prefix));
     if (!empty($this->namespaces)) {
         unset($this->namespaces[$prefix]);
     }
 }
예제 #11
0
 /**
  * Deletes a managed entity.
  *
  * The entity to delete must be managed and have a persistent identifier.
  * The deletion happens instantaneously.
  *
  * Subclasses may override this method to customize the semantics of entity deletion.
  *
  * @param object $entity The entity to delete.
  */
 public function delete($entity)
 {
     $identifier = $this->_em->getUnitOfWork()->getEntityIdentifier($entity);
     $this->deleteJoinTableRecords($identifier);
     $id = array_combine($this->_class->getIdentifierColumnNames(), $identifier);
     $this->_conn->delete($this->_class->getQuotedTableName($this->_platform), $id);
 }
예제 #12
0
 /**
  * @param string $version
  * @param \DateTime $apply_at
  * @throws \Exception
  */
 public function fixVersion($version, \DateTime $apply_at = null)
 {
     if ($apply_at === null) {
         $apply_at = new \DateTime();
     }
     $this->createTable();
     $this->doctrine->beginTransaction();
     try {
         $this->doctrine->delete(self::TABLE_NAME, array('version' => $version));
         $this->doctrine->insert(self::TABLE_NAME, array('version' => $version, 'apply_at' => $apply_at->format('Y-m-d\\TH:i:s')));
         $this->doctrine->commit();
     } catch (\Exception $ex) {
         $this->doctrine->rollBack();
         throw $ex;
     }
 }
예제 #13
0
 /**
  * {@inheritdoc}
  */
 public function delete($tableExpression, array $identifier, array $types = [])
 {
     $fixedIdentifier = [];
     foreach ($identifier as $columnName => $value) {
         $fixedIdentifier[$this->quoteIdentifier($columnName)] = $value;
     }
     return parent::delete($this->quoteIdentifier($tableExpression), $fixedIdentifier, $types);
 }
예제 #14
0
 /**
  * {@inheritdoc}
  */
 public function remove($id)
 {
     try {
         $this->connection->delete($this->tableName, [self::COLUMN_ID => $id]);
     } catch (DBALException $e) {
         throw DatabaseException::fromDBALException($e);
     }
 }
예제 #15
0
 public function saveUserTags(User $user)
 {
     $this->dbal->delete('userTags', ['user_id' => $user->getId()]);
     foreach ($user->getMentorTags() as $mentorTag) {
         echo 'Saving ' . $mentorTag->getName();
         $this->dbal->insert('userTags', ['user_id' => $user->getId(), 'term_id' => $mentorTag->getId()]);
     }
     foreach ($user->getApprenticeTags() as $apprenticeTag) {
         echo 'Saving ' . $apprenticeTag->getName();
         $this->dbal->insert('userTags', ['user_id' => $user->getId(), 'term_id' => $apprenticeTag->getId()]);
     }
 }
예제 #16
0
 /**
  * Run all fixtures.
  *
  * @param Connection $connection
  * @param bool       $append     Don't empty tables before loading
  */
 public function run(Connection $connection, $append = false)
 {
     if (!$append) {
         //in the future, resolve key constraints here
         foreach (array_unique($this->dropTables) as $table) {
             $connection->delete($table, [1 => 1], [\PDO::PARAM_INT]);
         }
     }
     foreach ($this->getSortedFixtures() as $fixture) {
         $this->runFixture($connection, $fixture);
     }
 }
 /**
  * Delete a workflow by its ID
  *
  * @param int $workflowId
  * @return void
  */
 public function delete($workflowId)
 {
     $this->conn->beginTransaction();
     try {
         // delete only those two, the rest should be deleted automatically through cascading foreign keys
         $this->conn->delete($this->options->variableHandlerTable(), array('workflow_id' => $workflowId));
         $this->conn->delete($this->options->workflowTable(), array('workflow_id' => $workflowId));
         $this->conn->commit();
     } catch (\Exception $e) {
         $this->conn->rollback();
     }
 }
예제 #18
0
 /**
  * Removes the object from the database
  *
  * @param DataObjectInterface $object
  * @throws \Doctrine\DBAL\Exception\InvalidArgumentException
  */
 public function delete(DataObjectInterface $object)
 {
     $this->checkArgument($object);
     $this->dispatchEvents('beforeDelete', $object);
     $columns = $this->queryHelper->getDbColumns($object->getTableName());
     if (isset($columns['isDeleted'])) {
         $this->db->update($object->getTableName(), [$this->db->quoteIdentifier('isDeleted') => 1], ['id' => $object->getId()]);
     } else {
         $this->db->delete($object->getTableName(), ['id' => $object->getId()]);
     }
     $object->setDeleted(true);
     $this->dispatchEvents('afterDelete', $object);
 }
예제 #19
0
 /**
  * Generates a delete string and executes it.
  *
  * @throws \Exception
  * @return boolean True if delete was successful.
  */
 public function delete()
 {
     if (!$this->beforeDelete()) {
         return false;
     }
     if (!isset($this->id)) {
         throw new \Exception('cant delete without id');
     }
     $return = (bool) self::$CONN->delete($this->tableName(), ['id' => $this->id]);
     if (!$this->afterDelete()) {
         $this->save();
         return false;
     }
     return $return;
 }
 /**
  * Salva a lista de presença (salva as faltas) de uma data específica no banco de dados.
  * 
  * @param Connection $conn
  * @param DateTime $date Data da lista de presença
  * @param array $types Tipos de presença
  * @param array $students Alunos
  * @throws Exception
  */
 public static function insertNewList(Connection $conn, DateTime $date, array $types, array $students = [])
 {
     $conn->beginTransaction();
     try {
         foreach ($types as $type) {
             $conn->delete('attendance', ['attendance_date' => $date, 'attendance_type_id' => $type], ['date', PDO::PARAM_INT]);
         }
         foreach ($students as $student) {
             $conn->insert('attendance', ['enrollment_id' => $student['id'], 'attendance_type_id' => $student['type'], 'attendance_date' => $date], [PDO::PARAM_INT, PDO::PARAM_INT, 'date']);
         }
         $conn->commit();
     } catch (Exception $ex) {
         $conn->rollBack();
         throw $ex;
     }
 }
예제 #21
0
파일: Doctrine.php 프로젝트: Anyqax/Phabric
 /**
  * Resets the database state to the point of initial insert or update query.
  *
  * @retun void
  */
 public function reset()
 {
     foreach ($this->resetMap as $entityName => $entity) {
         $tableName = $this->tableMappings[$entityName]['tableName'];
         $pKeyCol = $this->tableMappings[$entityName]['primaryKey'];
         if (isset($entity['insert'])) {
             foreach ($entity['insert'] as $record) {
                 $this->connection->delete($tableName, array($pKeyCol => $record));
             }
         }
         if (isset($entity['update'])) {
             foreach ($entity['update'] as $id => $record) {
                 $this->connection->update($tableName, $record, array($pKeyCol => $id));
             }
         }
     }
 }
예제 #22
0
파일: Users.php 프로젝트: aaleksu/bolt_cm
 /**
  * Log out the currently logged in user.
  */
 public function logout()
 {
     $this->session->getFlashBag()->add('info', Trans::__('You have been logged out.'));
     $this->session->remove('user');
     // @see: https://bugs.php.net/bug.php?id=63379
     try {
         $this->session->migrate(true);
     } catch (\Exception $e) {
     }
     // Remove all auth tokens when logging off a user (so we sign out _all_ this user's sessions on all locations)
     try {
         $this->db->delete($this->authtokentable, array('username' => $this->currentuser['username']));
     } catch (\Exception $e) {
         // Nope. No auth tokens to be deleted. .
     }
     // Remove the cookie.
     setcookie('bolt_authtoken', '', time() - 1, '/', $this->app['config']->get('general/cookies_domain'), $this->app['config']->get('general/enforce_ssl'), true);
 }
예제 #23
0
 /**
  * Delete entity from the database.
  *
  * @param \Lokhman\Silex\ARM\AbstractEntity $entity
  *
  * @throws \Exception
  * @return integer
  *         Number of affected rows
  */
 public function delete(AbstractEntity $entity)
 {
     $this->assert($entity);
     // check if primary key is defined and is not NULL
     $primary = $this->metadata->getPrimary();
     if (!isset($entity[$primary])) {
         self::raise('Primary key is required to update the entity.');
     }
     try {
         $this->db->beginTransaction();
         // pre-delete event
         $this->preDelete($entity);
         // update position indexes
         if ($this->metadata->hasPosition()) {
             $position = $entity[$this->metadata->getPosition()];
             $this->positionShift($entity, $position + 1, null, -1);
         }
         if ($this->translate) {
             // delete all translations for entity
             $this->db->delete($this->app['arm.trans'], ['_table' => $this->table, '_key' => $entity[$primary]]);
         }
         // attempt to delete entity
         $result = $this->db->delete($this->table, [$primary => $entity[$primary]]);
         // delete all files
         $this->unlink($entity);
         $this->db->commit();
         // unset primary key
         unset($entity[$primary]);
         // post-delete event
         $this->postDelete($entity);
     } catch (\Exception $ex) {
         $this->rollback();
         throw $ex;
     }
     return $result;
 }
 /**
  * Deletes the group.
  *
  * @param integer $id
  */
 public function delete($id)
 {
     return $this->db->delete('', array('group_id' => $id));
 }
 /**
  * @param \Doctrine\DBAL\Connection $connection
  */
 function it_deletes_file($connection)
 {
     $connection->quoteIdentifier(Argument::any())->will(function ($argument) {
         return sprintf('"%s"', $argument[0]);
     });
     $connection->delete('someTableName', array('"key"' => 'filename'))->shouldBeCalled()->willReturn(1);
     $this->delete('filename')->shouldReturn(true);
 }
예제 #26
0
파일: Version.php 프로젝트: berchapman/ice9
 public function markNotMigrated()
 {
     $this->configuration->createMigrationTable();
     $this->connection->delete($this->configuration->getMigrationsTableName(), array('version' => $this->version));
 }
 /**
  * {@inheritDoc}
  */
 public function delete($tableName, array $identifier, array $types = array())
 {
     $this->connect('master');
     return parent::delete($tableName, $identifier, $types);
 }
예제 #28
0
    /**
     * Deletes a managed entity.
     *
     * The entity to delete must be managed and have a persistent identifier.
     * The deletion happens instantaneously.
     *
     * Subclasses may override this method to customize the semantics of entity deletion.
     *
     * @param object $entity The entity to delete.
     *
     * @return void
     */
    public function delete($entity)
    {
        $class      = $this->class;
        $em         = $this->em;

        $identifier = $this->em->getUnitOfWork()->getEntityIdentifier($entity);
        $tableName  = $this->quoteStrategy->getTableName($class, $this->platform);
        $idColumns  = $this->quoteStrategy->getIdentifierColumnNames($class, $this->platform);
        $id         = array_combine($idColumns, $identifier);

        $types = array_map(function ($identifier) use ($class, $em) {
            if (isset($class->fieldMappings[$identifier])) {
                return $class->fieldMappings[$identifier]['type'];
            }

            $targetMapping = $em->getClassMetadata($class->associationMappings[$identifier]['targetEntity']);

            if (isset($targetMapping->fieldMappings[$targetMapping->identifier[0]])) {
                return $targetMapping->fieldMappings[$targetMapping->identifier[0]]['type'];
            }

            if (isset($targetMapping->associationMappings[$targetMapping->identifier[0]])) {
                $types[] = $targetMapping->associationMappings[$targetMapping->identifier[0]]['type'];
            }

            throw ORMException::unrecognizedField($targetMapping->identifier[0]);

        }, $class->identifier);

        $this->deleteJoinTableRecords($identifier);
        $this->conn->delete($tableName, $id, $types);
    }
예제 #29
0
 /**
  * Deletes the like.
  *
  * @param integer $id
  */
 public function delete($id)
 {
     return $this->db->delete('likes', array('like_id' => $id));
 }
예제 #30
0
 /**
  * Executes an SQL DELETE statement on a table.
  *
  * @param array $identifier The deletion criteria. An associateve array containing column-value pairs.
  *
  * @return integer The number of affected rows.
  */
 public function delete(array $identifier)
 {
     return $this->db->delete($this->getTableName(), $identifier);
 }