/** * Generates the LIMIT part of a SQL query * * @param int $limit the limit clause * @param Query $query The query that is being compiled * @return string */ protected function _buildLimitPart(int $limit, Query $query) : string { if ($limit === null || $query->clause('offset') === null) { return ''; } return sprintf(' FETCH FIRST %d ROWS ONLY', $limit); }
/** * Helper function used to build the string representation of a SELECT clause, * it constructs the field list taking care of aliasing and * converting expression objects to string. This function also constructs the * DISTINCT clause for the query. * * @param array $parts list of fields to be transformed to string * @param Query $query The query that is being compiled * @param ValueBinder $generator the placeholder generator to be used in expressions * @return string */ protected function _buildSelectPart(array $parts, Query $query, ValueBinder $generator) : string { $select = 'SELECT %s%s%s'; if ($this->_orderedUnion && $query->clause('union')) { $select = '(SELECT %s%s%s'; } $distinct = $query->clause('distinct'); $modifiers = $query->clause('modifier') ?: null; $normalized = []; $parts = $this->_stringifyExpressions($parts, $generator); foreach ($parts as $k => $p) { if (!is_numeric($k)) { $p = $p . ' AS ' . "`{$k}`"; } $normalized[] = $p; } if ($distinct === true) { $distinct = 'DISTINCT '; } if (is_array($distinct)) { $distinct = $this->_stringifyExpressions($distinct, $generator); $distinct = sprintf('DISTINCT ON (%s) ', implode(', ', $distinct)); } if ($modifiers !== null) { $modifiers = $this->_stringifyExpressions($modifiers, $generator); $modifiers = implode(' ', $modifiers) . ' '; } return sprintf($select, $distinct, $modifiers, implode(', ', $normalized)); }