Exemplo n.º 1
0
 /**
  * Updates provided entity within storage.
  *
  * @param object $entity
  * @return void
  * @throws \DomainException
  * @throws \RuntimeException
  */
 public function update($entity)
 {
     $this->entityMetadata = $this->getEntityMetadata($entity);
     $entityStorage = $this->entityMetadata->getStorage();
     $connectionId = $entityStorage->getConnectionId();
     $this->connection = $this->getConnection($connectionId);
     $dbTable = $entityStorage->getTable();
     $sqlTable = $this->connection->escapeAndQuoteTable($dbTable);
     $sqlProperties = array();
     $parameters = array();
     foreach ($this->exportEntity($entity) as $columnName => $value) {
         $sqlField = $this->connection->escapeAndQuoteField($columnName);
         $sqlProperties[] = "{$sqlField} = ?";
         $parameters[] = $value;
     }
     $primaryKeyFilter = $this->getPrimaryKeyFilter($entity);
     $sqlWhere = $primaryKeyFilter->getClause();
     foreach ($primaryKeyFilter->getParameters() as $parameter) {
         $parameters[] = $parameter;
     }
     $sql = "UPDATE {$sqlTable} SET " . join(', ', $sqlProperties) . " WHERE {$sqlWhere}";
     $this->connection->execute($sql, $parameters);
 }
Exemplo n.º 2
0
 /**
  *
  *
  * @return void
  */
 private function from()
 {
     $entityStorage = $this->entityMetadata->getStorage();
     $table = $entityStorage->getTable();
     $this->sqlChunks[] = 'FROM ' . $this->connection->escapeAndQuoteTable($table);
 }