1
0
mirror of https://github.com/dg/dibi.git synced 2025-08-06 14:16:39 +02:00

Correct limit and offset for Firebird Driver (#221)

SELECT [FIRST (<int-expr>)] [SKIP (<int-expr>)] <columns> FROM ...
This commit is contained in:
aldria
2016-05-27 03:48:06 +02:00
committed by David Grudl
parent 2571e54f3c
commit b7d84b90ef

View File

@@ -333,9 +333,9 @@ class FirebirdDriver implements Dibi\Driver, Dibi\ResultDriver, Dibi\Reflector
*/ */
public function applyLimit(& $sql, $limit, $offset) public function applyLimit(& $sql, $limit, $offset)
{ {
if ($limit >= 0 && $offset > 0) { if ($limit > 0 || $offset > 0) {
// see http://scott.yang.id.au/2004/01/limit-in-select-statements-in-firebird/ // http://www.firebirdsql.org/refdocs/langrefupd20-select.html
$sql = 'SELECT FIRST ' . (int) $limit . ($offset > 0 ? ' SKIP ' . (int) $offset : '') . ' * FROM (' . $sql . ')'; $sql = 'SELECT ' . ($limit > 0 ? 'FIRST ' . (int) $limit : '') . ($offset > 0 ? ' SKIP ' . (int) $offset : '') . ' * FROM (' . $sql . ')';
} }
} }