protected function getSQLForSelect()
{
extract($this->parts);
$query = sprintf('SELECT %s FROM ' . $from, $select ? implode(', ', $select) : '*');
foreach ($join as $j) {
$query .= sprintf(' %s JOIN %s ON %s', strtoupper($j['type']), $j['table'], (string) $j['condition']);
}
if ($where) {
$query .= ' WHERE ' . $where;
}
if ($group) {
$query .= ' GROUP BY ' . implode(', ', $group);
}
if ($having) {
$query .= ' HAVING ' . $having;
}
if ($order) {
$query .= ' ORDER BY ' . implode(', ', $order);
}
return $limit === null && $offset === null ? $query : $this->connection->getDatabasePlatform()->modifyLimitQuery($query, $limit, $offset);
}