Complex classes like SqlWalker often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use SqlWalker, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 42 | class SqlWalker implements TreeWalker |
||
| 43 | { |
||
| 44 | /** |
||
| 45 | * @var string |
||
| 46 | */ |
||
| 47 | const HINT_DISTINCT = 'doctrine.distinct'; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @var ResultSetMapping |
||
| 51 | */ |
||
| 52 | private $rsm; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * Counter for generating unique column aliases. |
||
| 56 | * |
||
| 57 | * @var integer |
||
| 58 | */ |
||
| 59 | private $aliasCounter = 0; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Counter for generating unique table aliases. |
||
| 63 | * |
||
| 64 | * @var integer |
||
| 65 | */ |
||
| 66 | private $tableAliasCounter = 0; |
||
| 67 | |||
| 68 | /** |
||
| 69 | * Counter for generating unique scalar result. |
||
| 70 | * |
||
| 71 | * @var integer |
||
| 72 | */ |
||
| 73 | private $scalarResultCounter = 1; |
||
| 74 | |||
| 75 | /** |
||
| 76 | * Counter for generating unique parameter indexes. |
||
| 77 | * |
||
| 78 | * @var integer |
||
| 79 | */ |
||
| 80 | private $sqlParamIndex = 0; |
||
| 81 | |||
| 82 | /** |
||
| 83 | * Counter for generating indexes. |
||
| 84 | * |
||
| 85 | * @var integer |
||
| 86 | */ |
||
| 87 | private $newObjectCounter = 0; |
||
| 88 | |||
| 89 | /** |
||
| 90 | * @var ParserResult |
||
| 91 | */ |
||
| 92 | private $parserResult; |
||
| 93 | |||
| 94 | /** |
||
| 95 | * @var \Doctrine\ORM\EntityManager |
||
| 96 | */ |
||
| 97 | private $em; |
||
| 98 | |||
| 99 | /** |
||
| 100 | * @var \Doctrine\DBAL\Connection |
||
| 101 | */ |
||
| 102 | private $conn; |
||
| 103 | |||
| 104 | /** |
||
| 105 | * @var \Doctrine\ORM\AbstractQuery |
||
| 106 | */ |
||
| 107 | private $query; |
||
| 108 | |||
| 109 | /** |
||
| 110 | * @var array |
||
| 111 | */ |
||
| 112 | private $tableAliasMap = []; |
||
| 113 | |||
| 114 | /** |
||
| 115 | * Map from result variable names to their SQL column alias names. |
||
| 116 | * |
||
| 117 | * @var array |
||
| 118 | */ |
||
| 119 | private $scalarResultAliasMap = []; |
||
| 120 | |||
| 121 | /** |
||
| 122 | * Map from Table-Alias + Column-Name to OrderBy-Direction. |
||
| 123 | * |
||
| 124 | * @var array |
||
| 125 | */ |
||
| 126 | private $orderedColumnsMap = []; |
||
| 127 | |||
| 128 | /** |
||
| 129 | * Map from DQL-Alias + Field-Name to SQL Column Alias. |
||
| 130 | * |
||
| 131 | * @var array |
||
| 132 | */ |
||
| 133 | private $scalarFields = []; |
||
| 134 | |||
| 135 | /** |
||
| 136 | * Map of all components/classes that appear in the DQL query. |
||
| 137 | * |
||
| 138 | * @var array |
||
| 139 | */ |
||
| 140 | private $queryComponents; |
||
| 141 | |||
| 142 | /** |
||
| 143 | * A list of classes that appear in non-scalar SelectExpressions. |
||
| 144 | * |
||
| 145 | * @var array |
||
| 146 | */ |
||
| 147 | private $selectedClasses = []; |
||
| 148 | |||
| 149 | /** |
||
| 150 | * The DQL alias of the root class of the currently traversed query. |
||
| 151 | * |
||
| 152 | * @var array |
||
| 153 | */ |
||
| 154 | private $rootAliases = []; |
||
| 155 | |||
| 156 | /** |
||
| 157 | * Flag that indicates whether to generate SQL table aliases in the SQL. |
||
| 158 | * These should only be generated for SELECT queries, not for UPDATE/DELETE. |
||
| 159 | * |
||
| 160 | * @var boolean |
||
| 161 | */ |
||
| 162 | private $useSqlTableAliases = true; |
||
| 163 | |||
| 164 | /** |
||
| 165 | * The database platform abstraction. |
||
| 166 | * |
||
| 167 | * @var \Doctrine\DBAL\Platforms\AbstractPlatform |
||
| 168 | */ |
||
| 169 | private $platform; |
||
| 170 | |||
| 171 | /** |
||
| 172 | * The quote strategy. |
||
| 173 | * |
||
| 174 | * @var \Doctrine\ORM\Mapping\QuoteStrategy |
||
| 175 | */ |
||
| 176 | private $quoteStrategy; |
||
| 177 | |||
| 178 | /** |
||
| 179 | * {@inheritDoc} |
||
| 180 | */ |
||
| 181 | 362 | public function __construct($query, $parserResult, array $queryComponents) |
|
| 192 | |||
| 193 | /** |
||
| 194 | * Gets the Query instance used by the walker. |
||
| 195 | * |
||
| 196 | * @return Query. |
||
|
|
|||
| 197 | */ |
||
| 198 | public function getQuery() |
||
| 202 | |||
| 203 | /** |
||
| 204 | * Gets the Connection used by the walker. |
||
| 205 | * |
||
| 206 | * @return \Doctrine\DBAL\Connection |
||
| 207 | */ |
||
| 208 | 18 | public function getConnection() |
|
| 212 | |||
| 213 | /** |
||
| 214 | * Gets the EntityManager used by the walker. |
||
| 215 | * |
||
| 216 | * @return \Doctrine\ORM\EntityManager |
||
| 217 | */ |
||
| 218 | 15 | public function getEntityManager() |
|
| 222 | |||
| 223 | /** |
||
| 224 | * Gets the information about a single query component. |
||
| 225 | * |
||
| 226 | * @param string $dqlAlias The DQL alias. |
||
| 227 | * |
||
| 228 | * @return array |
||
| 229 | */ |
||
| 230 | 15 | public function getQueryComponent($dqlAlias) |
|
| 234 | |||
| 235 | /** |
||
| 236 | * {@inheritdoc} |
||
| 237 | */ |
||
| 238 | public function getQueryComponents() |
||
| 242 | |||
| 243 | /** |
||
| 244 | * {@inheritdoc} |
||
| 245 | */ |
||
| 246 | 1 | public function setQueryComponent($dqlAlias, array $queryComponent) |
|
| 256 | |||
| 257 | /** |
||
| 258 | * {@inheritdoc} |
||
| 259 | */ |
||
| 260 | 356 | public function getExecutor($AST) |
|
| 261 | { |
||
| 262 | switch (true) { |
||
| 263 | 356 | case ($AST instanceof AST\DeleteStatement): |
|
| 264 | 30 | $primaryClass = $this->em->getClassMetadata($AST->deleteClause->abstractSchemaName); |
|
| 265 | |||
| 266 | 30 | return ($primaryClass->isInheritanceTypeJoined()) |
|
| 267 | ? new Exec\MultiTableDeleteExecutor($AST, $this) |
||
| 268 | 30 | : new Exec\SingleTableDeleteUpdateExecutor($AST, $this); |
|
| 269 | |||
| 270 | 305 | case ($AST instanceof AST\UpdateStatement): |
|
| 271 | 21 | $primaryClass = $this->em->getClassMetadata($AST->updateClause->abstractSchemaName); |
|
| 272 | |||
| 273 | 21 | return ($primaryClass->isInheritanceTypeJoined()) |
|
| 274 | ? new Exec\MultiTableUpdateExecutor($AST, $this) |
||
| 275 | 21 | : new Exec\SingleTableDeleteUpdateExecutor($AST, $this); |
|
| 276 | |||
| 277 | default: |
||
| 278 | 305 | return new Exec\SingleSelectExecutor($AST, $this); |
|
| 279 | } |
||
| 280 | } |
||
| 281 | |||
| 282 | /** |
||
| 283 | * Generates a unique, short SQL table alias. |
||
| 284 | * |
||
| 285 | * @param string $tableName Table name |
||
| 286 | * @param string $dqlAlias The DQL alias. |
||
| 287 | * |
||
| 288 | * @return string Generated table alias. |
||
| 289 | */ |
||
| 290 | 314 | public function getSQLTableAlias($tableName, $dqlAlias = '') |
|
| 301 | |||
| 302 | /** |
||
| 303 | * Forces the SqlWalker to use a specific alias for a table name, rather than |
||
| 304 | * generating an alias on its own. |
||
| 305 | * |
||
| 306 | * @param string $tableName |
||
| 307 | * @param string $alias |
||
| 308 | * @param string $dqlAlias |
||
| 309 | * |
||
| 310 | * @return string |
||
| 311 | */ |
||
| 312 | 51 | public function setSQLTableAlias($tableName, $alias, $dqlAlias = '') |
|
| 320 | |||
| 321 | /** |
||
| 322 | * Gets an SQL column alias for a column name. |
||
| 323 | * |
||
| 324 | * @param string $columnName |
||
| 325 | * |
||
| 326 | * @return string |
||
| 327 | */ |
||
| 328 | 305 | public function getSQLColumnAlias($columnName) |
|
| 332 | |||
| 333 | /** |
||
| 334 | * Generates the SQL JOINs that are necessary for Class Table Inheritance |
||
| 335 | * for the given class. |
||
| 336 | * |
||
| 337 | * @param ClassMetadata $class The class for which to generate the joins. |
||
| 338 | * @param string $dqlAlias The DQL alias of the class. |
||
| 339 | * |
||
| 340 | * @return string The SQL. |
||
| 341 | */ |
||
| 342 | 38 | private function _generateClassTableInheritanceJoins($class, $dqlAlias) |
|
| 343 | { |
||
| 344 | 38 | $sql = ''; |
|
| 345 | |||
| 346 | 38 | $baseTableAlias = $this->getSQLTableAlias($class->getTableName(), $dqlAlias); |
|
| 347 | |||
| 348 | // INNER JOIN parent class tables |
||
| 349 | 38 | foreach ($class->parentClasses as $parentClassName) { |
|
| 350 | 23 | $parentClass = $this->em->getClassMetadata($parentClassName); |
|
| 351 | 23 | $tableAlias = $this->getSQLTableAlias($parentClass->getTableName(), $dqlAlias); |
|
| 352 | |||
| 353 | // If this is a joined association we must use left joins to preserve the correct result. |
||
| 354 | 23 | $sql .= isset($this->queryComponents[$dqlAlias]['relation']) ? ' LEFT ' : ' INNER '; |
|
| 355 | 23 | $sql .= 'JOIN ' . $this->quoteStrategy->getTableName($parentClass, $this->platform) . ' ' . $tableAlias . ' ON '; |
|
| 356 | |||
| 357 | 23 | $sqlParts = []; |
|
| 358 | |||
| 359 | 23 | foreach ($this->quoteStrategy->getIdentifierColumnNames($class, $this->platform) as $columnName) { |
|
| 360 | 23 | $sqlParts[] = $baseTableAlias . '.' . $columnName . ' = ' . $tableAlias . '.' . $columnName; |
|
| 361 | } |
||
| 362 | |||
| 363 | // Add filters on the root class |
||
| 364 | 23 | if ($filterSql = $this->generateFilterConditionSQL($parentClass, $tableAlias)) { |
|
| 365 | $sqlParts[] = $filterSql; |
||
| 366 | } |
||
| 367 | |||
| 368 | 23 | $sql .= implode(' AND ', $sqlParts); |
|
| 369 | } |
||
| 370 | |||
| 371 | // Ignore subclassing inclusion if partial objects is disallowed |
||
| 372 | 38 | if ($this->query->getHint(Query::HINT_FORCE_PARTIAL_LOAD)) { |
|
| 373 | 21 | return $sql; |
|
| 374 | } |
||
| 375 | |||
| 376 | // LEFT JOIN child class tables |
||
| 377 | 17 | foreach ($class->subClasses as $subClassName) { |
|
| 378 | 11 | $subClass = $this->em->getClassMetadata($subClassName); |
|
| 379 | 11 | $tableAlias = $this->getSQLTableAlias($subClass->getTableName(), $dqlAlias); |
|
| 380 | |||
| 381 | 11 | $sql .= ' LEFT JOIN ' . $this->quoteStrategy->getTableName($subClass, $this->platform) . ' ' . $tableAlias . ' ON '; |
|
| 382 | |||
| 383 | 11 | $sqlParts = []; |
|
| 384 | |||
| 385 | 11 | foreach ($this->quoteStrategy->getIdentifierColumnNames($subClass, $this->platform) as $columnName) { |
|
| 386 | 11 | $sqlParts[] = $baseTableAlias . '.' . $columnName . ' = ' . $tableAlias . '.' . $columnName; |
|
| 387 | } |
||
| 388 | |||
| 389 | 11 | $sql .= implode(' AND ', $sqlParts); |
|
| 390 | } |
||
| 391 | |||
| 392 | 17 | return $sql; |
|
| 393 | } |
||
| 394 | |||
| 395 | /** |
||
| 396 | * @return string |
||
| 397 | */ |
||
| 398 | 298 | private function _generateOrderedCollectionOrderByItems() |
|
| 399 | { |
||
| 400 | 298 | $orderedColumns = []; |
|
| 401 | |||
| 402 | 298 | foreach ($this->selectedClasses as $selectedClass) { |
|
| 403 | 214 | $dqlAlias = $selectedClass['dqlAlias']; |
|
| 404 | 214 | $qComp = $this->queryComponents[$dqlAlias]; |
|
| 405 | |||
| 406 | 214 | if ( ! isset($qComp['relation']['orderBy'])) { |
|
| 407 | 214 | continue; |
|
| 408 | } |
||
| 409 | |||
| 410 | 2 | $persister = $this->em->getUnitOfWork()->getEntityPersister($qComp['metadata']->name); |
|
| 411 | |||
| 412 | 2 | foreach ($qComp['relation']['orderBy'] as $fieldName => $orientation) { |
|
| 413 | 2 | $columnName = $this->quoteStrategy->getColumnName($fieldName, $qComp['metadata'], $this->platform); |
|
| 414 | 2 | $tableName = ($qComp['metadata']->isInheritanceTypeJoined()) |
|
| 415 | ? $persister->getOwningTable($fieldName) |
||
| 416 | 2 | : $qComp['metadata']->getTableName(); |
|
| 417 | |||
| 418 | 2 | $orderedColumn = $this->getSQLTableAlias($tableName, $dqlAlias) . '.' . $columnName; |
|
| 419 | |||
| 420 | // OrderByClause should replace an ordered relation. see - DDC-2475 |
||
| 421 | 2 | if (isset($this->orderedColumnsMap[$orderedColumn])) { |
|
| 422 | 1 | continue; |
|
| 423 | } |
||
| 424 | |||
| 425 | 2 | $this->orderedColumnsMap[$orderedColumn] = $orientation; |
|
| 426 | 2 | $orderedColumns[] = $orderedColumn . ' ' . $orientation; |
|
| 427 | } |
||
| 428 | } |
||
| 429 | |||
| 430 | 298 | return implode(', ', $orderedColumns); |
|
| 431 | } |
||
| 432 | |||
| 433 | /** |
||
| 434 | * Generates a discriminator column SQL condition for the class with the given DQL alias. |
||
| 435 | * |
||
| 436 | * @param array $dqlAliases List of root DQL aliases to inspect for discriminator restrictions. |
||
| 437 | * |
||
| 438 | * @return string |
||
| 439 | */ |
||
| 440 | 350 | private function _generateDiscriminatorColumnConditionSQL(array $dqlAliases) |
|
| 441 | { |
||
| 442 | 350 | $sqlParts = []; |
|
| 443 | |||
| 444 | 350 | foreach ($dqlAliases as $dqlAlias) { |
|
| 445 | 350 | $class = $this->queryComponents[$dqlAlias]['metadata']; |
|
| 446 | |||
| 447 | 350 | if ( ! $class->isInheritanceTypeSingleTable()) continue; |
|
| 448 | |||
| 449 | 18 | $conn = $this->em->getConnection(); |
|
| 450 | 18 | $values = []; |
|
| 451 | |||
| 452 | 18 | if ($class->discriminatorValue !== null) { // discriminators can be 0 |
|
| 453 | 10 | $values[] = $conn->quote($class->discriminatorValue); |
|
| 454 | } |
||
| 455 | |||
| 456 | 18 | foreach ($class->subClasses as $subclassName) { |
|
| 457 | 12 | $values[] = $conn->quote($this->em->getClassMetadata($subclassName)->discriminatorValue); |
|
| 458 | } |
||
| 459 | |||
| 460 | 18 | $sqlTableAlias = ($this->useSqlTableAliases) |
|
| 461 | 17 | ? $this->getSQLTableAlias($class->getTableName(), $dqlAlias) . '.' |
|
| 462 | 18 | : ''; |
|
| 463 | |||
| 464 | 18 | $sqlParts[] = $sqlTableAlias . $class->discriminatorColumn['name'] . ' IN (' . implode(', ', $values) . ')'; |
|
| 465 | } |
||
| 466 | |||
| 467 | 350 | $sql = implode(' AND ', $sqlParts); |
|
| 468 | |||
| 469 | 350 | return (count($sqlParts) > 1) ? '(' . $sql . ')' : $sql; |
|
| 470 | } |
||
| 471 | |||
| 472 | /** |
||
| 473 | * Generates the filter SQL for a given entity and table alias. |
||
| 474 | * |
||
| 475 | * @param ClassMetadata $targetEntity Metadata of the target entity. |
||
| 476 | * @param string $targetTableAlias The table alias of the joined/selected table. |
||
| 477 | * |
||
| 478 | * @return string The SQL query part to add to a query. |
||
| 479 | */ |
||
| 480 | 116 | private function generateFilterConditionSQL(ClassMetadata $targetEntity, $targetTableAlias) |
|
| 481 | { |
||
| 482 | 116 | if (!$this->em->hasFilters()) { |
|
| 483 | 99 | return ''; |
|
| 484 | } |
||
| 485 | |||
| 486 | 17 | switch($targetEntity->inheritanceType) { |
|
| 487 | 17 | case ClassMetadata::INHERITANCE_TYPE_NONE: |
|
| 488 | 11 | break; |
|
| 489 | 6 | case ClassMetadata::INHERITANCE_TYPE_JOINED: |
|
| 490 | // The classes in the inheritance will be added to the query one by one, |
||
| 491 | // but only the root node is getting filtered |
||
| 492 | 3 | if ($targetEntity->name !== $targetEntity->rootEntityName) { |
|
| 493 | 2 | return ''; |
|
| 494 | } |
||
| 495 | 3 | break; |
|
| 496 | 3 | case ClassMetadata::INHERITANCE_TYPE_SINGLE_TABLE: |
|
| 497 | // With STI the table will only be queried once, make sure that the filters |
||
| 498 | // are added to the root entity |
||
| 499 | 3 | $targetEntity = $this->em->getClassMetadata($targetEntity->rootEntityName); |
|
| 500 | 3 | break; |
|
| 501 | default: |
||
| 502 | //@todo: throw exception? |
||
| 503 | return ''; |
||
| 504 | } |
||
| 505 | |||
| 506 | 17 | $filterClauses = []; |
|
| 507 | 17 | foreach ($this->em->getFilters()->getEnabledFilters() as $filter) { |
|
| 508 | 1 | if ('' !== $filterExpr = $filter->addFilterConstraint($targetEntity, $targetTableAlias)) { |
|
| 509 | 1 | $filterClauses[] = '(' . $filterExpr . ')'; |
|
| 510 | } |
||
| 511 | } |
||
| 512 | |||
| 513 | 17 | return implode(' AND ', $filterClauses); |
|
| 514 | } |
||
| 515 | |||
| 516 | /** |
||
| 517 | * {@inheritdoc} |
||
| 518 | */ |
||
| 519 | 305 | public function walkSelectStatement(AST\SelectStatement $AST) |
|
| 520 | { |
||
| 521 | 305 | $limit = $this->query->getMaxResults(); |
|
| 522 | 305 | $offset = $this->query->getFirstResult(); |
|
| 523 | 305 | $lockMode = $this->query->getHint(Query::HINT_LOCK_MODE); |
|
| 524 | 305 | $sql = $this->walkSelectClause($AST->selectClause) |
|
| 525 | 305 | . $this->walkFromClause($AST->fromClause) |
|
| 526 | 302 | . $this->walkWhereClause($AST->whereClause); |
|
| 527 | |||
| 528 | 299 | if ($AST->groupByClause) { |
|
| 529 | 14 | $sql .= $this->walkGroupByClause($AST->groupByClause); |
|
| 530 | } |
||
| 531 | |||
| 532 | 299 | if ($AST->havingClause) { |
|
| 533 | 11 | $sql .= $this->walkHavingClause($AST->havingClause); |
|
| 534 | } |
||
| 535 | |||
| 536 | 299 | if ($AST->orderByClause) { |
|
| 537 | 20 | $sql .= $this->walkOrderByClause($AST->orderByClause); |
|
| 538 | } |
||
| 539 | |||
| 540 | 298 | if ( ! $AST->orderByClause && ($orderBySql = $this->_generateOrderedCollectionOrderByItems())) { |
|
| 541 | 2 | $sql .= ' ORDER BY ' . $orderBySql; |
|
| 542 | } |
||
| 543 | |||
| 544 | 298 | if ($limit !== null || $offset !== null) { |
|
| 545 | 2 | $sql = $this->platform->modifyLimitQuery($sql, $limit, $offset); |
|
| 546 | } |
||
| 547 | |||
| 548 | 298 | if ($lockMode === null || $lockMode === false || $lockMode === LockMode::NONE) { |
|
| 549 | 293 | return $sql; |
|
| 550 | } |
||
| 551 | |||
| 552 | 5 | if ($lockMode === LockMode::PESSIMISTIC_READ) { |
|
| 553 | 3 | return $sql . ' ' . $this->platform->getReadLockSQL(); |
|
| 554 | } |
||
| 555 | |||
| 556 | 2 | if ($lockMode === LockMode::PESSIMISTIC_WRITE) { |
|
| 557 | 1 | return $sql . ' ' . $this->platform->getWriteLockSQL(); |
|
| 558 | } |
||
| 559 | |||
| 560 | 1 | if ($lockMode !== LockMode::OPTIMISTIC) { |
|
| 561 | throw QueryException::invalidLockMode(); |
||
| 562 | } |
||
| 563 | |||
| 564 | 1 | foreach ($this->selectedClasses as $selectedClass) { |
|
| 565 | 1 | if ( ! $selectedClass['class']->isVersioned) { |
|
| 566 | 1 | throw OptimisticLockException::lockFailed($selectedClass['class']->name); |
|
| 567 | } |
||
| 568 | } |
||
| 569 | |||
| 570 | return $sql; |
||
| 571 | } |
||
| 572 | |||
| 573 | /** |
||
| 574 | * {@inheritdoc} |
||
| 575 | */ |
||
| 576 | 21 | public function walkUpdateStatement(AST\UpdateStatement $AST) |
|
| 577 | { |
||
| 578 | 21 | $this->useSqlTableAliases = false; |
|
| 579 | 21 | $this->rsm->isSelect = false; |
|
| 580 | |||
| 581 | 21 | return $this->walkUpdateClause($AST->updateClause) |
|
| 582 | 21 | . $this->walkWhereClause($AST->whereClause); |
|
| 583 | } |
||
| 584 | |||
| 585 | /** |
||
| 586 | * {@inheritdoc} |
||
| 587 | */ |
||
| 588 | 30 | public function walkDeleteStatement(AST\DeleteStatement $AST) |
|
| 589 | { |
||
| 590 | 30 | $this->useSqlTableAliases = false; |
|
| 591 | 30 | $this->rsm->isSelect = false; |
|
| 592 | |||
| 593 | 30 | return $this->walkDeleteClause($AST->deleteClause) |
|
| 594 | 30 | . $this->walkWhereClause($AST->whereClause); |
|
| 595 | } |
||
| 596 | |||
| 597 | /** |
||
| 598 | * Walks down an IdentificationVariable AST node, thereby generating the appropriate SQL. |
||
| 599 | * This one differs of ->walkIdentificationVariable() because it generates the entity identifiers. |
||
| 600 | * |
||
| 601 | * @param string $identVariable |
||
| 602 | * |
||
| 603 | * @return string |
||
| 604 | */ |
||
| 605 | 2 | public function walkEntityIdentificationVariable($identVariable) |
|
| 606 | { |
||
| 607 | 2 | $class = $this->queryComponents[$identVariable]['metadata']; |
|
| 608 | 2 | $tableAlias = $this->getSQLTableAlias($class->getTableName(), $identVariable); |
|
| 609 | 2 | $sqlParts = []; |
|
| 610 | |||
| 611 | 2 | foreach ($this->quoteStrategy->getIdentifierColumnNames($class, $this->platform) as $columnName) { |
|
| 612 | 2 | $sqlParts[] = $tableAlias . '.' . $columnName; |
|
| 613 | } |
||
| 614 | |||
| 615 | 2 | return implode(', ', $sqlParts); |
|
| 616 | } |
||
| 617 | |||
| 618 | /** |
||
| 619 | * Walks down an IdentificationVariable (no AST node associated), thereby generating the SQL. |
||
| 620 | * |
||
| 621 | * @param string $identificationVariable |
||
| 622 | * @param string $fieldName |
||
| 623 | * |
||
| 624 | * @return string The SQL. |
||
| 625 | */ |
||
| 626 | 193 | public function walkIdentificationVariable($identificationVariable, $fieldName = null) |
|
| 627 | { |
||
| 628 | 193 | $class = $this->queryComponents[$identificationVariable]['metadata']; |
|
| 629 | |||
| 630 | if ( |
||
| 631 | 193 | $fieldName !== null && $class->isInheritanceTypeJoined() && |
|
| 632 | 193 | isset($class->fieldMappings[$fieldName]['inherited']) |
|
| 633 | ) { |
||
| 634 | 6 | $class = $this->em->getClassMetadata($class->fieldMappings[$fieldName]['inherited']); |
|
| 635 | } |
||
| 636 | |||
| 637 | 193 | return $this->getSQLTableAlias($class->getTableName(), $identificationVariable); |
|
| 638 | } |
||
| 639 | |||
| 640 | /** |
||
| 641 | * {@inheritdoc} |
||
| 642 | */ |
||
| 643 | 250 | public function walkPathExpression($pathExpr) |
|
| 644 | { |
||
| 645 | 250 | $sql = ''; |
|
| 646 | |||
| 647 | 250 | switch ($pathExpr->type) { |
|
| 648 | 250 | case AST\PathExpression::TYPE_STATE_FIELD: |
|
| 649 | 236 | $fieldName = $pathExpr->field; |
|
| 650 | 236 | $dqlAlias = $pathExpr->identificationVariable; |
|
| 651 | 236 | $class = $this->queryComponents[$dqlAlias]['metadata']; |
|
| 652 | |||
| 653 | 236 | if ($this->useSqlTableAliases) { |
|
| 654 | 193 | $sql .= $this->walkIdentificationVariable($dqlAlias, $fieldName) . '.'; |
|
| 655 | } |
||
| 656 | |||
| 657 | 236 | $sql .= $this->quoteStrategy->getColumnName($fieldName, $class, $this->platform); |
|
| 658 | 236 | break; |
|
| 659 | |||
| 660 | 40 | case AST\PathExpression::TYPE_SINGLE_VALUED_ASSOCIATION: |
|
| 661 | // 1- the owning side: |
||
| 662 | // Just use the foreign key, i.e. u.group_id |
||
| 663 | 40 | $fieldName = $pathExpr->field; |
|
| 664 | 40 | $dqlAlias = $pathExpr->identificationVariable; |
|
| 665 | 40 | $class = $this->queryComponents[$dqlAlias]['metadata']; |
|
| 666 | |||
| 667 | 40 | if (isset($class->associationMappings[$fieldName]['inherited'])) { |
|
| 668 | 1 | $class = $this->em->getClassMetadata($class->associationMappings[$fieldName]['inherited']); |
|
| 669 | } |
||
| 670 | |||
| 671 | 40 | $assoc = $class->associationMappings[$fieldName]; |
|
| 672 | |||
| 673 | 40 | if ( ! $assoc['isOwningSide']) { |
|
| 674 | 2 | throw QueryException::associationPathInverseSideNotSupported(); |
|
| 675 | } |
||
| 676 | |||
| 677 | // COMPOSITE KEYS NOT (YET?) SUPPORTED |
||
| 678 | 38 | if (count($assoc['sourceToTargetKeyColumns']) > 1) { |
|
| 679 | 1 | throw QueryException::associationPathCompositeKeyNotSupported(); |
|
| 680 | } |
||
| 681 | |||
| 682 | 37 | if ($this->useSqlTableAliases) { |
|
| 683 | 35 | $sql .= $this->getSQLTableAlias($class->getTableName(), $dqlAlias) . '.'; |
|
| 684 | } |
||
| 685 | |||
| 686 | 37 | $sql .= reset($assoc['targetToSourceKeyColumns']); |
|
| 687 | 37 | break; |
|
| 688 | |||
| 689 | default: |
||
| 690 | throw QueryException::invalidPathExpression($pathExpr); |
||
| 691 | } |
||
| 692 | |||
| 693 | 247 | return $sql; |
|
| 694 | } |
||
| 695 | |||
| 696 | /** |
||
| 697 | * {@inheritdoc} |
||
| 698 | */ |
||
| 699 | 305 | public function walkSelectClause($selectClause) |
|
| 700 | { |
||
| 701 | 305 | $sql = 'SELECT ' . (($selectClause->isDistinct) ? 'DISTINCT ' : ''); |
|
| 702 | 305 | $sqlSelectExpressions = array_filter(array_map([$this, 'walkSelectExpression'], $selectClause->selectExpressions)); |
|
| 703 | |||
| 704 | 305 | if ($this->query->getHint(Query::HINT_INTERNAL_ITERATION) == true && $selectClause->isDistinct) { |
|
| 705 | $this->query->setHint(self::HINT_DISTINCT, true); |
||
| 706 | } |
||
| 707 | |||
| 708 | 305 | $addMetaColumns = ! $this->query->getHint(Query::HINT_FORCE_PARTIAL_LOAD) && |
|
| 709 | 143 | $this->query->getHydrationMode() == Query::HYDRATE_OBJECT |
|
| 710 | || |
||
| 711 | 175 | $this->query->getHydrationMode() != Query::HYDRATE_OBJECT && |
|
| 712 | 305 | $this->query->getHint(Query::HINT_INCLUDE_META_COLUMNS); |
|
| 713 | |||
| 714 | 305 | foreach ($this->selectedClasses as $selectedClass) { |
|
| 715 | 221 | $class = $selectedClass['class']; |
|
| 716 | 221 | $dqlAlias = $selectedClass['dqlAlias']; |
|
| 717 | 221 | $resultAlias = $selectedClass['resultAlias']; |
|
| 718 | |||
| 719 | // Register as entity or joined entity result |
||
| 720 | 221 | if ($this->queryComponents[$dqlAlias]['relation'] === null) { |
|
| 721 | 221 | $this->rsm->addEntityResult($class->name, $dqlAlias, $resultAlias); |
|
| 722 | } else { |
||
| 723 | 52 | $this->rsm->addJoinedEntityResult( |
|
| 724 | 52 | $class->name, |
|
| 725 | $dqlAlias, |
||
| 726 | 52 | $this->queryComponents[$dqlAlias]['parent'], |
|
| 727 | 52 | $this->queryComponents[$dqlAlias]['relation']['fieldName'] |
|
| 728 | ); |
||
| 729 | } |
||
| 730 | |||
| 731 | 221 | if ($class->isInheritanceTypeSingleTable() || $class->isInheritanceTypeJoined()) { |
|
| 732 | // Add discriminator columns to SQL |
||
| 733 | 40 | $rootClass = $this->em->getClassMetadata($class->rootEntityName); |
|
| 734 | 40 | $tblAlias = $this->getSQLTableAlias($rootClass->getTableName(), $dqlAlias); |
|
| 735 | 40 | $discrColumn = $rootClass->discriminatorColumn; |
|
| 736 | 40 | $columnAlias = $this->getSQLColumnAlias($discrColumn['name']); |
|
| 737 | |||
| 738 | 40 | $sqlSelectExpressions[] = $tblAlias . '.' . $discrColumn['name'] . ' AS ' . $columnAlias; |
|
| 739 | |||
| 740 | 40 | $this->rsm->setDiscriminatorColumn($dqlAlias, $columnAlias); |
|
| 741 | 40 | $this->rsm->addMetaResult($dqlAlias, $columnAlias, $discrColumn['fieldName'], false, $discrColumn['type']); |
|
| 742 | } |
||
| 743 | |||
| 744 | // Add foreign key columns to SQL, if necessary |
||
| 745 | 221 | if ( ! $addMetaColumns && ! $class->containsForeignIdentifier) { |
|
| 746 | 109 | continue; |
|
| 747 | } |
||
| 748 | |||
| 749 | // Add foreign key columns of class and also parent classes |
||
| 750 | 120 | foreach ($class->associationMappings as $assoc) { |
|
| 751 | 103 | if ( ! ($assoc['isOwningSide'] && $assoc['type'] & ClassMetadata::TO_ONE)) { |
|
| 752 | 75 | continue; |
|
| 753 | 85 | } else if ( !$addMetaColumns && !isset($assoc['id'])) { |
|
| 754 | continue; |
||
| 755 | } |
||
| 756 | |||
| 757 | 85 | $targetClass = $this->em->getClassMetadata($assoc['targetEntity']); |
|
| 758 | 85 | $isIdentifier = (isset($assoc['id']) && $assoc['id'] === true); |
|
| 759 | 85 | $owningClass = (isset($assoc['inherited'])) ? $this->em->getClassMetadata($assoc['inherited']) : $class; |
|
| 760 | 85 | $sqlTableAlias = $this->getSQLTableAlias($owningClass->getTableName(), $dqlAlias); |
|
| 761 | |||
| 762 | 85 | foreach ($assoc['joinColumns'] as $joinColumn) { |
|
| 763 | 85 | $columnName = $joinColumn['name']; |
|
| 764 | 85 | $columnAlias = $this->getSQLColumnAlias($columnName); |
|
| 765 | 85 | $columnType = PersisterHelper::getTypeOfColumn($joinColumn['referencedColumnName'], $targetClass, $this->em); |
|
| 766 | |||
| 767 | 85 | $quotedColumnName = $this->quoteStrategy->getJoinColumnName($joinColumn, $class, $this->platform); |
|
| 768 | 85 | $sqlSelectExpressions[] = $sqlTableAlias . '.' . $quotedColumnName . ' AS ' . $columnAlias; |
|
| 769 | |||
| 770 | 85 | $this->rsm->addMetaResult($dqlAlias, $columnAlias, $columnName, $isIdentifier, $columnType); |
|
| 771 | } |
||
| 772 | } |
||
| 773 | |||
| 774 | // Add foreign key columns to SQL, if necessary |
||
| 775 | 120 | if ( ! $addMetaColumns) { |
|
| 776 | 2 | continue; |
|
| 777 | } |
||
| 778 | |||
| 779 | // Add foreign key columns of subclasses |
||
| 780 | 118 | foreach ($class->subClasses as $subClassName) { |
|
| 781 | 10 | $subClass = $this->em->getClassMetadata($subClassName); |
|
| 782 | 10 | $sqlTableAlias = $this->getSQLTableAlias($subClass->getTableName(), $dqlAlias); |
|
| 783 | |||
| 784 | 10 | foreach ($subClass->associationMappings as $assoc) { |
|
| 785 | // Skip if association is inherited |
||
| 786 | 10 | if (isset($assoc['inherited'])) continue; |
|
| 787 | |||
| 788 | 8 | if ($assoc['isOwningSide'] && $assoc['type'] & ClassMetadata::TO_ONE) { |
|
| 789 | 7 | $targetClass = $this->em->getClassMetadata($assoc['targetEntity']); |
|
| 790 | |||
| 791 | 7 | foreach ($assoc['joinColumns'] as $joinColumn) { |
|
| 792 | 7 | $columnName = $joinColumn['name']; |
|
| 793 | 7 | $columnAlias = $this->getSQLColumnAlias($columnName); |
|
| 794 | 7 | $columnType = PersisterHelper::getTypeOfColumn($joinColumn['referencedColumnName'], $targetClass, $this->em); |
|
| 795 | |||
| 796 | 7 | $sqlSelectExpressions[] = $sqlTableAlias . '.' . $columnName . ' AS ' . $columnAlias; |
|
| 797 | |||
| 798 | 118 | $this->rsm->addMetaResult($dqlAlias, $columnAlias, $columnName, $subClass->isIdentifier($columnName), $columnType); |
|
| 799 | } |
||
| 800 | } |
||
| 801 | } |
||
| 802 | } |
||
| 803 | } |
||
| 804 | |||
| 805 | 305 | $sql .= implode(', ', $sqlSelectExpressions); |
|
| 806 | |||
| 807 | 305 | return $sql; |
|
| 808 | } |
||
| 809 | |||
| 810 | /** |
||
| 811 | * {@inheritdoc} |
||
| 812 | */ |
||
| 813 | 305 | public function walkFromClause($fromClause) |
|
| 824 | |||
| 825 | /** |
||
| 826 | * Walks down a IdentificationVariableDeclaration AST node, thereby generating the appropriate SQL. |
||
| 827 | * |
||
| 828 | * @param AST\IdentificationVariableDeclaration $identificationVariableDecl |
||
| 829 | * |
||
| 830 | * @return string |
||
| 831 | */ |
||
| 832 | 306 | public function walkIdentificationVariableDeclaration($identificationVariableDecl) |
|
| 833 | { |
||
| 834 | 306 | $sql = $this->walkRangeVariableDeclaration($identificationVariableDecl->rangeVariableDeclaration); |
|
| 835 | |||
| 836 | 306 | if ($identificationVariableDecl->indexBy) { |
|
| 837 | $this->walkIndexBy($identificationVariableDecl->indexBy); |
||
| 838 | } |
||
| 839 | |||
| 840 | 306 | foreach ($identificationVariableDecl->joins as $join) { |
|
| 841 | 98 | $sql .= $this->walkJoin($join); |
|
| 842 | } |
||
| 843 | |||
| 844 | 303 | return $sql; |
|
| 845 | } |
||
| 846 | |||
| 847 | /** |
||
| 848 | * Walks down a IndexBy AST node. |
||
| 849 | * |
||
| 850 | * @param AST\IndexBy $indexBy |
||
| 851 | * |
||
| 852 | * @return void |
||
| 853 | */ |
||
| 854 | public function walkIndexBy($indexBy) |
||
| 855 | { |
||
| 856 | $pathExpression = $indexBy->simpleStateFieldPathExpression; |
||
| 857 | $alias = $pathExpression->identificationVariable; |
||
| 858 | $field = $pathExpression->field; |
||
| 859 | |||
| 860 | if (isset($this->scalarFields[$alias][$field])) { |
||
| 861 | $this->rsm->addIndexByScalar($this->scalarFields[$alias][$field]); |
||
| 862 | |||
| 863 | return; |
||
| 864 | } |
||
| 865 | |||
| 866 | $this->rsm->addIndexBy($alias, $field); |
||
| 867 | } |
||
| 868 | |||
| 869 | /** |
||
| 870 | * Walks down a RangeVariableDeclaration AST node, thereby generating the appropriate SQL. |
||
| 871 | * |
||
| 872 | * @param AST\RangeVariableDeclaration $rangeVariableDeclaration |
||
| 873 | * |
||
| 874 | * @return string |
||
| 875 | */ |
||
| 876 | 306 | public function walkRangeVariableDeclaration($rangeVariableDeclaration) |
|
| 897 | |||
| 898 | /** |
||
| 899 | * Walks down a JoinAssociationDeclaration AST node, thereby generating the appropriate SQL. |
||
| 900 | * |
||
| 901 | * @param AST\JoinAssociationDeclaration $joinAssociationDeclaration |
||
| 902 | * @param int $joinType |
||
| 903 | * @param AST\ConditionalExpression $condExpr |
||
| 904 | * |
||
| 905 | * @return string |
||
| 906 | * |
||
| 907 | * @throws QueryException |
||
| 908 | */ |
||
| 909 | 83 | public function walkJoinAssociationDeclaration($joinAssociationDeclaration, $joinType = AST\Join::JOIN_TYPE_INNER, $condExpr = null) |
|
| 910 | { |
||
| 911 | 83 | $sql = ''; |
|
| 912 | |||
| 913 | 83 | $associationPathExpression = $joinAssociationDeclaration->joinAssociationPathExpression; |
|
| 914 | 83 | $joinedDqlAlias = $joinAssociationDeclaration->aliasIdentificationVariable; |
|
| 915 | 83 | $indexBy = $joinAssociationDeclaration->indexBy; |
|
| 916 | |||
| 917 | 83 | $relation = $this->queryComponents[$joinedDqlAlias]['relation']; |
|
| 918 | 83 | $targetClass = $this->em->getClassMetadata($relation['targetEntity']); |
|
| 919 | 83 | $sourceClass = $this->em->getClassMetadata($relation['sourceEntity']); |
|
| 920 | 83 | $targetTableName = $this->quoteStrategy->getTableName($targetClass, $this->platform); |
|
| 921 | |||
| 922 | 83 | $targetTableAlias = $this->getSQLTableAlias($targetClass->getTableName(), $joinedDqlAlias); |
|
| 923 | 83 | $sourceTableAlias = $this->getSQLTableAlias($sourceClass->getTableName(), $associationPathExpression->identificationVariable); |
|
| 924 | |||
| 925 | // Ensure we got the owning side, since it has all mapping info |
||
| 926 | 83 | $assoc = ( ! $relation['isOwningSide']) ? $targetClass->associationMappings[$relation['mappedBy']] : $relation; |
|
| 927 | |||
| 928 | 83 | if ($this->query->getHint(Query::HINT_INTERNAL_ITERATION) == true && (!$this->query->getHint(self::HINT_DISTINCT) || isset($this->selectedClasses[$joinedDqlAlias]))) { |
|
| 929 | 3 | if ($relation['type'] == ClassMetadata::ONE_TO_MANY || $relation['type'] == ClassMetadata::MANY_TO_MANY) { |
|
| 930 | 3 | throw QueryException::iterateWithFetchJoinNotAllowed($assoc); |
|
| 931 | } |
||
| 932 | } |
||
| 933 | |||
| 934 | 80 | $targetTableJoin = null; |
|
| 935 | |||
| 936 | // This condition is not checking ClassMetadata::MANY_TO_ONE, because by definition it cannot |
||
| 937 | // be the owning side and previously we ensured that $assoc is always the owning side of the associations. |
||
| 938 | // The owning side is necessary at this point because only it contains the JoinColumn information. |
||
| 939 | switch (true) { |
||
| 940 | 80 | case ($assoc['type'] & ClassMetadata::TO_ONE): |
|
| 941 | 52 | $conditions = []; |
|
| 942 | |||
| 943 | 52 | foreach ($assoc['joinColumns'] as $joinColumn) { |
|
| 944 | 52 | $quotedSourceColumn = $this->quoteStrategy->getJoinColumnName($joinColumn, $targetClass, $this->platform); |
|
| 945 | 52 | $quotedTargetColumn = $this->quoteStrategy->getReferencedJoinColumnName($joinColumn, $targetClass, $this->platform); |
|
| 946 | |||
| 947 | 52 | if ($relation['isOwningSide']) { |
|
| 948 | 31 | $conditions[] = $sourceTableAlias . '.' . $quotedSourceColumn . ' = ' . $targetTableAlias . '.' . $quotedTargetColumn; |
|
| 949 | |||
| 950 | 31 | continue; |
|
| 951 | } |
||
| 952 | |||
| 953 | 23 | $conditions[] = $sourceTableAlias . '.' . $quotedTargetColumn . ' = ' . $targetTableAlias . '.' . $quotedSourceColumn; |
|
| 954 | } |
||
| 955 | |||
| 956 | // Apply remaining inheritance restrictions |
||
| 957 | 52 | $discrSql = $this->_generateDiscriminatorColumnConditionSQL([$joinedDqlAlias]); |
|
| 958 | |||
| 959 | 52 | if ($discrSql) { |
|
| 960 | $conditions[] = $discrSql; |
||
| 961 | } |
||
| 962 | |||
| 963 | // Apply the filters |
||
| 964 | 52 | $filterExpr = $this->generateFilterConditionSQL($targetClass, $targetTableAlias); |
|
| 965 | |||
| 966 | 52 | if ($filterExpr) { |
|
| 967 | $conditions[] = $filterExpr; |
||
| 968 | } |
||
| 969 | |||
| 970 | $targetTableJoin = [ |
||
| 971 | 52 | 'table' => $targetTableName . ' ' . $targetTableAlias, |
|
| 972 | 52 | 'condition' => implode(' AND ', $conditions), |
|
| 973 | ]; |
||
| 974 | 52 | break; |
|
| 975 | |||
| 976 | 29 | case ($assoc['type'] == ClassMetadata::MANY_TO_MANY): |
|
| 977 | // Join relation table |
||
| 978 | 29 | $joinTable = $assoc['joinTable']; |
|
| 979 | 29 | $joinTableAlias = $this->getSQLTableAlias($joinTable['name'], $joinedDqlAlias); |
|
| 980 | 29 | $joinTableName = $this->quoteStrategy->getJoinTableName($assoc, $sourceClass, $this->platform); |
|
| 981 | |||
| 982 | 29 | $conditions = []; |
|
| 983 | 29 | $relationColumns = ($relation['isOwningSide']) |
|
| 984 | 22 | ? $assoc['joinTable']['joinColumns'] |
|
| 985 | 29 | : $assoc['joinTable']['inverseJoinColumns']; |
|
| 986 | |||
| 987 | 29 | foreach ($relationColumns as $joinColumn) { |
|
| 988 | 29 | $quotedSourceColumn = $this->quoteStrategy->getJoinColumnName($joinColumn, $targetClass, $this->platform); |
|
| 989 | 29 | $quotedTargetColumn = $this->quoteStrategy->getReferencedJoinColumnName($joinColumn, $targetClass, $this->platform); |
|
| 990 | |||
| 991 | 29 | $conditions[] = $sourceTableAlias . '.' . $quotedTargetColumn . ' = ' . $joinTableAlias . '.' . $quotedSourceColumn; |
|
| 992 | } |
||
| 993 | |||
| 994 | 29 | $sql .= $joinTableName . ' ' . $joinTableAlias . ' ON ' . implode(' AND ', $conditions); |
|
| 995 | |||
| 996 | // Join target table |
||
| 997 | 29 | $sql .= ($joinType == AST\Join::JOIN_TYPE_LEFT || $joinType == AST\Join::JOIN_TYPE_LEFTOUTER) ? ' LEFT JOIN ' : ' INNER JOIN '; |
|
| 998 | |||
| 999 | 29 | $conditions = []; |
|
| 1000 | 29 | $relationColumns = ($relation['isOwningSide']) |
|
| 1001 | 22 | ? $assoc['joinTable']['inverseJoinColumns'] |
|
| 1002 | 29 | : $assoc['joinTable']['joinColumns']; |
|
| 1003 | |||
| 1004 | 29 | foreach ($relationColumns as $joinColumn) { |
|
| 1005 | 29 | $quotedSourceColumn = $this->quoteStrategy->getJoinColumnName($joinColumn, $targetClass, $this->platform); |
|
| 1006 | 29 | $quotedTargetColumn = $this->quoteStrategy->getReferencedJoinColumnName($joinColumn, $targetClass, $this->platform); |
|
| 1007 | |||
| 1008 | 29 | $conditions[] = $targetTableAlias . '.' . $quotedTargetColumn . ' = ' . $joinTableAlias . '.' . $quotedSourceColumn; |
|
| 1009 | } |
||
| 1010 | |||
| 1011 | // Apply remaining inheritance restrictions |
||
| 1012 | 29 | $discrSql = $this->_generateDiscriminatorColumnConditionSQL([$joinedDqlAlias]); |
|
| 1013 | |||
| 1014 | 29 | if ($discrSql) { |
|
| 1015 | 1 | $conditions[] = $discrSql; |
|
| 1016 | } |
||
| 1017 | |||
| 1018 | // Apply the filters |
||
| 1019 | 29 | $filterExpr = $this->generateFilterConditionSQL($targetClass, $targetTableAlias); |
|
| 1020 | |||
| 1021 | 29 | if ($filterExpr) { |
|
| 1022 | $conditions[] = $filterExpr; |
||
| 1023 | } |
||
| 1024 | |||
| 1025 | $targetTableJoin = [ |
||
| 1026 | 29 | 'table' => $targetTableName . ' ' . $targetTableAlias, |
|
| 1027 | 29 | 'condition' => implode(' AND ', $conditions), |
|
| 1028 | ]; |
||
| 1029 | 29 | break; |
|
| 1030 | |||
| 1031 | default: |
||
| 1032 | throw new \BadMethodCallException('Type of association must be one of *_TO_ONE or MANY_TO_MANY'); |
||
| 1033 | } |
||
| 1034 | |||
| 1035 | // Handle WITH clause |
||
| 1036 | 80 | $withCondition = (null === $condExpr) ? '' : ('(' . $this->walkConditionalExpression($condExpr) . ')'); |
|
| 1037 | |||
| 1038 | 80 | if ($targetClass->isInheritanceTypeJoined()) { |
|
| 1039 | 5 | $ctiJoins = $this->_generateClassTableInheritanceJoins($targetClass, $joinedDqlAlias); |
|
| 1040 | // If we have WITH condition, we need to build nested joins for target class table and cti joins |
||
| 1041 | 5 | if ($withCondition) { |
|
| 1042 | 1 | $sql .= '(' . $targetTableJoin['table'] . $ctiJoins . ') ON ' . $targetTableJoin['condition']; |
|
| 1043 | } else { |
||
| 1044 | 5 | $sql .= $targetTableJoin['table'] . ' ON ' . $targetTableJoin['condition'] . $ctiJoins; |
|
| 1045 | } |
||
| 1046 | } else { |
||
| 1047 | 75 | $sql .= $targetTableJoin['table'] . ' ON ' . $targetTableJoin['condition']; |
|
| 1048 | } |
||
| 1049 | |||
| 1050 | 80 | if ($withCondition) { |
|
| 1051 | 4 | $sql .= ' AND ' . $withCondition; |
|
| 1052 | } |
||
| 1053 | |||
| 1054 | // Apply the indexes |
||
| 1055 | 80 | if ($indexBy) { |
|
| 1056 | // For Many-To-One or One-To-One associations this obviously makes no sense, but is ignored silently. |
||
| 1057 | $this->walkIndexBy($indexBy); |
||
| 1058 | 80 | } else if (isset($relation['indexBy'])) { |
|
| 1059 | $this->rsm->addIndexBy($joinedDqlAlias, $relation['indexBy']); |
||
| 1060 | } |
||
| 1061 | |||
| 1062 | 80 | return $sql; |
|
| 1063 | } |
||
| 1064 | |||
| 1065 | /** |
||
| 1066 | * {@inheritdoc} |
||
| 1067 | */ |
||
| 1068 | 42 | public function walkFunction($function) |
|
| 1072 | |||
| 1073 | /** |
||
| 1074 | * {@inheritdoc} |
||
| 1075 | */ |
||
| 1076 | 31 | public function walkOrderByClause($orderByClause) |
|
| 1086 | |||
| 1087 | /** |
||
| 1088 | * {@inheritdoc} |
||
| 1089 | */ |
||
| 1090 | 41 | public function walkOrderByItem($orderByItem) |
|
| 1106 | |||
| 1107 | /** |
||
| 1108 | * {@inheritdoc} |
||
| 1109 | */ |
||
| 1110 | 11 | public function walkHavingClause($havingClause) |
|
| 1114 | |||
| 1115 | /** |
||
| 1116 | * {@inheritdoc} |
||
| 1117 | */ |
||
| 1118 | 98 | public function walkJoin($join) |
|
| 1171 | |||
| 1172 | /** |
||
| 1173 | * Walks down a CoalesceExpression AST node and generates the corresponding SQL. |
||
| 1174 | * |
||
| 1175 | * @param AST\CoalesceExpression $coalesceExpression |
||
| 1176 | * |
||
| 1177 | * @return string The SQL. |
||
| 1178 | */ |
||
| 1179 | 2 | public function walkCoalesceExpression($coalesceExpression) |
|
| 1180 | { |
||
| 1181 | 2 | $sql = 'COALESCE('; |
|
| 1193 | |||
| 1194 | /** |
||
| 1195 | * Walks down a NullIfExpression AST node and generates the corresponding SQL. |
||
| 1196 | * |
||
| 1197 | * @param AST\NullIfExpression $nullIfExpression |
||
| 1198 | * |
||
| 1199 | * @return string The SQL. |
||
| 1200 | */ |
||
| 1201 | 3 | public function walkNullIfExpression($nullIfExpression) |
|
| 1213 | |||
| 1214 | /** |
||
| 1215 | * Walks down a GeneralCaseExpression AST node and generates the corresponding SQL. |
||
| 1216 | * |
||
| 1217 | * @param AST\GeneralCaseExpression $generalCaseExpression |
||
| 1218 | * |
||
| 1219 | * @return string The SQL. |
||
| 1220 | */ |
||
| 1221 | 8 | public function walkGeneralCaseExpression(AST\GeneralCaseExpression $generalCaseExpression) |
|
| 1234 | |||
| 1235 | /** |
||
| 1236 | * Walks down a SimpleCaseExpression AST node and generates the corresponding SQL. |
||
| 1237 | * |
||
| 1238 | * @param AST\SimpleCaseExpression $simpleCaseExpression |
||
| 1239 | * |
||
| 1240 | * @return string The SQL. |
||
| 1241 | */ |
||
| 1242 | 5 | public function walkSimpleCaseExpression($simpleCaseExpression) |
|
| 1255 | |||
| 1256 | /** |
||
| 1257 | * {@inheritdoc} |
||
| 1258 | */ |
||
| 1259 | 305 | public function walkSelectExpression($selectExpression) |
|
| 1260 | { |
||
| 1261 | 305 | $sql = ''; |
|
| 1262 | 305 | $expr = $selectExpression->expression; |
|
| 1263 | 305 | $hidden = $selectExpression->hiddenAliasResultVariable; |
|
| 1264 | |||
| 1265 | switch (true) { |
||
| 1266 | 305 | case ($expr instanceof AST\PathExpression): |
|
| 1267 | 60 | if ($expr->type !== AST\PathExpression::TYPE_STATE_FIELD) { |
|
| 1268 | throw QueryException::invalidPathExpression($expr); |
||
| 1269 | } |
||
| 1270 | |||
| 1271 | 60 | $fieldName = $expr->field; |
|
| 1272 | 60 | $dqlAlias = $expr->identificationVariable; |
|
| 1273 | 60 | $qComp = $this->queryComponents[$dqlAlias]; |
|
| 1274 | 60 | $class = $qComp['metadata']; |
|
| 1275 | |||
| 1276 | 60 | $resultAlias = $selectExpression->fieldIdentificationVariable ?: $fieldName; |
|
| 1277 | 60 | $tableName = ($class->isInheritanceTypeJoined()) |
|
| 1278 | 6 | ? $this->em->getUnitOfWork()->getEntityPersister($class->name)->getOwningTable($fieldName) |
|
| 1279 | 60 | : $class->getTableName(); |
|
| 1280 | |||
| 1281 | 60 | $sqlTableAlias = $this->getSQLTableAlias($tableName, $dqlAlias); |
|
| 1282 | 60 | $fieldMapping = $class->fieldMappings[$fieldName]; |
|
| 1283 | 60 | $columnName = $this->quoteStrategy->getColumnName($fieldName, $class, $this->platform); |
|
| 1284 | 60 | $columnAlias = $this->getSQLColumnAlias($fieldMapping['columnName']); |
|
| 1285 | 60 | $col = $sqlTableAlias . '.' . $columnName; |
|
| 1286 | |||
| 1287 | 60 | if (isset($fieldMapping['requireSQLConversion'])) { |
|
| 1288 | 1 | $type = Type::getType($fieldMapping['type']); |
|
| 1289 | 1 | $col = $type->convertToPHPValueSQL($col, $this->conn->getDatabasePlatform()); |
|
| 1290 | } |
||
| 1291 | |||
| 1292 | 60 | $sql .= $col . ' AS ' . $columnAlias; |
|
| 1293 | |||
| 1294 | 60 | $this->scalarResultAliasMap[$resultAlias] = $columnAlias; |
|
| 1295 | |||
| 1296 | 60 | if ( ! $hidden) { |
|
| 1297 | 60 | $this->rsm->addScalarResult($columnAlias, $resultAlias, $fieldMapping['type']); |
|
| 1298 | 60 | $this->scalarFields[$dqlAlias][$fieldName] = $columnAlias; |
|
| 1299 | } |
||
| 1300 | |||
| 1301 | 60 | break; |
|
| 1302 | |||
| 1303 | case ($expr instanceof AST\AggregateExpression): |
||
| 1304 | case ($expr instanceof AST\Functions\FunctionNode): |
||
| 1305 | case ($expr instanceof AST\SimpleArithmeticExpression): |
||
| 1306 | case ($expr instanceof AST\ArithmeticTerm): |
||
| 1307 | 1 | case ($expr instanceof AST\ArithmeticFactor): |
|
| 1308 | case ($expr instanceof AST\ParenthesisExpression): |
||
| 1309 | case ($expr instanceof AST\Literal): |
||
| 1310 | 1 | case ($expr instanceof AST\NullIfExpression): |
|
| 1311 | 1 | case ($expr instanceof AST\CoalesceExpression): |
|
| 1312 | case ($expr instanceof AST\GeneralCaseExpression): |
||
| 1313 | 7 | case ($expr instanceof AST\SimpleCaseExpression): |
|
| 1314 | 67 | $columnAlias = $this->getSQLColumnAlias('sclr'); |
|
| 1315 | 67 | $resultAlias = $selectExpression->fieldIdentificationVariable ?: $this->scalarResultCounter++; |
|
| 1316 | |||
| 1317 | 67 | $sql .= $expr->dispatch($this) . ' AS ' . $columnAlias; |
|
| 1318 | |||
| 1319 | 67 | $this->scalarResultAliasMap[$resultAlias] = $columnAlias; |
|
| 1320 | |||
| 1321 | 67 | if ( ! $hidden) { |
|
| 1322 | // We cannot resolve field type here; assume 'string'. |
||
| 1323 | 66 | $this->rsm->addScalarResult($columnAlias, $resultAlias, 'string'); |
|
| 1324 | } |
||
| 1325 | 67 | break; |
|
| 1326 | |||
| 1327 | case ($expr instanceof AST\Subselect): |
||
| 1328 | 10 | $columnAlias = $this->getSQLColumnAlias('sclr'); |
|
| 1329 | 10 | $resultAlias = $selectExpression->fieldIdentificationVariable ?: $this->scalarResultCounter++; |
|
| 1330 | |||
| 1331 | 10 | $sql .= '(' . $this->walkSubselect($expr) . ') AS ' . $columnAlias; |
|
| 1332 | |||
| 1333 | 10 | $this->scalarResultAliasMap[$resultAlias] = $columnAlias; |
|
| 1334 | |||
| 1335 | 10 | if ( ! $hidden) { |
|
| 1336 | // We cannot resolve field type here; assume 'string'. |
||
| 1337 | 10 | $this->rsm->addScalarResult($columnAlias, $resultAlias, 'string'); |
|
| 1338 | } |
||
| 1339 | 10 | break; |
|
| 1340 | |||
| 1341 | 221 | case ($expr instanceof AST\NewObjectExpression): |
|
| 1342 | 1 | $sql .= $this->walkNewObject($expr,$selectExpression->fieldIdentificationVariable); |
|
| 1343 | 1 | break; |
|
| 1344 | |||
| 1345 | default: |
||
| 1346 | // IdentificationVariable or PartialObjectExpression |
||
| 1347 | 221 | if ($expr instanceof AST\PartialObjectExpression) { |
|
| 1348 | 6 | $dqlAlias = $expr->identificationVariable; |
|
| 1349 | 6 | $partialFieldSet = $expr->partialFieldSet; |
|
| 1350 | } else { |
||
| 1351 | 218 | $dqlAlias = $expr; |
|
| 1352 | 218 | $partialFieldSet = []; |
|
| 1353 | } |
||
| 1354 | |||
| 1355 | 221 | $queryComp = $this->queryComponents[$dqlAlias]; |
|
| 1356 | 221 | $class = $queryComp['metadata']; |
|
| 1357 | 221 | $resultAlias = $selectExpression->fieldIdentificationVariable ?: null; |
|
| 1358 | |||
| 1359 | 221 | if ( ! isset($this->selectedClasses[$dqlAlias])) { |
|
| 1360 | 221 | $this->selectedClasses[$dqlAlias] = [ |
|
| 1361 | 221 | 'class' => $class, |
|
| 1362 | 221 | 'dqlAlias' => $dqlAlias, |
|
| 1363 | 221 | 'resultAlias' => $resultAlias |
|
| 1364 | ]; |
||
| 1365 | } |
||
| 1366 | |||
| 1367 | 221 | $sqlParts = []; |
|
| 1368 | |||
| 1369 | // Select all fields from the queried class |
||
| 1370 | 221 | foreach ($class->fieldMappings as $fieldName => $mapping) { |
|
| 1371 | 220 | if ($partialFieldSet && ! in_array($fieldName, $partialFieldSet)) { |
|
| 1372 | 5 | continue; |
|
| 1373 | } |
||
| 1374 | |||
| 1375 | 220 | $tableName = (isset($mapping['inherited'])) |
|
| 1376 | 21 | ? $this->em->getClassMetadata($mapping['inherited'])->getTableName() |
|
| 1377 | 220 | : $class->getTableName(); |
|
| 1378 | |||
| 1379 | 220 | $sqlTableAlias = $this->getSQLTableAlias($tableName, $dqlAlias); |
|
| 1380 | 220 | $columnAlias = $this->getSQLColumnAlias($mapping['columnName']); |
|
| 1381 | 220 | $quotedColumnName = $this->quoteStrategy->getColumnName($fieldName, $class, $this->platform); |
|
| 1382 | |||
| 1383 | 220 | $col = $sqlTableAlias . '.' . $quotedColumnName; |
|
| 1384 | |||
| 1385 | 220 | if (isset($mapping['requireSQLConversion'])) { |
|
| 1386 | 4 | $type = Type::getType($mapping['type']); |
|
| 1387 | 4 | $col = $type->convertToPHPValueSQL($col, $this->platform); |
|
| 1388 | } |
||
| 1389 | |||
| 1390 | 220 | $sqlParts[] = $col . ' AS '. $columnAlias; |
|
| 1391 | |||
| 1392 | 220 | $this->scalarResultAliasMap[$resultAlias][] = $columnAlias; |
|
| 1393 | |||
| 1394 | 220 | $this->rsm->addFieldResult($dqlAlias, $columnAlias, $fieldName, $class->name); |
|
| 1395 | } |
||
| 1396 | |||
| 1397 | // Add any additional fields of subclasses (excluding inherited fields) |
||
| 1398 | // 1) on Single Table Inheritance: always, since its marginal overhead |
||
| 1399 | // 2) on Class Table Inheritance only if partial objects are disallowed, |
||
| 1400 | // since it requires outer joining subtables. |
||
| 1401 | 221 | if ($class->isInheritanceTypeSingleTable() || ! $this->query->getHint(Query::HINT_FORCE_PARTIAL_LOAD)) { |
|
| 1402 | 128 | foreach ($class->subClasses as $subClassName) { |
|
| 1403 | 18 | $subClass = $this->em->getClassMetadata($subClassName); |
|
| 1404 | 18 | $sqlTableAlias = $this->getSQLTableAlias($subClass->getTableName(), $dqlAlias); |
|
| 1405 | |||
| 1406 | 18 | foreach ($subClass->fieldMappings as $fieldName => $mapping) { |
|
| 1407 | 18 | if (isset($mapping['inherited']) || ($partialFieldSet && !in_array($fieldName, $partialFieldSet))) { |
|
| 1408 | 18 | continue; |
|
| 1409 | } |
||
| 1410 | |||
| 1411 | 18 | $columnAlias = $this->getSQLColumnAlias($mapping['columnName']); |
|
| 1412 | 18 | $quotedColumnName = $this->quoteStrategy->getColumnName($fieldName, $subClass, $this->platform); |
|
| 1413 | |||
| 1414 | 18 | $col = $sqlTableAlias . '.' . $quotedColumnName; |
|
| 1415 | |||
| 1416 | 18 | if (isset($mapping['requireSQLConversion'])) { |
|
| 1417 | $type = Type::getType($mapping['type']); |
||
| 1418 | $col = $type->convertToPHPValueSQL($col, $this->platform); |
||
| 1419 | } |
||
| 1420 | |||
| 1421 | 18 | $sqlParts[] = $col . ' AS ' . $columnAlias; |
|
| 1422 | |||
| 1423 | 18 | $this->scalarResultAliasMap[$resultAlias][] = $columnAlias; |
|
| 1424 | |||
| 1425 | 18 | $this->rsm->addFieldResult($dqlAlias, $columnAlias, $fieldName, $subClassName); |
|
| 1426 | } |
||
| 1427 | } |
||
| 1428 | } |
||
| 1429 | |||
| 1430 | 221 | $sql .= implode(', ', $sqlParts); |
|
| 1431 | } |
||
| 1432 | |||
| 1433 | 305 | return $sql; |
|
| 1434 | } |
||
| 1435 | |||
| 1436 | /** |
||
| 1437 | * {@inheritdoc} |
||
| 1438 | */ |
||
| 1439 | public function walkQuantifiedExpression($qExpr) |
||
| 1443 | |||
| 1444 | /** |
||
| 1445 | * {@inheritdoc} |
||
| 1446 | */ |
||
| 1447 | 26 | public function walkSubselect($subselect) |
|
| 1468 | |||
| 1469 | /** |
||
| 1470 | * {@inheritdoc} |
||
| 1471 | */ |
||
| 1472 | 26 | public function walkSubselectFromClause($subselectFromClause) |
|
| 1483 | |||
| 1484 | /** |
||
| 1485 | * {@inheritdoc} |
||
| 1486 | */ |
||
| 1487 | 26 | public function walkSimpleSelectClause($simpleSelectClause) |
|
| 1492 | |||
| 1493 | /** |
||
| 1494 | * @param \Doctrine\ORM\Query\AST\ParenthesisExpression $parenthesisExpression |
||
| 1495 | * |
||
| 1496 | * @return string. |
||
| 1497 | */ |
||
| 1498 | 19 | public function walkParenthesisExpression(AST\ParenthesisExpression $parenthesisExpression) |
|
| 1502 | |||
| 1503 | /** |
||
| 1504 | * @param AST\NewObjectExpression $newObjectExpression |
||
| 1505 | * |
||
| 1506 | * @return string The SQL. |
||
| 1507 | */ |
||
| 1508 | 1 | public function walkNewObject($newObjectExpression, $newObjectResultAlias=null) |
|
| 1509 | { |
||
| 1510 | 1 | $sqlSelectExpressions = []; |
|
| 1511 | 1 | $objIndex = $newObjectResultAlias?:$this->newObjectCounter++; |
|
| 1512 | |||
| 1513 | 1 | foreach ($newObjectExpression->args as $argIndex => $e) { |
|
| 1514 | 1 | $resultAlias = $this->scalarResultCounter++; |
|
| 1515 | 1 | $columnAlias = $this->getSQLColumnAlias('sclr'); |
|
| 1516 | 1 | $fieldType = 'string'; |
|
| 1517 | |||
| 1518 | switch (true) { |
||
| 1519 | 1 | case ($e instanceof AST\NewObjectExpression): |
|
| 1520 | $sqlSelectExpressions[] = $e->dispatch($this); |
||
| 1521 | break; |
||
| 1522 | |||
| 1523 | case ($e instanceof AST\Subselect): |
||
| 1524 | 1 | $sqlSelectExpressions[] = '(' . $e->dispatch($this) . ') AS ' . $columnAlias; |
|
| 1525 | 1 | break; |
|
| 1526 | |||
| 1527 | case ($e instanceof AST\PathExpression): |
||
| 1528 | 1 | $dqlAlias = $e->identificationVariable; |
|
| 1529 | 1 | $qComp = $this->queryComponents[$dqlAlias]; |
|
| 1530 | 1 | $class = $qComp['metadata']; |
|
| 1531 | 1 | $fieldType = $class->fieldMappings[$e->field]['type']; |
|
| 1532 | |||
| 1533 | 1 | $sqlSelectExpressions[] = trim($e->dispatch($this)) . ' AS ' . $columnAlias; |
|
| 1534 | 1 | break; |
|
| 1535 | |||
| 1536 | 1 | case ($e instanceof AST\Literal): |
|
| 1537 | switch ($e->type) { |
||
| 1538 | case AST\Literal::BOOLEAN: |
||
| 1539 | $fieldType = 'boolean'; |
||
| 1540 | break; |
||
| 1541 | |||
| 1542 | case AST\Literal::NUMERIC: |
||
| 1543 | $fieldType = is_float($e->value) ? 'float' : 'integer'; |
||
| 1544 | break; |
||
| 1545 | } |
||
| 1546 | |||
| 1547 | $sqlSelectExpressions[] = trim($e->dispatch($this)) . ' AS ' . $columnAlias; |
||
| 1548 | break; |
||
| 1549 | |||
| 1550 | default: |
||
| 1551 | 1 | $sqlSelectExpressions[] = trim($e->dispatch($this)) . ' AS ' . $columnAlias; |
|
| 1552 | 1 | break; |
|
| 1553 | } |
||
| 1554 | |||
| 1555 | 1 | $this->scalarResultAliasMap[$resultAlias] = $columnAlias; |
|
| 1556 | 1 | $this->rsm->addScalarResult($columnAlias, $resultAlias, $fieldType); |
|
| 1557 | |||
| 1558 | 1 | $this->rsm->newObjectMappings[$columnAlias] = [ |
|
| 1559 | 1 | 'className' => $newObjectExpression->className, |
|
| 1560 | 1 | 'objIndex' => $objIndex, |
|
| 1561 | 1 | 'argIndex' => $argIndex |
|
| 1562 | ]; |
||
| 1563 | } |
||
| 1564 | |||
| 1565 | 1 | return implode(', ', $sqlSelectExpressions); |
|
| 1566 | } |
||
| 1567 | |||
| 1568 | /** |
||
| 1569 | * {@inheritdoc} |
||
| 1570 | */ |
||
| 1571 | 26 | public function walkSimpleSelectExpression($simpleSelectExpression) |
|
| 1624 | |||
| 1625 | /** |
||
| 1626 | * {@inheritdoc} |
||
| 1627 | */ |
||
| 1628 | 52 | public function walkAggregateExpression($aggExpression) |
|
| 1633 | |||
| 1634 | /** |
||
| 1635 | * {@inheritdoc} |
||
| 1636 | */ |
||
| 1637 | 14 | public function walkGroupByClause($groupByClause) |
|
| 1647 | |||
| 1648 | /** |
||
| 1649 | * {@inheritdoc} |
||
| 1650 | */ |
||
| 1651 | 14 | public function walkGroupByItem($groupByItem) |
|
| 1694 | |||
| 1695 | /** |
||
| 1696 | * {@inheritdoc} |
||
| 1697 | */ |
||
| 1698 | 30 | public function walkDeleteClause(AST\DeleteClause $deleteClause) |
|
| 1709 | |||
| 1710 | /** |
||
| 1711 | * {@inheritdoc} |
||
| 1712 | */ |
||
| 1713 | 21 | public function walkUpdateClause($updateClause) |
|
| 1726 | |||
| 1727 | /** |
||
| 1728 | * {@inheritdoc} |
||
| 1729 | */ |
||
| 1730 | 21 | public function walkUpdateItem($updateItem) |
|
| 1756 | |||
| 1757 | /** |
||
| 1758 | * {@inheritdoc} |
||
| 1759 | */ |
||
| 1760 | 353 | public function walkWhereClause($whereClause) |
|
| 1761 | { |
||
| 1762 | 353 | $condSql = null !== $whereClause ? $this->walkConditionalExpression($whereClause->conditionalExpression) : ''; |
|
| 1763 | 350 | $discrSql = $this->_generateDiscriminatorColumnConditionSql($this->rootAliases); |
|
| 1764 | |||
| 1765 | 350 | if ($this->em->hasFilters()) { |
|
| 1766 | 17 | $filterClauses = []; |
|
| 1767 | 17 | foreach ($this->rootAliases as $dqlAlias) { |
|
| 1768 | 17 | $class = $this->queryComponents[$dqlAlias]['metadata']; |
|
| 1769 | 17 | $tableAlias = $this->getSQLTableAlias($class->table['name'], $dqlAlias); |
|
| 1770 | |||
| 1771 | 17 | if ($filterExpr = $this->generateFilterConditionSQL($class, $tableAlias)) { |
|
| 1772 | 17 | $filterClauses[] = $filterExpr; |
|
| 1773 | } |
||
| 1774 | } |
||
| 1775 | |||
| 1776 | 17 | if (count($filterClauses)) { |
|
| 1777 | 1 | if ($condSql) { |
|
| 1778 | $condSql = '(' . $condSql . ') AND '; |
||
| 1779 | } |
||
| 1780 | |||
| 1781 | 1 | $condSql .= implode(' AND ', $filterClauses); |
|
| 1782 | } |
||
| 1783 | } |
||
| 1784 | |||
| 1785 | 350 | if ($condSql) { |
|
| 1786 | 186 | return ' WHERE ' . (( ! $discrSql) ? $condSql : '(' . $condSql . ') AND ' . $discrSql); |
|
| 1787 | } |
||
| 1788 | |||
| 1789 | 184 | if ($discrSql) { |
|
| 1790 | 10 | return ' WHERE ' . $discrSql; |
|
| 1791 | } |
||
| 1792 | |||
| 1793 | 175 | return ''; |
|
| 1794 | } |
||
| 1795 | |||
| 1796 | /** |
||
| 1797 | * {@inheritdoc} |
||
| 1798 | */ |
||
| 1799 | 214 | public function walkConditionalExpression($condExpr) |
|
| 1809 | |||
| 1810 | /** |
||
| 1811 | * {@inheritdoc} |
||
| 1812 | */ |
||
| 1813 | 214 | public function walkConditionalTerm($condTerm) |
|
| 1823 | |||
| 1824 | /** |
||
| 1825 | * {@inheritdoc} |
||
| 1826 | */ |
||
| 1827 | 214 | public function walkConditionalFactor($factor) |
|
| 1835 | |||
| 1836 | /** |
||
| 1837 | * {@inheritdoc} |
||
| 1838 | */ |
||
| 1839 | 214 | public function walkConditionalPrimary($primary) |
|
| 1851 | |||
| 1852 | /** |
||
| 1853 | * {@inheritdoc} |
||
| 1854 | */ |
||
| 1855 | 5 | public function walkExistsExpression($existsExpr) |
|
| 1863 | |||
| 1864 | /** |
||
| 1865 | * {@inheritdoc} |
||
| 1866 | */ |
||
| 1867 | 6 | public function walkCollectionMemberExpression($collMemberExpr) |
|
| 1973 | |||
| 1974 | /** |
||
| 1975 | * {@inheritdoc} |
||
| 1976 | */ |
||
| 1977 | 2 | public function walkEmptyCollectionComparisonExpression($emptyCollCompExpr) |
|
| 1984 | |||
| 1985 | /** |
||
| 1986 | * {@inheritdoc} |
||
| 1987 | */ |
||
| 1988 | 8 | public function walkNullComparisonExpression($nullCompExpr) |
|
| 2005 | |||
| 2006 | /** |
||
| 2007 | * {@inheritdoc} |
||
| 2008 | */ |
||
| 2009 | 29 | public function walkInExpression($inExpr) |
|
| 2021 | |||
| 2022 | /** |
||
| 2023 | * {@inheritdoc} |
||
| 2024 | */ |
||
| 2025 | 7 | public function walkInstanceOfExpression($instanceOfExpr) |
|
| 2074 | |||
| 2075 | /** |
||
| 2076 | * {@inheritdoc} |
||
| 2077 | */ |
||
| 2078 | 22 | public function walkInParameter($inParam) |
|
| 2084 | |||
| 2085 | /** |
||
| 2086 | * {@inheritdoc} |
||
| 2087 | */ |
||
| 2088 | 102 | public function walkLiteral($literal) |
|
| 2104 | |||
| 2105 | /** |
||
| 2106 | * {@inheritdoc} |
||
| 2107 | */ |
||
| 2108 | 6 | public function walkBetweenExpression($betweenExpr) |
|
| 2121 | |||
| 2122 | /** |
||
| 2123 | * {@inheritdoc} |
||
| 2124 | */ |
||
| 2125 | 9 | public function walkLikeExpression($likeExpr) |
|
| 2150 | |||
| 2151 | /** |
||
| 2152 | * {@inheritdoc} |
||
| 2153 | */ |
||
| 2154 | 5 | public function walkStateFieldPathExpression($stateFieldPathExpression) |
|
| 2158 | |||
| 2159 | /** |
||
| 2160 | * {@inheritdoc} |
||
| 2161 | */ |
||
| 2162 | 164 | public function walkComparisonExpression($compExpr) |
|
| 2180 | |||
| 2181 | /** |
||
| 2182 | * {@inheritdoc} |
||
| 2183 | */ |
||
| 2184 | 99 | public function walkInputParameter($inputParam) |
|
| 2196 | |||
| 2197 | /** |
||
| 2198 | * {@inheritdoc} |
||
| 2199 | */ |
||
| 2200 | 182 | public function walkArithmeticExpression($arithmeticExpr) |
|
| 2206 | |||
| 2207 | /** |
||
| 2208 | * {@inheritdoc} |
||
| 2209 | */ |
||
| 2210 | 220 | public function walkSimpleArithmeticExpression($simpleArithmeticExpr) |
|
| 2218 | |||
| 2219 | /** |
||
| 2220 | * {@inheritdoc} |
||
| 2221 | */ |
||
| 2222 | 225 | public function walkArithmeticTerm($term) |
|
| 2238 | |||
| 2239 | /** |
||
| 2240 | * {@inheritdoc} |
||
| 2241 | */ |
||
| 2242 | 225 | public function walkArithmeticFactor($factor) |
|
| 2260 | |||
| 2261 | /** |
||
| 2262 | * Walks down an ArithmeticPrimary that represents an AST node, thereby generating the appropriate SQL. |
||
| 2263 | * |
||
| 2264 | * @param mixed $primary |
||
| 2265 | * |
||
| 2266 | * @return string The SQL. |
||
| 2267 | */ |
||
| 2268 | 225 | public function walkArithmeticPrimary($primary) |
|
| 2280 | |||
| 2281 | /** |
||
| 2282 | * {@inheritdoc} |
||
| 2283 | */ |
||
| 2284 | 12 | public function walkStringPrimary($stringPrimary) |
|
| 2290 | |||
| 2291 | /** |
||
| 2292 | * {@inheritdoc} |
||
| 2293 | */ |
||
| 2294 | 25 | public function walkResultVariable($resultVariable) |
|
| 2304 | } |
||
| 2305 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.