| Total Complexity | 20 |
| Total Lines | 95 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 11 | class PostgreSQLQueryBuilder extends DBQueryBuilder |
||
| 12 | { |
||
| 13 | /** |
||
| 14 | * Max table length. |
||
| 15 | * Aliases longer than this will be re-written |
||
| 16 | */ |
||
| 17 | const MAX_TABLE = 63; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * Return the LIMIT clause ready for inserting into a query. |
||
| 21 | * |
||
| 22 | * @param SQLSelect $query The expression object to build from |
||
| 23 | * @param array $parameters Out parameter for the resulting query parameters |
||
| 24 | * @return string The finalised limit SQL fragment |
||
| 25 | */ |
||
| 26 | public function buildLimitFragment(SQLSelect $query, array &$parameters) |
||
| 27 | { |
||
| 28 | $nl = $this->getSeparator(); |
||
| 29 | |||
| 30 | // Ensure limit is given |
||
| 31 | $limit = $query->getLimit(); |
||
| 32 | if (empty($limit)) { |
||
| 33 | return ''; |
||
| 34 | } |
||
| 35 | |||
| 36 | // For literal values return this as the limit SQL |
||
| 37 | if (! is_array($limit)) { |
||
|
|
|||
| 38 | return "{$nl}LIMIT $limit"; |
||
| 39 | } |
||
| 40 | |||
| 41 | // Assert that the array version provides the 'limit' key |
||
| 42 | if (! array_key_exists('limit', $limit) || ($limit['limit'] !== null && ! is_numeric($limit['limit']))) { |
||
| 43 | throw new InvalidArgumentException( |
||
| 44 | 'DBQueryBuilder::buildLimitSQL(): Wrong format for $limit: '. var_export($limit, true) |
||
| 45 | ); |
||
| 46 | } |
||
| 47 | |||
| 48 | if ($limit['limit'] === null) { |
||
| 49 | $limit['limit'] = 'ALL'; |
||
| 50 | } |
||
| 51 | |||
| 52 | $clause = "{$nl}LIMIT {$limit['limit']}"; |
||
| 53 | if (isset($limit['start']) && is_numeric($limit['start']) && $limit['start'] !== 0) { |
||
| 54 | $clause .= " OFFSET {$limit['start']}"; |
||
| 55 | } |
||
| 56 | return $clause; |
||
| 57 | } |
||
| 58 | |||
| 59 | public function buildSQL(SQLExpression $query, &$parameters) |
||
| 63 | } |
||
| 64 | |||
| 65 | /** |
||
| 66 | * Find and generate table aliases necessary in the given query |
||
| 67 | * |
||
| 68 | * @param SQLConditionalExpression $query |
||
| 69 | * @return array List of replacements |
||
| 70 | */ |
||
| 71 | protected function findRewrites(SQLConditionalExpression $query) |
||
| 87 | } |
||
| 88 | |||
| 89 | /** |
||
| 90 | * Rewrite all ` AS "Identifier"` with strlen(Identifier) > 63 |
||
| 91 | * |
||
| 92 | * @param SQLExpression $query |
||
| 93 | * @param string $sql |
||
| 94 | * @return string |
||
| 95 | */ |
||
| 96 | protected function rewriteLongIdentifiers(SQLExpression $query, $sql) |
||
| 108 |