public function convertToPHPValue($value, AbstractPlatform $platform) { if ($value === null) { return null; } $val = \DateTime::createFromFormat($platform->getDateTimeFormatString(), $value, self::$utc ? self::$utc : (self::$utc = new \DateTimeZone(\DateTimeZone::UTC))); if (!$val) { throw ConversionException::conversionFailed($value, $this->getName()); } return $val; }
/** * Completes the ID generator mapping. If "auto" is specified we choose the generator * most appropriate for the targeted database platform. * * @param \Doctrine\ORM\Mapping\ClassMetadata $class */ private function completeIdGeneratorMapping(ClassMetadataInfo $class) { $idGenType = $class->generatorType; if ($idGenType == ClassMetadata::GENERATOR_TYPE_AUTO) { if ($this->targetPlatform->prefersSequences()) { $class->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_SEQUENCE); } else { if ($this->targetPlatform->prefersIdentityColumns()) { $class->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_IDENTITY); } else { $class->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_TABLE); } } } // Create & assign an appropriate ID generator instance switch ($class->generatorType) { case ClassMetadata::GENERATOR_TYPE_IDENTITY: // For PostgreSQL IDENTITY (SERIAL) we need a sequence name. It defaults to // <table>_<column>_seq in PostgreSQL for SERIAL columns. // Not pretty but necessary and the simplest solution that currently works. $seqName = $this->targetPlatform instanceof Platforms\PostgreSQLPlatform ? $class->getTableName() . '_' . $class->columnNames[$class->identifier[0]] . '_seq' : null; $class->setIdGenerator(new \Doctrine\ORM\Id\IdentityGenerator($seqName)); break; case ClassMetadata::GENERATOR_TYPE_SEQUENCE: // If there is no sequence definition yet, create a default definition $definition = $class->sequenceGeneratorDefinition; if (!$definition) { $sequenceName = $class->getTableName() . '_' . $class->getSingleIdentifierColumnName() . '_seq'; $definition['sequenceName'] = $this->targetPlatform->fixSchemaElementName($sequenceName); $definition['allocationSize'] = 1; $definition['initialValue'] = 1; $class->setSequenceGeneratorDefinition($definition); } $sequenceGenerator = new \Doctrine\ORM\Id\SequenceGenerator($definition['sequenceName'], $definition['allocationSize']); $class->setIdGenerator($sequenceGenerator); break; case ClassMetadata::GENERATOR_TYPE_NONE: $class->setIdGenerator(new \Doctrine\ORM\Id\AssignedGenerator()); break; case ClassMetadata::GENERATOR_TYPE_UUID: $class->setIdGenerator(new \Doctrine\ORM\Id\UuidGenerator()); break; case ClassMetadata::GENERATOR_TYPE_TABLE: throw new ORMException("TableGenerator not yet implemented."); break; case ClassMetadata::GENERATOR_TYPE_CUSTOM: $definition = $class->customGeneratorDefinition; if (!class_exists($definition['class'])) { throw new ORMException("Can't instantiate custom generator : " . $definition['class']); } $class->setIdGenerator(new $definition['class']()); break; default: throw new ORMException("Unknown generator type: " . $class->generatorType); } }
/** * Generates the INSERT SQL used by the persister to persist entities. * * @return string */ protected function _generateInsertSql() { $insertSql = ''; $columns = $this->_getInsertColumnList(); if (empty($columns)) { $insertSql = $this->_platform->getEmptyIdentityInsertSql($this->_class->getQuotedTableName($this->_platform), $this->_class->getQuotedColumnName($this->_class->identifier[0], $this->_platform)); } else { $columns = array_unique($columns); $values = array_fill(0, count($columns), '?'); $insertSql = 'INSERT INTO ' . $this->_class->getQuotedTableName($this->_platform) . ' (' . implode(', ', $columns) . ') ' . 'VALUES (' . implode(', ', $values) . ')'; } return $insertSql; }
/** * Gets the SQL snippet for all join columns of the given class that are to be * placed in an SQL SELECT statement. * * @return string */ protected function _getSelectJoinColumnsSQL(ClassMetadata $class) { $sql = ''; foreach ($class->associationMappings as $assoc) { if ($assoc->isOwningSide && $assoc->isOneToOne()) { foreach ($assoc->targetToSourceKeyColumns as $srcColumn) { $columnAlias = $srcColumn . $this->_sqlAliasCounter++; $sql .= ', ' . $this->_getSQLTableAlias($this->_class) . ".{$srcColumn} AS {$columnAlias}"; $resultColumnName = $this->_platform->getSQLResultCasing($columnAlias); if (!isset($this->_resultColumnNames[$resultColumnName])) { $this->_resultColumnNames[$resultColumnName] = $srcColumn; } } } } return $sql; }
/** * Walks down a SubselectFromClause AST node, thereby generating the appropriate SQL. * * @param SubselectFromClause * @return string The SQL. */ public function walkSubselectFromClause($subselectFromClause) { $identificationVarDecls = $subselectFromClause->identificationVariableDeclarations; $sqlParts = array(); foreach ($identificationVarDecls as $subselectIdVarDecl) { $sql = ''; $rangeDecl = $subselectIdVarDecl->rangeVariableDeclaration; $dqlAlias = $rangeDecl->aliasIdentificationVariable; $class = $this->_em->getClassMetadata($rangeDecl->abstractSchemaName); $sql .= $class->getQuotedTableName($this->_platform) . ' ' . $this->getSqlTableAlias($class->table['name'], $dqlAlias); if ($class->isInheritanceTypeJoined()) { $sql .= $this->_generateClassTableInheritanceJoins($class, $dqlAlias); } foreach ($subselectIdVarDecl->joinVariableDeclarations as $joinVarDecl) { $sql .= $this->walkJoinVariableDeclaration($joinVarDecl); } $sqlParts[] = $this->_platform->appendLockHint($sql, $this->_query->getHint(Query::HINT_LOCK_MODE)); } return ' FROM ' . implode(', ', $sqlParts); }
public function getSqlDeclaration(array $fieldDeclaration, AbstractPlatform $platform) { return $platform->getBigIntTypeDeclarationSql($fieldDeclaration); }
/** * {@inheritdoc} * * @override */ public function convertToPHPValue($value, AbstractPlatform $platform) { return $value !== null ? \DateTime::createFromFormat($platform->getTimeFormatString(), $value) : null; }
public function convertToDatabaseValue($value, AbstractPlatform $platform) { return $platform->convertBooleans($value); }
/** * @override */ public function getDefaultValueDeclarationSql($field) { if (!empty($field['nextval'])) { return ' NOT NULL'; } else { return parent::getDefaultValueDeclarationSql($field); } }
/** * Creates a new MySqlPlatform instance. */ public function __construct() { parent::__construct(); }
/** * Walks down a SubselectFromClause AST node, thereby generating the appropriate SQL. * * @param SubselectFromClause * @return string The SQL. */ public function walkSubselectFromClause($subselectFromClause) { $identificationVarDecls = $subselectFromClause->identificationVariableDeclarations; $sqlParts = array(); foreach ($identificationVarDecls as $subselectIdVarDecl) { $sql = $this->platform->appendLockHint($this->walkRangeVariableDeclaration($subselectIdVarDecl->rangeVariableDeclaration), $this->query->getHint(Query::HINT_LOCK_MODE)); foreach ($subselectIdVarDecl->joins as $join) { $sql .= $this->walkJoin($join); } $sqlParts[] = $sql; } return ' FROM ' . implode(', ', $sqlParts); }
/** * Gets the (possibly quoted) name of the discriminator column for safe use * in an SQL statement. * * @param AbstractPlatform $platform * @return string */ public function getQuotedDiscriminatorColumnName($platform) { return isset($this->discriminatorColumn['quoted']) ? $platform->quoteIdentifier($this->discriminatorColumn['name']) : $this->discriminatorColumn['name']; }
/** * Gets the (possibly quoted) column name of a join column that is safe to use * in an SQL statement. * * @param string $joinColumn * @param AbstractPlatform $platform * @return string */ public function getQuotedJoinColumnName($joinColumn, $platform) { return isset($this->joinColumns[$joinColumn]['quoted']) ? $platform->quoteIdentifier($joinColumn) : $joinColumn; }
/** * Gets the (possibly quoted) column name of a mapped field for safe use * in an SQL statement. * * @param string $field * @param AbstractPlatform $platform * @return string */ public function getQuotedColumnName($field, $platform) { return isset($this->fieldMappings[$field]['quoted']) ? $platform->quoteIdentifier($this->fieldMappings[$field]['columnName']) : $this->fieldMappings[$field]['columnName']; }
/** * Enter description here... * * @param unknown_type $level * @override */ protected function _getTransactionIsolationLevelSql($level) { switch ($level) { case Doctrine_DBAL_Connection::TRANSACTION_READ_UNCOMMITTED: return 'READ COMMITTED RECORD_VERSION'; case Doctrine_DBAL_Connection::TRANSACTION_READ_COMMITTED: return 'READ COMMITTED NO RECORD_VERSION'; case Doctrine_DBAL_Connection::TRANSACTION_REPEATABLE_READ: return 'SNAPSHOT'; case Doctrine_DBAL_Connection::TRANSACTION_SERIALIZABLE: return 'SNAPSHOT TABLE STABILITY'; default: return parent::_getTransactionIsolationLevelSql($level); } }
protected function _getTransactionIsolationLevelSql($level) { switch ($level) { // case \Doctrine\DBAL\Connection::TRANSACTION_READ_UNCOMMITTED: // return 0; // case \Doctrine\DBAL\Connection::TRANSACTION_READ_COMMITTED: // case \Doctrine\DBAL\Connection::TRANSACTION_REPEATABLE_READ: // case \Doctrine\DBAL\Connection::TRANSACTION_SERIALIZABLE: // return 1; default: return parent::_getTransactionIsolationLevelSql($level); } }
/** * Gets the (possibly quoted) name of the join table. * * @param AbstractPlatform $platform * @return string */ public function getQuotedJoinTableName(array $assoc, $platform) { return isset($assoc['joinTable']['quoted']) ? $platform->quoteIdentifier($assoc['joinTable']['name']) : $assoc['joinTable']['name']; }
/** * @override */ public function getCreateIndexSQL(Index $index, $table) { $constraint = parent::getCreateIndexSQL($index, $table); if ($index->isUnique()) { $constraint = $this->_appendUniqueConstraintDefinition($constraint, $index); } return $constraint; }
/** * Walks down a SelectExpression AST node and generates the corresponding SQL. * * @param SelectExpression $selectExpression * @return string The SQL. */ public function walkSelectExpression($selectExpression) { $sql = ''; $expr = $selectExpression->expression; if ($expr instanceof AST\PathExpression) { if ($expr->type == AST\PathExpression::TYPE_STATE_FIELD) { $parts = $expr->parts; $fieldName = array_pop($parts); $dqlAlias = $expr->identificationVariable . (!empty($parts) ? '.' . implode('.', $parts) : ''); $qComp = $this->_queryComponents[$dqlAlias]; $class = $qComp['metadata']; if (!$selectExpression->fieldIdentificationVariable) { $resultAlias = $fieldName; } else { $resultAlias = $selectExpression->fieldIdentificationVariable; } if ($class->isInheritanceTypeJoined()) { $tableName = $this->_em->getUnitOfWork()->getEntityPersister($class->name)->getOwningTable($fieldName); } else { $tableName = $class->getTableName(); } $sqlTableAlias = $this->getSqlTableAlias($tableName, $dqlAlias); $columnName = $class->getQuotedColumnName($fieldName, $this->_platform); $columnAlias = $this->getSqlColumnAlias($columnName); $sql .= $sqlTableAlias . '.' . $columnName . ' AS ' . $columnAlias; $columnAlias = $this->_platform->getSQLResultCasing($columnAlias); $this->_rsm->addScalarResult($columnAlias, $resultAlias); } else { throw QueryException::invalidPathExpression($expr->type); } } else { if ($expr instanceof AST\AggregateExpression) { if (!$selectExpression->fieldIdentificationVariable) { $resultAlias = $this->_scalarResultCounter++; } else { $resultAlias = $selectExpression->fieldIdentificationVariable; } $columnAlias = 'sclr' . $this->_aliasCounter++; $sql .= $this->walkAggregateExpression($expr) . ' AS ' . $columnAlias; $this->_scalarResultAliasMap[$resultAlias] = $columnAlias; $columnAlias = $this->_platform->getSQLResultCasing($columnAlias); $this->_rsm->addScalarResult($columnAlias, $resultAlias); } else { if ($expr instanceof AST\Subselect) { if (!$selectExpression->fieldIdentificationVariable) { $resultAlias = $this->_scalarResultCounter++; } else { $resultAlias = $selectExpression->fieldIdentificationVariable; } $columnAlias = 'sclr' . $this->_aliasCounter++; $sql .= '(' . $this->walkSubselect($expr) . ') AS ' . $columnAlias; $this->_scalarResultAliasMap[$resultAlias] = $columnAlias; $columnAlias = $this->_platform->getSQLResultCasing($columnAlias); $this->_rsm->addScalarResult($columnAlias, $resultAlias); } else { if ($expr instanceof AST\Functions\FunctionNode) { if (!$selectExpression->fieldIdentificationVariable) { $resultAlias = $this->_scalarResultCounter++; } else { $resultAlias = $selectExpression->fieldIdentificationVariable; } $columnAlias = 'sclr' . $this->_aliasCounter++; $sql .= $this->walkFunction($expr) . ' AS ' . $columnAlias; $this->_scalarResultAliasMap[$resultAlias] = $columnAlias; $columnAlias = $this->_platform->getSQLResultCasing($columnAlias); $this->_rsm->addScalarResult($columnAlias, $resultAlias); } else { if ($expr instanceof AST\SimpleArithmeticExpression) { if (!$selectExpression->fieldIdentificationVariable) { $resultAlias = $this->_scalarResultCounter++; } else { $resultAlias = $selectExpression->fieldIdentificationVariable; } $columnAlias = 'sclr' . $this->_aliasCounter++; $sql .= $this->walkSimpleArithmeticExpression($expr) . ' AS ' . $columnAlias; $this->_scalarResultAliasMap[$resultAlias] = $columnAlias; $columnAlias = $this->_platform->getSQLResultCasing($columnAlias); $this->_rsm->addScalarResult($columnAlias, $resultAlias); } else { // IdentificationVariable or PartialObjectExpression if ($expr instanceof AST\PartialObjectExpression) { $dqlAlias = $expr->identificationVariable; $partialFieldSet = $expr->partialFieldSet; } else { $dqlAlias = $expr; $partialFieldSet = array(); } $queryComp = $this->_queryComponents[$dqlAlias]; $class = $queryComp['metadata']; if (!isset($this->_selectedClasses[$dqlAlias])) { $this->_selectedClasses[$dqlAlias] = $class; } $beginning = true; // Select all fields from the queried class foreach ($class->fieldMappings as $fieldName => $mapping) { if ($partialFieldSet && !in_array($fieldName, $partialFieldSet)) { continue; } if (isset($mapping['inherited'])) { $tableName = $this->_em->getClassMetadata($mapping['inherited'])->primaryTable['name']; } else { $tableName = $class->primaryTable['name']; } if ($beginning) { $beginning = false; } else { $sql .= ', '; } $sqlTableAlias = $this->getSqlTableAlias($tableName, $dqlAlias); $columnAlias = $this->getSqlColumnAlias($mapping['columnName']); $sql .= $sqlTableAlias . '.' . $class->getQuotedColumnName($fieldName, $this->_platform) . ' AS ' . $columnAlias; $columnAlias = $this->_platform->getSQLResultCasing($columnAlias); $this->_rsm->addFieldResult($dqlAlias, $columnAlias, $fieldName, $class->name); } // Add any additional fields of subclasses (excluding inherited fields) // 1) on Single Table Inheritance: always, since its marginal overhead // 2) on Class Table Inheritance only if partial objects are disallowed, // since it requires outer joining subtables. if ($class->isInheritanceTypeSingleTable() || !$this->_query->getHint(Query::HINT_FORCE_PARTIAL_LOAD)) { foreach ($class->subClasses as $subClassName) { $subClass = $this->_em->getClassMetadata($subClassName); $sqlTableAlias = $this->getSqlTableAlias($subClass->primaryTable['name'], $dqlAlias); foreach ($subClass->fieldMappings as $fieldName => $mapping) { if (isset($mapping['inherited']) || $partialFieldSet && !in_array($fieldName, $partialFieldSet)) { continue; } if ($beginning) { $beginning = false; } else { $sql .= ', '; } $columnAlias = $this->getSqlColumnAlias($mapping['columnName']); $sql .= $sqlTableAlias . '.' . $subClass->getQuotedColumnName($fieldName, $this->_platform) . ' AS ' . $columnAlias; $columnAlias = $this->_platform->getSQLResultCasing($columnAlias); $this->_rsm->addFieldResult($dqlAlias, $columnAlias, $fieldName, $subClassName); } // Add join columns (foreign keys) of the subclass //TODO: Probably better do this in walkSelectClause to honor the INCLUDE_META_COLUMNS hint foreach ($subClass->associationMappings as $fieldName => $assoc) { if ($assoc->isOwningSide && $assoc->isOneToOne() && !isset($subClass->inheritedAssociationFields[$fieldName])) { foreach ($assoc->targetToSourceKeyColumns as $srcColumn) { if ($beginning) { $beginning = false; } else { $sql .= ', '; } $columnAlias = $this->getSqlColumnAlias($srcColumn); $sql .= $sqlTableAlias . '.' . $srcColumn . ' AS ' . $columnAlias; $this->_rsm->addMetaResult($dqlAlias, $this->_platform->getSQLResultCasing($columnAlias), $srcColumn); } } } } } } } } } } return $sql; }
/** * Gets the (possibly quoted) primary table name of this class for safe use * in an SQL statement. * * @param AbstractPlatform $platform * @return string */ public function getQuotedTableName($platform) { return isset($this->table['quoted']) ? $platform->quoteIdentifier($this->table['name']) : $this->table['name']; }
/** * Enter description here... * * @param integer $level * @override */ protected function _getTransactionIsolationLevelSql($level) { switch ($level) { case Doctrine_DBAL_Connection::TRANSACTION_READ_UNCOMMITTED: case Doctrine_DBAL_Connection::TRANSACTION_READ_COMMITTED: return 'READ COMMITTED'; case Doctrine_DBAL_Connection::TRANSACTION_REPEATABLE_READ: case Doctrine_DBAL_Connection::TRANSACTION_SERIALIZABLE: return 'SERIALIZABLE'; default: return parent::_getTransactionIsolationLevelSql($level); } }
/** @override */ public function getDefaultLength(AbstractPlatform $platform) { return $platform->getVarcharDefaultLength(); }