Example #1
0
 /**
  * @return \Doctrine\DBAL\Platforms\AbstractPlatform
  */
 private function getTargetPlatform()
 {
     if (!$this->targetPlatform) {
         $this->targetPlatform = $this->em->getConnection()->getDatabasePlatform();
     }
     return $this->targetPlatform;
 }
Example #2
0
 /**
  * @param object $entity
  * @param array $queryResult
  * @return object
  * @throws \Doctrine\DBAL\DBALException
  * @throws \Doctrine\ORM\Mapping\MappingException
  */
 public function hydrate($entity, $queryResult)
 {
     $platform = $this->em->getConnection()->getDatabasePlatform();
     foreach ($queryResult as $columnName => $value) {
         $fieldName = $this->metaData->getFieldForColumn($columnName);
         $typeForField = $this->metaData->getTypeOfField($fieldName);
         if ($typeForField) {
             $type = Type::getType($typeForField);
             $entity->{$fieldName} = $type->convertToPHPValue($value, $platform);
         } else {
             throw new RuntimeException('Unknown type for field ' . $fieldName);
         }
     }
     return $entity;
 }
Example #3
0
File: DBAL.php Project: lynx/lynx
 /**
  * @param object $entity
  * @return int
  * @throws \Doctrine\ORM\Mapping\MappingException
  */
 public function update($entity)
 {
     $identifiers = [];
     $types = ['id' => \PDO::PARAM_INT];
     foreach ($this->metaData->getIdentifierColumnNames() as $columnName) {
         $fieldName = $this->metaData->getFieldForColumn($columnName);
         $value = $this->metaData->getFieldValue($entity, $fieldName);
         $identifiers[$columnName] = $value;
     }
     $updateSet = [];
     foreach ($this->metaData->getColumnNames() as $columnName) {
         if (isset($identifiers[$columnName])) {
             continue;
         }
         $fieldName = $this->metaData->getFieldForColumn($columnName);
         $typeName = $this->metaData->getTypeOfColumn($fieldName);
         $type = \Doctrine\DBAL\Types\Type::getType($typeName);
         $value = $type->convertToDatabaseValue($entity->{$fieldName}, $this->em->getConnection()->getDatabasePlatform());
         $types[$columnName] = $type->getBindingType();
         $updateSet[$columnName] = $value;
     }
     return $this->em->getConnection()->update($this->metaData->getTableName(), $updateSet, $identifiers, $types);
 }