@@ -56,7 +56,8 @@ discard block |
||
| 56 | 56 | if (($pos = strrpos($name, '.')) !== false) { |
| 57 | 57 | $prefix = $this->quoteTableName(substr($name, 0, $pos)) . '.'; |
| 58 | 58 | $name = substr($name, $pos + 1); |
| 59 | - } else { |
|
| 59 | + } |
|
| 60 | + else { |
|
| 60 | 61 | $prefix = ''; |
| 61 | 62 | } |
| 62 | 63 | return $prefix . $this->quoteSimpleColumnName($name); |
@@ -134,13 +135,17 @@ discard block |
||
| 134 | 135 | { |
| 135 | 136 | if ($value instanceof IToSql) { |
| 136 | 137 | return $value->toSql(); |
| 137 | - } else if ($value === true || strtolower($value) === 'true') { |
|
| 138 | + } |
|
| 139 | + else if ($value === true || strtolower($value) === 'true') { |
|
| 138 | 140 | return 'TRUE'; |
| 139 | - } else if ($value === false || strtolower($value) === 'false') { |
|
| 141 | + } |
|
| 142 | + else if ($value === false || strtolower($value) === 'false') { |
|
| 140 | 143 | return 'FALSE'; |
| 141 | - } else if ($value === null || strtolower($value) === 'null') { |
|
| 144 | + } |
|
| 145 | + else if ($value === null || strtolower($value) === 'null') { |
|
| 142 | 146 | return 'NULL'; |
| 143 | - } else if (is_string($value) && $driver = $this->getDriver()) { |
|
| 147 | + } |
|
| 148 | + else if (is_string($value) && $driver = $this->getDriver()) { |
|
| 144 | 149 | return $driver->quote($value); |
| 145 | 150 | } |
| 146 | 151 | |
@@ -213,7 +218,8 @@ discard block |
||
| 213 | 218 | { |
| 214 | 219 | if ($rawValue === true || $rawValue === false || $rawValue === 'true' || $rawValue === 'false') { |
| 215 | 220 | return $this->getBoolean($rawValue); |
| 216 | - } else if ($rawValue === 'null' || $rawValue === null) { |
|
| 221 | + } |
|
| 222 | + else if ($rawValue === 'null' || $rawValue === null) { |
|
| 217 | 223 | return 'NULL'; |
| 218 | 224 | } |
| 219 | 225 | return $rawValue; |
@@ -267,7 +273,8 @@ discard block |
||
| 267 | 273 | foreach ($columns as $i => $column) { |
| 268 | 274 | if ($column instanceof Expression) { |
| 269 | 275 | $columns[$i] = $column->toSQL(); |
| 270 | - } else if (strpos($column, '(') === false) { |
|
| 276 | + } |
|
| 277 | + else if (strpos($column, '(') === false) { |
|
| 271 | 278 | $columns[$i] = $this->quoteColumn($column); |
| 272 | 279 | } |
| 273 | 280 | } |
@@ -417,12 +424,14 @@ discard block |
||
| 417 | 424 | foreach ($columns as $name => $type) { |
| 418 | 425 | if (is_string($name)) { |
| 419 | 426 | $cols[] = "\t" . $this->quoteColumn($name) . ' ' . $type; |
| 420 | - } else { |
|
| 427 | + } |
|
| 428 | + else { |
|
| 421 | 429 | $cols[] = "\t" . $type; |
| 422 | 430 | } |
| 423 | 431 | } |
| 424 | 432 | $sql = ($ifNotExists ? "CREATE TABLE IF NOT EXISTS " : "CREATE TABLE ") . $this->quoteTableName($tableName) . " (\n" . implode(",\n", $cols) . "\n)"; |
| 425 | - } else { |
|
| 433 | + } |
|
| 434 | + else { |
|
| 426 | 435 | $sql = ($ifNotExists ? "CREATE TABLE IF NOT EXISTS " : "CREATE TABLE ") . $this->quoteTableName($tableName) . " " . $this->quoteSql($columns); |
| 427 | 436 | } |
| 428 | 437 | return empty($options) ? $sql : $sql . ' ' . $options; |
@@ -472,11 +481,14 @@ discard block |
||
| 472 | 481 | { |
| 473 | 482 | if ($value === 'true' || $value === true) { |
| 474 | 483 | return 'TRUE'; |
| 475 | - } else if ($value === null || $value === 'null') { |
|
| 484 | + } |
|
| 485 | + else if ($value === null || $value === 'null') { |
|
| 476 | 486 | return 'NULL'; |
| 477 | - } else if ($value === false || $value === 'false') { |
|
| 487 | + } |
|
| 488 | + else if ($value === false || $value === 'false') { |
|
| 478 | 489 | return 'FALSE'; |
| 479 | - } else { |
|
| 490 | + } |
|
| 491 | + else { |
|
| 480 | 492 | return $value; |
| 481 | 493 | } |
| 482 | 494 | } |
@@ -604,12 +616,14 @@ discard block |
||
| 604 | 616 | foreach ($tables as $tableAlias => $table) { |
| 605 | 617 | if ($table instanceof QueryBuilder) { |
| 606 | 618 | $tableRaw = $table->toSQL(); |
| 607 | - } else { |
|
| 619 | + } |
|
| 620 | + else { |
|
| 608 | 621 | $tableRaw = $this->getRawTableName($table); |
| 609 | 622 | } |
| 610 | 623 | if (strpos($tableRaw, 'SELECT') !== false) { |
| 611 | 624 | $quotedTableNames[] = '(' . $tableRaw . ')' . (is_numeric($tableAlias) ? '' : ' AS ' . $this->quoteTableName($tableAlias)); |
| 612 | - } else { |
|
| 625 | + } |
|
| 626 | + else { |
|
| 613 | 627 | $quotedTableNames[] = $this->quoteTableName($tableRaw) . (is_numeric($tableAlias) ? '' : ' AS ' . $this->quoteTableName($tableAlias)); |
| 614 | 628 | } |
| 615 | 629 | } |
@@ -630,12 +644,15 @@ discard block |
||
| 630 | 644 | if (is_string($tableName) && $tableName = $this->getRawTableName($tableName)) { |
| 631 | 645 | if (strpos($tableName, 'SELECT') !== false) { |
| 632 | 646 | $toSql[] = '(' . $this->quoteSql($tableName) . ')' ; |
| 633 | - } else { |
|
| 647 | + } |
|
| 648 | + else { |
|
| 634 | 649 | $toSql[] = $this->quoteTableName($tableName); |
| 635 | 650 | } |
| 636 | - } else if ($tableName instanceof QueryBuilder) { |
|
| 651 | + } |
|
| 652 | + else if ($tableName instanceof QueryBuilder) { |
|
| 637 | 653 | $toSql[] = '(' . $this->quoteSql($tableName->toSQL()) . ')' ; |
| 638 | - } else { |
|
| 654 | + } |
|
| 655 | + else { |
|
| 639 | 656 | throw new QBException('Incorrect table name'); |
| 640 | 657 | } |
| 641 | 658 | |
@@ -647,11 +664,13 @@ discard block |
||
| 647 | 664 | $onSQL = []; |
| 648 | 665 | if (is_string($on)) { |
| 649 | 666 | $onSQL[] = $this->quoteSql($on); |
| 650 | - } else { |
|
| 667 | + } |
|
| 668 | + else { |
|
| 651 | 669 | foreach ($on as $leftColumn => $rightColumn) { |
| 652 | 670 | if ($rightColumn instanceof Expression) { |
| 653 | 671 | $onSQL[] = $this->quoteColumn($leftColumn) . '=' . $this->quoteSql($rightColumn->toSQL()); |
| 654 | - } else { |
|
| 672 | + } |
|
| 673 | + else { |
|
| 655 | 674 | $onSQL[] = $this->quoteColumn($leftColumn) . '=' . $this->quoteColumn($rightColumn); |
| 656 | 675 | } |
| 657 | 676 | } |
@@ -691,7 +710,8 @@ discard block |
||
| 691 | 710 | $sql = $having |
| 692 | 711 | ->setQb($queryBuilder) |
| 693 | 712 | ->toSql(); |
| 694 | - } else { |
|
| 713 | + } |
|
| 714 | + else { |
|
| 695 | 715 | $sql = $this->quoteSql($having); |
| 696 | 716 | } |
| 697 | 717 | |
@@ -711,7 +731,8 @@ discard block |
||
| 711 | 731 | |
| 712 | 732 | if ($union instanceof QueryBuilderInterface) { |
| 713 | 733 | $unionSQL = $union->setOrder(null)->toSQL(); |
| 714 | - } else { |
|
| 734 | + } |
|
| 735 | + else { |
|
| 715 | 736 | $unionSQL = $this->quoteSql($union); |
| 716 | 737 | } |
| 717 | 738 | |
@@ -182,7 +182,8 @@ discard block |
||
| 182 | 182 | $types = [static::TYPE_INSERT, static::TYPE_UPDATE, static::TYPE_DELETE, static::TYPE_SELECT]; |
| 183 | 183 | if (in_array($type, $types, true)) { |
| 184 | 184 | $this->_type = $type; |
| 185 | - } else { |
|
| 185 | + } |
|
| 186 | + else { |
|
| 186 | 187 | throw new QBException('Incorrect type'); |
| 187 | 188 | } |
| 188 | 189 | |
@@ -255,12 +256,15 @@ discard block |
||
| 255 | 256 | if ($newSelect === false) { |
| 256 | 257 | if ($tableAlias === null || $rawColumn === '*') { |
| 257 | 258 | $columns = $rawColumn; |
| 258 | - } elseif (strpos($rawColumn, '.') !== false) { |
|
| 259 | + } |
|
| 260 | + elseif (strpos($rawColumn, '.') !== false) { |
|
| 259 | 261 | $columns = $rawColumn; |
| 260 | - } else { |
|
| 262 | + } |
|
| 263 | + else { |
|
| 261 | 264 | $columns = $tableAlias . '.' . $rawColumn; |
| 262 | 265 | } |
| 263 | - } else { |
|
| 266 | + } |
|
| 267 | + else { |
|
| 264 | 268 | list($alias, $joinColumn) = $newSelect; |
| 265 | 269 | $columns = $alias . '.' . $joinColumn; |
| 266 | 270 | } |
@@ -286,17 +290,21 @@ discard block |
||
| 286 | 290 | foreach ($this->_select as $alias => $column) { |
| 287 | 291 | if ($column instanceof Aggregation) { |
| 288 | 292 | $select[$alias] = $this->buildSelectFromAggregation($column); |
| 289 | - } else if (is_string($column)) { |
|
| 293 | + } |
|
| 294 | + else if (is_string($column)) { |
|
| 290 | 295 | if (strpos($column, 'SELECT') !== false) { |
| 291 | 296 | $select[$alias] = $column; |
| 292 | - } else { |
|
| 297 | + } |
|
| 298 | + else { |
|
| 293 | 299 | $select[$alias] = $this->addColumnAlias($builder->fetchColumnName($column)); |
| 294 | 300 | } |
| 295 | - } else { |
|
| 301 | + } |
|
| 302 | + else { |
|
| 296 | 303 | $select[$alias] = $column; |
| 297 | 304 | } |
| 298 | 305 | } |
| 299 | - } else if (is_string($this->_select)) { |
|
| 306 | + } |
|
| 307 | + else if (is_string($this->_select)) { |
|
| 300 | 308 | $select = $this->addColumnAlias($this->_select); |
| 301 | 309 | } |
| 302 | 310 | return $this->getAdapter()->sqlSelect($select, $this->_queryOptions); |
@@ -316,7 +324,8 @@ discard block |
||
| 316 | 324 | |
| 317 | 325 | if ($alias) { |
| 318 | 326 | $this->_select[$alias] = $select; |
| 319 | - } else { |
|
| 327 | + } |
|
| 328 | + else { |
|
| 320 | 329 | $this->_select[] = $select; |
| 321 | 330 | } |
| 322 | 331 | |
@@ -333,9 +342,11 @@ discard block |
||
| 333 | 342 | if (is_string($select) && $newSelect = $this->getLookupBuilder()->buildJoin($this, $select)) { |
| 334 | 343 | list($t_alias, $column) = $newSelect; |
| 335 | 344 | $this->pushToSelect($t_alias . '.' . $column, $alias); |
| 336 | - } else if ($select instanceof IToSql) { |
|
| 345 | + } |
|
| 346 | + else if ($select instanceof IToSql) { |
|
| 337 | 347 | $this->pushToSelect($select->setQb($this), $alias); |
| 338 | - } else { |
|
| 348 | + } |
|
| 349 | + else { |
|
| 339 | 350 | $this->pushToSelect($select, $alias); |
| 340 | 351 | } |
| 341 | 352 | |
@@ -358,7 +369,8 @@ discard block |
||
| 358 | 369 | foreach ($select as $key => $part) { |
| 359 | 370 | $this->addSelect($part, $key); |
| 360 | 371 | } |
| 361 | - } else { |
|
| 372 | + } |
|
| 373 | + else { |
|
| 362 | 374 | $this->addSelect($select); |
| 363 | 375 | } |
| 364 | 376 | |
@@ -472,10 +484,12 @@ discard block |
||
| 472 | 484 | { |
| 473 | 485 | if ($tableName instanceof QueryBuilderInterface) { |
| 474 | 486 | $this->_join[] = $this->getAdapter()->sqlJoin($joinType, $tableName, $on, $alias, $index); |
| 475 | - } else { |
|
| 487 | + } |
|
| 488 | + else { |
|
| 476 | 489 | if ($joinType === 'RAW' && !empty($tableName)) { |
| 477 | 490 | $join = $this->getAdapter()->quoteSql($tableName); |
| 478 | - } else { |
|
| 491 | + } |
|
| 492 | + else { |
|
| 479 | 493 | $join = $this->getAdapter()->sqlJoin($joinType, $tableName, $on, $alias); |
| 480 | 494 | } |
| 481 | 495 | |
@@ -547,7 +561,8 @@ discard block |
||
| 547 | 561 | foreach ($columns as $column) { |
| 548 | 562 | $this->addOrder($column); |
| 549 | 563 | } |
| 550 | - } else { |
|
| 564 | + } |
|
| 565 | + else { |
|
| 551 | 566 | $this->addOrder($columns); |
| 552 | 567 | } |
| 553 | 568 | |
@@ -581,11 +596,13 @@ discard block |
||
| 581 | 596 | } |
| 582 | 597 | |
| 583 | 598 | $this->_order[] = $_column; |
| 584 | - } else { |
|
| 599 | + } |
|
| 600 | + else { |
|
| 585 | 601 | $this->_order[] = current($temp); |
| 586 | 602 | } |
| 587 | 603 | } |
| 588 | - } else { |
|
| 604 | + } |
|
| 605 | + else { |
|
| 589 | 606 | $this->_order[] = $column; |
| 590 | 607 | } |
| 591 | 608 | |
@@ -674,14 +691,18 @@ discard block |
||
| 674 | 691 | if (is_numeric($key)) { |
| 675 | 692 | if ($value instanceof IToSql) { |
| 676 | 693 | $parts[] = $this->parseCondition($value, $operator); |
| 677 | - } elseif ($value instanceof QueryBuilder) { |
|
| 694 | + } |
|
| 695 | + elseif ($value instanceof QueryBuilder) { |
|
| 678 | 696 | $parts[] = $this->parseCondition($value, $operator); |
| 679 | - } else if (is_array($value)) { |
|
| 697 | + } |
|
| 698 | + else if (is_array($value)) { |
|
| 680 | 699 | $parts[] = $this->parseCondition($value, $operator); |
| 681 | - } else if (is_string($value)) { |
|
| 700 | + } |
|
| 701 | + else if (is_string($value)) { |
|
| 682 | 702 | $parts[] = $value; |
| 683 | 703 | } |
| 684 | - } else { |
|
| 704 | + } |
|
| 705 | + else { |
|
| 685 | 706 | $tableAlias = $this->getAlias(); |
| 686 | 707 | $value = $this->getAdapter()->prepareValue($value); |
| 687 | 708 | |
@@ -702,13 +723,16 @@ discard block |
||
| 702 | 723 | return '(' . implode(') ' . $operator . ' (', $parts) . ')'; |
| 703 | 724 | } |
| 704 | 725 | |
| 705 | - } else if ($condition instanceof IToSql) { |
|
| 726 | + } |
|
| 727 | + else if ($condition instanceof IToSql) { |
|
| 706 | 728 | return $condition |
| 707 | 729 | ->setQb($this) |
| 708 | 730 | ->toSql(); |
| 709 | - } else if ($condition instanceof QueryBuilder) { |
|
| 731 | + } |
|
| 732 | + else if ($condition instanceof QueryBuilder) { |
|
| 710 | 733 | return $condition->toSQL(); |
| 711 | - } else if (is_string($condition)) { |
|
| 734 | + } |
|
| 735 | + else if (is_string($condition)) { |
|
| 712 | 736 | return $condition; |
| 713 | 737 | } |
| 714 | 738 | |
@@ -721,7 +745,8 @@ discard block |
||
| 721 | 745 | foreach ($operands as $operand) { |
| 722 | 746 | if (is_array($operand)) { |
| 723 | 747 | $operand = $this->buildCondition($operand, $params); |
| 724 | - } else { |
|
| 748 | + } |
|
| 749 | + else { |
|
| 725 | 750 | $operand = $this->parseCondition($operand); |
| 726 | 751 | } |
| 727 | 752 | if ($operand !== '') { |
@@ -782,7 +807,8 @@ discard block |
||
| 782 | 807 | foreach ($this->_whereAnd as $condition) { |
| 783 | 808 | if (empty($where)) { |
| 784 | 809 | $where = ['and', $condition]; |
| 785 | - } else { |
|
| 810 | + } |
|
| 811 | + else { |
|
| 786 | 812 | $where = ['and', $where, ['and', $condition]]; |
| 787 | 813 | } |
| 788 | 814 | } |
@@ -790,7 +816,8 @@ discard block |
||
| 790 | 816 | foreach ($this->_whereOr as $condition) { |
| 791 | 817 | if (empty($where)) { |
| 792 | 818 | $where = ['or', $condition]; |
| 793 | - } else { |
|
| 819 | + } |
|
| 820 | + else { |
|
| 794 | 821 | $where = ['or', $where, ['and', $condition]]; |
| 795 | 822 | } |
| 796 | 823 | } |
@@ -1115,7 +1142,8 @@ discard block |
||
| 1115 | 1142 | { |
| 1116 | 1143 | if (strpos($order, '-') === false) { |
| 1117 | 1144 | $direction = 'ASC'; |
| 1118 | - } else { |
|
| 1145 | + } |
|
| 1146 | + else { |
|
| 1119 | 1147 | $direction = 'DESC'; |
| 1120 | 1148 | $order = substr($order, 1); |
| 1121 | 1149 | } |
@@ -1152,12 +1180,14 @@ discard block |
||
| 1152 | 1180 | } |
| 1153 | 1181 | else if ($column === '?') { |
| 1154 | 1182 | $order[] = $this->getAdapter()->getRandomOrder(); |
| 1155 | - } else { |
|
| 1183 | + } |
|
| 1184 | + else { |
|
| 1156 | 1185 | list($newColumn, $direction) = $this->buildOrderJoin($column); |
| 1157 | 1186 | $order[$this->applyTableAlias($newColumn)] = $direction; |
| 1158 | 1187 | } |
| 1159 | 1188 | } |
| 1160 | - } else { |
|
| 1189 | + } |
|
| 1190 | + else { |
|
| 1161 | 1191 | $order[] = $this->buildOrderJoin($this->_order); |
| 1162 | 1192 | } |
| 1163 | 1193 | |
@@ -1204,7 +1234,8 @@ discard block |
||
| 1204 | 1234 | { |
| 1205 | 1235 | if ($this->_alias !== null && !is_array($this->_from)) { |
| 1206 | 1236 | $from = [$this->_alias => $this->_from]; |
| 1207 | - } else { |
|
| 1237 | + } |
|
| 1238 | + else { |
|
| 1208 | 1239 | $from = $this->_from; |
| 1209 | 1240 | } |
| 1210 | 1241 | $sql = $this->getAdapter()->sqlFrom($from); |