本文整理汇总了PHP中Doctrine\ORM\Mapping\QuoteStrategy类的典型用法代码示例。如果您正苦于以下问题:PHP QuoteStrategy类的具体用法?PHP QuoteStrategy怎么用?PHP QuoteStrategy使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QuoteStrategy类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: getSqlForManyToOneAndOneToOneRelationsWithPropertyPath
/**
* @param DoctrineSqlFilter $sqlFilter
* @param QuoteStrategy $quoteStrategy
* @param ClassMetadata $targetEntity
* @param string $targetTableAlias
* @param string $targetEntityPropertyName
* @return string
* @throws InvalidQueryRewritingConstraintException
* @throws \Exception
*/
protected function getSqlForManyToOneAndOneToOneRelationsWithPropertyPath(DoctrineSqlFilter $sqlFilter, QuoteStrategy $quoteStrategy, ClassMetadata $targetEntity, $targetTableAlias, $targetEntityPropertyName)
{
$subselectQuery = $this->getSubselectQuery($targetEntity, $targetEntityPropertyName);
$associationMapping = $targetEntity->getAssociationMapping($targetEntityPropertyName);
$subselectConstraintQueries = array();
foreach ($associationMapping['joinColumns'] as $joinColumn) {
$rootAliases = $subselectQuery->getQueryBuilder()->getRootAliases();
$subselectQuery->getQueryBuilder()->select($rootAliases[0] . '.' . $targetEntity->getFieldForColumn($joinColumn['referencedColumnName']));
$subselectSql = $subselectQuery->getSql();
foreach ($subselectQuery->getParameters() as $parameter) {
$parameterValue = $parameter->getValue();
if (is_object($parameterValue)) {
$parameterValue = $this->persistenceManager->getIdentifierByObject($parameter->getValue());
}
$subselectSql = preg_replace('/\\?/', $this->entityManager->getConnection()->quote($parameterValue, $parameter->getType()), $subselectSql, 1);
}
$quotedColumnName = $quoteStrategy->getJoinColumnName($joinColumn, $targetEntity, $this->entityManager->getConnection()->getDatabasePlatform());
$subselectIdentifier = 'subselect' . md5($subselectSql);
$subselectConstraintQueries[] = $targetTableAlias . '.' . $quotedColumnName . ' IN (SELECT ' . $subselectIdentifier . '.' . $joinColumn['referencedColumnName'] . '0 FROM (' . $subselectSql . ') AS ' . $subselectIdentifier . ' ) ';
}
return ' (' . implode(' ) AND ( ', $subselectConstraintQueries) . ') ';
}
开发者ID:nlx-sascha,项目名称:flow-development-collection,代码行数:32,代码来源:PropertyConditionGenerator.php
示例2: _gatherRelationJoinColumns
/**
* Gather columns and fk constraints that are required for one part of relationship.
*
* @param array $joinColumns
* @param \Doctrine\DBAL\Schema\Table $theJoinTable
* @param ClassMetadata $class
* @param array $mapping
* @param array $primaryKeyColumns
* @param array $uniqueConstraints
*/
private function _gatherRelationJoinColumns($joinColumns, $theJoinTable, $class, $mapping, &$primaryKeyColumns, &$uniqueConstraints)
{
$localColumns = array();
$foreignColumns = array();
$fkOptions = array();
$foreignTableName = $this->quoteStrategy->getTableName($class, $this->platform);
foreach ($joinColumns as $joinColumn) {
list($definingClass, $referencedFieldName) = $this->getDefiningClass($class, $joinColumn['referencedColumnName']);
if (!$definingClass) {
throw new \Doctrine\ORM\ORMException("Column name `" . $joinColumn['referencedColumnName'] . "` referenced for relation from " . $mapping['sourceEntity'] . " towards " . $mapping['targetEntity'] . " does not exist.");
}
$quotedColumnName = $this->quoteStrategy->getJoinColumnName($joinColumn, $class, $this->platform);
$quotedRefColumnName = $this->quoteStrategy->getReferencedJoinColumnName($joinColumn, $class, $this->platform);
$primaryKeyColumns[] = $quotedColumnName;
$localColumns[] = $quotedColumnName;
$foreignColumns[] = $quotedRefColumnName;
if (!$theJoinTable->hasColumn($quotedColumnName)) {
// Only add the column to the table if it does not exist already.
// It might exist already if the foreign key is mapped into a regular
// property as well.
$fieldMapping = $definingClass->getFieldMapping($referencedFieldName);
$columnDef = null;
if (isset($joinColumn['columnDefinition'])) {
$columnDef = $joinColumn['columnDefinition'];
} else {
if (isset($fieldMapping['columnDefinition'])) {
$columnDef = $fieldMapping['columnDefinition'];
}
}
$columnOptions = array('notnull' => false, 'columnDefinition' => $columnDef);
if (isset($joinColumn['nullable'])) {
$columnOptions['notnull'] = !$joinColumn['nullable'];
}
if (isset($fieldMapping['options'])) {
$columnOptions['options'] = $fieldMapping['options'];
}
if ($fieldMapping['type'] == "string" && isset($fieldMapping['length'])) {
$columnOptions['length'] = $fieldMapping['length'];
} else {
if ($fieldMapping['type'] == "decimal") {
$columnOptions['scale'] = $fieldMapping['scale'];
$columnOptions['precision'] = $fieldMapping['precision'];
}
}
$theJoinTable->addColumn($quotedColumnName, $fieldMapping['type'], $columnOptions);
}
if (isset($joinColumn['unique']) && $joinColumn['unique'] == true) {
$uniqueConstraints[] = array('columns' => array($quotedColumnName));
}
if (isset($joinColumn['onDelete'])) {
$fkOptions['onDelete'] = $joinColumn['onDelete'];
}
}
$theJoinTable->addUnnamedForeignKeyConstraint($foreignTableName, $localColumns, $foreignColumns, $fkOptions);
}
开发者ID:Herriniaina,项目名称:iVarotra,代码行数:65,代码来源:SchemaTool.php
示例3: apply
/**
* Apply the ACL constraints to the specified query builder, using the permission definition
*
* @param QueryBuilder $queryBuilder The query builder
* @param PermissionDefinition $permissionDef The permission definition
*
* @return Query
*/
public function apply(QueryBuilder $queryBuilder, PermissionDefinition $permissionDef)
{
$whereQueryParts = $queryBuilder->getDQLPart('where');
if (empty($whereQueryParts)) {
$queryBuilder->where('1 = 1');
// this will help in cases where no where query is specified
}
$query = $this->cloneQuery($queryBuilder->getQuery());
$builder = new MaskBuilder();
foreach ($permissionDef->getPermissions() as $permission) {
$mask = constant(get_class($builder) . '::MASK_' . strtoupper($permission));
$builder->add($mask);
}
$query->setHint('acl.mask', $builder->get());
$query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Kunstmaan\\AdminBundle\\Helper\\Security\\Acl\\AclWalker');
$rootEntity = $permissionDef->getEntity();
$rootAlias = $permissionDef->getAlias();
// If either alias or entity was not specified - use default from QueryBuilder
if (empty($rootEntity) || empty($rootAlias)) {
$rootEntities = $queryBuilder->getRootEntities();
$rootAliases = $queryBuilder->getRootAliases();
$rootEntity = $rootEntities[0];
$rootAlias = $rootAliases[0];
}
$query->setHint('acl.root.entity', $rootEntity);
$query->setHint('acl.extra.query', $this->getPermittedAclIdsSQLForUser($query));
$classMeta = $this->em->getClassMetadata($rootEntity);
$entityRootTableName = $this->quoteStrategy->getTableName($classMeta, $this->em->getConnection()->getDatabasePlatform());
$query->setHint('acl.entityRootTableName', $entityRootTableName);
$query->setHint('acl.entityRootTableDqlAlias', $rootAlias);
return $query;
}
开发者ID:axelvnk,项目名称:KunstmaanBundlesCMS,代码行数:40,代码来源:AclHelper.php
示例4: getEntityHistory
public function getEntityHistory($className, $id)
{
if (!$this->metadataFactory->isAudited($className)) {
throw new NotAuditedException($className);
}
/** @var ClassMetadataInfo|ClassMetadata $class */
$class = $this->em->getClassMetadata($className);
$tableName = $this->config->getTableName($class);
if (!is_array($id)) {
$id = array($class->identifier[0] => $id);
}
$whereId = array();
foreach ($class->identifier as $idField) {
if (isset($class->fieldMappings[$idField])) {
$columnName = $class->fieldMappings[$idField]['columnName'];
} else {
if (isset($class->associationMappings[$idField])) {
$columnName = $class->associationMappings[$idField]['joinColumns'][0];
} else {
continue;
}
}
$whereId[] = "{$columnName} = ?";
}
$whereSQL = implode(' AND ', $whereId);
$columnList = array($this->config->getRevisionFieldName());
$columnMap = array();
foreach ($class->fieldNames as $columnName => $field) {
$type = Type::getType($class->fieldMappings[$field]['type']);
$columnList[] = $type->convertToPHPValueSQL($this->quoteStrategy->getColumnName($field, $class, $this->platform), $this->platform) . ' AS ' . $this->platform->quoteSingleIdentifier($field);
$columnMap[$field] = $this->platform->getSQLResultCasing($columnName);
}
foreach ($class->associationMappings as $assoc) {
if (($assoc['type'] & ClassMetadata::TO_ONE) == 0 || !$assoc['isOwningSide']) {
continue;
}
foreach ($assoc['targetToSourceKeyColumns'] as $sourceCol) {
$columnList[] = $sourceCol;
$columnMap[$sourceCol] = $this->platform->getSQLResultCasing($sourceCol);
}
}
$values = array_values($id);
$query = "SELECT " . implode(', ', $columnList) . " FROM " . $tableName . " e WHERE " . $whereSQL . " ORDER BY e.rev DESC";
$stmt = $this->em->getConnection()->executeQuery($query, $values);
$result = array();
while ($row = $stmt->fetch(Query::HYDRATE_ARRAY)) {
$rev = $row[$this->config->getRevisionFieldName()];
unset($row[$this->config->getRevisionFieldName()]);
$result[] = $this->createEntity($class->name, $columnMap, $row, $rev);
}
return $result;
}
开发者ID:Soullivaneuh,项目名称:EntityAudit,代码行数:52,代码来源:AuditReader.php
示例5: getUniqueAndRequiredAssociations
private function getUniqueAndRequiredAssociations(ClassMetadata $meta, $entity)
{
$associations = array();
foreach ($meta->getAssociationNames() as $associationName) {
$mapping = $meta->getAssociationMapping($associationName);
if (!empty($mapping['id']) && $meta->usesIdGenerator()) {
// autogenerated id
continue;
}
if (!($mapping['type'] & ClassMetadata::TO_ONE)) {
// is not to one relation
continue;
}
if (empty($mapping['isOwningSide'])) {
// is not owning side
continue;
}
foreach ($mapping['joinColumns'] as $joinColumn) {
if (!empty($joinColumn['nullable']) && empty($joinColumn['unique'])) {
// is nullable and is not unique
continue;
}
$targetColumn = $joinColumn['referencedColumnName'];
$targetClass = $this->em->getClassMetadata($mapping['targetEntity']);
$newVal = $meta->getFieldValue($entity, $associationName);
if ($newVal !== NULL) {
$newValId = $this->uow->getEntityIdentifier($newVal);
}
switch (TRUE) {
case $newVal === NULL:
$value = NULL;
break;
case $targetClass->containsForeignIdentifier:
$value = $newValId[$targetClass->getFieldForColumn($targetColumn)];
break;
default:
$value = $newValId[$targetClass->fieldNames[$targetColumn]];
break;
}
$sourceColumn = $joinColumn['name'];
$quotedColumn = $this->quotes->getJoinColumnName($joinColumn, $meta, $this->platform);
$associations[$sourceColumn]['value'] = $value;
$associations[$sourceColumn]['quotedColumn'] = $quotedColumn;
$associations[$sourceColumn]['type'] = $targetClass->getTypeOfColumn($targetColumn);
}
}
return $associations;
}
开发者ID:peterkrejci,项目名称:music-collection,代码行数:48,代码来源:NonLockingUniqueInserter.php
示例6: rebuildOrderByClauseForOuterScope
/**
* Generates a new order by clause that works in the scope of a select query wrapping the original
*
* @param OrderByClause $orderByClause
* @return array
*/
private function rebuildOrderByClauseForOuterScope(OrderByClause $orderByClause)
{
$dqlAliasToSqlTableAliasMap = $searchPatterns = $replacements = $dqlAliasToClassMap = $selectListAdditions = $orderByItems = [];
// Generate DQL alias -> SQL table alias mapping
foreach (array_keys($this->rsm->aliasMap) as $dqlAlias) {
$dqlAliasToClassMap[$dqlAlias] = $class = $this->queryComponents[$dqlAlias]['metadata'];
$dqlAliasToSqlTableAliasMap[$dqlAlias] = $this->getSQLTableAlias($class->getTableName(), $dqlAlias);
}
// Pattern to find table path expressions in the order by clause
$fieldSearchPattern = '/(?<![a-z0-9_])%s\\.%s(?![a-z0-9_])/i';
// Generate search patterns for each field's path expression in the order by clause
foreach ($this->rsm->fieldMappings as $fieldAlias => $fieldName) {
$dqlAliasForFieldAlias = $this->rsm->columnOwnerMap[$fieldAlias];
$class = $dqlAliasToClassMap[$dqlAliasForFieldAlias];
// If the field is from a joined child table, we won't be ordering
// on it.
if (!isset($class->fieldMappings[$fieldName])) {
continue;
}
$fieldMapping = $class->fieldMappings[$fieldName];
// Get the proper column name as will appear in the select list
$columnName = $this->quoteStrategy->getColumnName($fieldName, $dqlAliasToClassMap[$dqlAliasForFieldAlias], $this->em->getConnection()->getDatabasePlatform());
// Get the SQL table alias for the entity and field
$sqlTableAliasForFieldAlias = $dqlAliasToSqlTableAliasMap[$dqlAliasForFieldAlias];
if (isset($fieldMapping['declared']) && $fieldMapping['declared'] !== $class->name) {
// Field was declared in a parent class, so we need to get the proper SQL table alias
// for the joined parent table.
$otherClassMetadata = $this->em->getClassMetadata($fieldMapping['declared']);
if (!$otherClassMetadata->isMappedSuperclass) {
$sqlTableAliasForFieldAlias = $this->getSQLTableAlias($otherClassMetadata->getTableName(), $dqlAliasForFieldAlias);
}
}
// Compose search/replace patterns
$searchPatterns[] = sprintf($fieldSearchPattern, $sqlTableAliasForFieldAlias, $columnName);
$replacements[] = $fieldAlias;
}
foreach ($orderByClause->orderByItems as $orderByItem) {
// Walk order by item to get string representation of it
$orderByItemString = $this->walkOrderByItem($orderByItem);
// Replace path expressions in the order by clause with their column alias
$orderByItemString = preg_replace($searchPatterns, $replacements, $orderByItemString);
$orderByItems[] = $orderByItemString;
}
return $orderByItems;
}
开发者ID:AlexanderForks,项目名称:doctrine2,代码行数:51,代码来源:LimitSubqueryOutputWalker.php
示例7: rebuildOrderByClauseForOuterScope
/**
* Generates a new order by clause that works in the scope of a select query wrapping the original
*
* @param OrderByClause $orderByClause
* @return array
*/
private function rebuildOrderByClauseForOuterScope(OrderByClause $orderByClause)
{
$dqlAliasToSqlTableAliasMap = $searchPatterns = $replacements = $dqlAliasToClassMap = $selectListAdditions = $orderByItems = [];
// Generate DQL alias -> SQL table alias mapping
foreach (array_keys($this->rsm->aliasMap) as $dqlAlias) {
$dqlAliasToClassMap[$dqlAlias] = $class = $this->queryComponents[$dqlAlias]['metadata'];
$dqlAliasToSqlTableAliasMap[$dqlAlias] = $this->getSQLTableAlias($class->getTableName(), $dqlAlias);
}
// Pattern to find table path expressions in the order by clause
$fieldSearchPattern = '/(?<![a-z0-9_])%s\\.%s(?![a-z0-9_])/i';
// Generate search patterns for each field's path expression in the order by clause
foreach ($this->rsm->fieldMappings as $fieldAlias => $columnName) {
$dqlAliasForFieldAlias = $this->rsm->columnOwnerMap[$fieldAlias];
$columnName = $this->quoteStrategy->getColumnName($columnName, $dqlAliasToClassMap[$dqlAliasForFieldAlias], $this->em->getConnection()->getDatabasePlatform());
$sqlTableAliasForFieldAlias = $dqlAliasToSqlTableAliasMap[$dqlAliasForFieldAlias];
$searchPatterns[] = sprintf($fieldSearchPattern, $sqlTableAliasForFieldAlias, $columnName);
$replacements[] = $fieldAlias;
}
$complexAddedOrderByAliases = 0;
foreach ($orderByClause->orderByItems as $orderByItem) {
// Walk order by item to get string representation of it
$orderByItemString = $this->walkOrderByItem($orderByItem);
// Replace path expressions in the order by clause with their column alias
$orderByItemString = preg_replace($searchPatterns, $replacements, $orderByItemString);
// The order by items are not required to be in the select list on Oracle and PostgreSQL, but
// for the sake of simplicity, order by items will be included in the select list on all platforms.
// This doesn't impact functionality.
$selectListAddition = trim(preg_replace('/([^ ]+) (?:asc|desc)/i', '$1', $orderByItemString));
// If the expression is an arithmetic expression, we need to create an alias for it.
if ($orderByItem->expression instanceof ArithmeticTerm) {
$orderByAlias = "ordr_" . $complexAddedOrderByAliases++;
$orderByItemString = $orderByAlias . " " . $orderByItem->type;
$selectListAddition .= " AS {$orderByAlias}";
}
$selectListAdditions[] = $selectListAddition;
$orderByItems[] = $orderByItemString;
}
return array($selectListAdditions, $orderByItems);
}
开发者ID:ismael-rivera,项目名称:project-manati,代码行数:45,代码来源:LimitSubqueryOutputWalker.php
示例8: getInsertRevisionSQL
/**
* @param ClassMetadata $class
*
* @return string
* @throws \Doctrine\DBAL\DBALException
*/
private function getInsertRevisionSQL($class)
{
if (!isset($this->insertRevisionSQL[$class->name])) {
$placeholders = array('?', '?');
$tableName = $this->config->getTableName($class);
$sql = "INSERT INTO " . $tableName . " (" . $this->config->getRevisionFieldName() . ", " . $this->config->getRevisionTypeFieldName();
$fields = array();
foreach ($class->associationMappings as $field => $assoc) {
if ($class->isInheritanceTypeJoined() && $class->isInheritedAssociation($field)) {
continue;
}
if (($assoc['type'] & ClassMetadata::TO_ONE) > 0 && $assoc['isOwningSide']) {
foreach ($assoc['targetToSourceKeyColumns'] as $sourceCol) {
$fields[$sourceCol] = true;
$sql .= ', ' . $sourceCol;
$placeholders[] = '?';
}
}
}
foreach ($class->fieldNames as $field) {
if (array_key_exists($field, $fields)) {
continue;
}
if ($class->isInheritanceTypeJoined() && $class->isInheritedField($field) && !$class->isIdentifier($field)) {
continue;
}
$type = Type::getType($class->fieldMappings[$field]['type']);
$placeholders[] = !empty($class->fieldMappings[$field]['requireSQLConversion']) ? $type->convertToDatabaseValueSQL('?', $this->platform) : '?';
$sql .= ', ' . $this->quoteStrategy->getColumnName($field, $class, $this->platform);
}
if ($class->isInheritanceTypeJoined() && $class->rootEntityName == $class->name || $class->isInheritanceTypeSingleTable()) {
$sql .= ', ' . $class->discriminatorColumn['name'];
$placeholders[] = '?';
}
$sql .= ") VALUES (" . implode(", ", $placeholders) . ")";
$this->insertRevisionSQL[$class->name] = $sql;
}
return $this->insertRevisionSQL[$class->name];
}
开发者ID:Soullivaneuh,项目名称:EntityAudit,代码行数:45,代码来源:LogRevisionsListener.php
示例9: walkCollectionMemberExpression
/**
* {@inheritdoc}
*/
public function walkCollectionMemberExpression($collMemberExpr)
{
$sql = $collMemberExpr->not ? 'NOT ' : '';
$sql .= 'EXISTS (SELECT 1 FROM ';
$entityExpr = $collMemberExpr->entityExpression;
$collPathExpr = $collMemberExpr->collectionValuedPathExpression;
$fieldName = $collPathExpr->field;
$dqlAlias = $collPathExpr->identificationVariable;
$class = $this->queryComponents[$dqlAlias]['metadata'];
switch (true) {
// InputParameter
case $entityExpr instanceof AST\InputParameter:
$dqlParamKey = $entityExpr->name;
$entitySql = '?';
break;
// SingleValuedAssociationPathExpression | IdentificationVariable
// SingleValuedAssociationPathExpression | IdentificationVariable
case $entityExpr instanceof AST\PathExpression:
$entitySql = $this->walkPathExpression($entityExpr);
break;
default:
throw new \BadMethodCallException("Not implemented");
}
$assoc = $class->associationMappings[$fieldName];
if ($assoc['type'] == ClassMetadata::ONE_TO_MANY) {
$targetClass = $this->em->getClassMetadata($assoc['targetEntity']);
$targetTableAlias = $this->getSQLTableAlias($targetClass->getTableName());
$sourceTableAlias = $this->getSQLTableAlias($class->getTableName(), $dqlAlias);
$sql .= $this->quoteStrategy->getTableName($targetClass, $this->platform) . ' ' . $targetTableAlias . ' WHERE ';
$owningAssoc = $targetClass->associationMappings[$assoc['mappedBy']];
$sqlParts = array();
foreach ($owningAssoc['targetToSourceKeyColumns'] as $targetColumn => $sourceColumn) {
$targetColumn = $this->quoteStrategy->getColumnName($class->fieldNames[$targetColumn], $class, $this->platform);
$sqlParts[] = $sourceTableAlias . '.' . $targetColumn . ' = ' . $targetTableAlias . '.' . $sourceColumn;
}
foreach ($this->quoteStrategy->getIdentifierColumnNames($targetClass, $this->platform) as $targetColumnName) {
if (isset($dqlParamKey)) {
$this->parserResult->addParameterMapping($dqlParamKey, $this->sqlParamIndex++);
}
$sqlParts[] = $targetTableAlias . '.' . $targetColumnName . ' = ' . $entitySql;
}
$sql .= implode(' AND ', $sqlParts);
} else {
// many-to-many
$targetClass = $this->em->getClassMetadata($assoc['targetEntity']);
$owningAssoc = $assoc['isOwningSide'] ? $assoc : $targetClass->associationMappings[$assoc['mappedBy']];
$joinTable = $owningAssoc['joinTable'];
// SQL table aliases
$joinTableAlias = $this->getSQLTableAlias($joinTable['name']);
$targetTableAlias = $this->getSQLTableAlias($targetClass->getTableName());
$sourceTableAlias = $this->getSQLTableAlias($class->getTableName(), $dqlAlias);
// join to target table
$sql .= $this->quoteStrategy->getJoinTableName($owningAssoc, $targetClass, $this->platform) . ' ' . $joinTableAlias . ' INNER JOIN ' . $this->quoteStrategy->getTableName($targetClass, $this->platform) . ' ' . $targetTableAlias . ' ON ';
// join conditions
$joinColumns = $assoc['isOwningSide'] ? $joinTable['inverseJoinColumns'] : $joinTable['joinColumns'];
$joinSqlParts = array();
foreach ($joinColumns as $joinColumn) {
$targetColumn = $this->quoteStrategy->getColumnName($targetClass->fieldNames[$joinColumn['referencedColumnName']], $targetClass, $this->platform);
$joinSqlParts[] = $joinTableAlias . '.' . $joinColumn['name'] . ' = ' . $targetTableAlias . '.' . $targetColumn;
}
$sql .= implode(' AND ', $joinSqlParts);
$sql .= ' WHERE ';
$joinColumns = $assoc['isOwningSide'] ? $joinTable['joinColumns'] : $joinTable['inverseJoinColumns'];
$sqlParts = array();
foreach ($joinColumns as $joinColumn) {
$targetColumn = $this->quoteStrategy->getColumnName($class->fieldNames[$joinColumn['referencedColumnName']], $class, $this->platform);
$sqlParts[] = $joinTableAlias . '.' . $joinColumn['name'] . ' = ' . $sourceTableAlias . '.' . $targetColumn;
}
foreach ($this->quoteStrategy->getIdentifierColumnNames($targetClass, $this->platform) as $targetColumnName) {
if (isset($dqlParamKey)) {
$this->parserResult->addParameterMapping($dqlParamKey, $this->sqlParamIndex++);
}
$sqlParts[] = $targetTableAlias . '.' . $targetColumnName . ' = ' . $entitySql;
}
$sql .= implode(' AND ', $sqlParts);
}
return $sql . ')';
}
开发者ID:nemekzg,项目名称:doctrine2,代码行数:81,代码来源:SqlWalker.php
示例10: getSQLColumnAlias
/**
* Gets an SQL column alias for a column name.
*
* @param string $columnName
*
* @return string
*/
public function getSQLColumnAlias($columnName)
{
return $this->quoteStrategy->getColumnAlias($columnName, $this->sqlAliasCounter++, $this->platform);
}
开发者ID:nattaphat,项目名称:hgis,代码行数:11,代码来源:BasicEntityPersister.php
示例11: gatherRelationJoinColumns
/**
* Gathers columns and fk constraints that are required for one part of relationship.
*
* @param array $joinColumns
* @param Table $theJoinTable
* @param ClassMetadata $class
* @param array $mapping
* @param array $primaryKeyColumns
* @param array $addedFks
* @param array $blacklistedFks
*
* @return void
*
* @throws \Doctrine\ORM\ORMException
*/
private function gatherRelationJoinColumns($joinColumns, $theJoinTable, $class, $mapping, &$primaryKeyColumns, &$addedFks, &$blacklistedFks)
{
$localColumns = array();
$foreignColumns = array();
$fkOptions = array();
$foreignTableName = $this->quoteStrategy->getTableName($class, $this->platform);
$uniqueConstraints = array();
foreach ($joinColumns as $joinColumn) {
list($definingClass, $referencedFieldName) = $this->getDefiningClass($class, $joinColumn['referencedColumnName']);
if (!$definingClass) {
throw new \Doctrine\ORM\ORMException("Column name `" . $joinColumn['referencedColumnName'] . "` referenced for relation from " . $mapping['sourceEntity'] . " towards " . $mapping['targetEntity'] . " does not exist.");
}
$quotedColumnName = $this->quoteStrategy->getJoinColumnName($joinColumn, $class, $this->platform);
$quotedRefColumnName = $this->quoteStrategy->getReferencedJoinColumnName($joinColumn, $class, $this->platform);
$primaryKeyColumns[] = $quotedColumnName;
$localColumns[] = $quotedColumnName;
$foreignColumns[] = $quotedRefColumnName;
if (!$theJoinTable->hasColumn($quotedColumnName)) {
// Only add the column to the table if it does not exist already.
// It might exist already if the foreign key is mapped into a regular
// property as well.
$fieldMapping = $definingClass->getFieldMapping($referencedFieldName);
$columnDef = null;
if (isset($joinColumn['columnDefinition'])) {
$columnDef = $joinColumn['columnDefinition'];
} elseif (isset($fieldMapping['columnDefinition'])) {
$columnDef = $fieldMapping['columnDefinition'];
}
$columnOptions = array('notnull' => false, 'columnDefinition' => $columnDef);
if (isset($joinColumn['nullable'])) {
$columnOptions['notnull'] = !$joinColumn['nullable'];
}
if (isset($fieldMapping['options'])) {
$columnOptions['options'] = $fieldMapping['options'];
}
if ($fieldMapping['type'] == "string" && isset($fieldMapping['length'])) {
$columnOptions['length'] = $fieldMapping['length'];
} elseif ($fieldMapping['type'] == "decimal") {
$columnOptions['scale'] = $fieldMapping['scale'];
$columnOptions['precision'] = $fieldMapping['precision'];
}
$theJoinTable->addColumn($quotedColumnName, $fieldMapping['type'], $columnOptions);
}
if (isset($joinColumn['unique']) && $joinColumn['unique'] == true) {
$uniqueConstraints[] = array('columns' => array($quotedColumnName));
}
if (isset($joinColumn['onDelete'])) {
$fkOptions['onDelete'] = $joinColumn['onDelete'];
}
}
// Prefer unique constraints over implicit simple indexes created for foreign keys.
// Also avoids index duplication.
foreach ($uniqueConstraints as $indexName => $unique) {
$theJoinTable->addUniqueIndex($unique['columns'], is_numeric($indexName) ? null : $indexName);
}
$compositeName = $theJoinTable->getName() . '.' . implode('', $localColumns);
if (isset($addedFks[$compositeName]) && ($foreignTableName != $addedFks[$compositeName]['foreignTableName'] || 0 < count(array_diff($foreignColumns, $addedFks[$compositeName]['foreignColumns'])))) {
foreach ($theJoinTable->getForeignKeys() as $fkName => $key) {
if (0 === count(array_diff($key->getLocalColumns(), $localColumns)) && ($key->getForeignTableName() != $foreignTableName || 0 < count(array_diff($key->getForeignColumns(), $foreignColumns)))) {
$theJoinTable->removeForeignKey($fkName);
break;
}
}
$blacklistedFks[$compositeName] = true;
} elseif (!isset($blacklistedFks[$compositeName])) {
$addedFks[$compositeName] = array('foreignTableName' => $foreignTableName, 'foreignColumns' => $foreignColumns);
$theJoinTable->addUnnamedForeignKeyConstraint($foreignTableName, $localColumns, $foreignColumns, $fkOptions);
}
}
开发者ID:BozzaCoon,项目名称:SPHERE-Framework,代码行数:84,代码来源:SchemaTool.php
示例12: getLockTablesSql
/**
* Gets the FROM and optionally JOIN conditions to lock the entity managed by this persister.
*
* @param integer $lockMode One of the Doctrine\DBAL\LockMode::* constants.
*
* @return string
*/
protected function getLockTablesSql($lockMode)
{
return $this->platform->appendLockHint('FROM ' . $this->quoteStrategy->getTableName($this->class, $this->platform) . ' ' . $this->getSQLTableAlias($this->class->name), $lockMode);
}
开发者ID:BozzaCoon,项目名称:SPHERE-Framework,代码行数:11,代码来源:BasicEntityPersister.php
注:本文中的Doctrine\ORM\Mapping\QuoteStrategy类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论