diff --git a/dibi/drivers/mssql.php b/dibi/drivers/mssql.php index 412ac5d7..374d6107 100644 --- a/dibi/drivers/mssql.php +++ b/dibi/drivers/mssql.php @@ -247,7 +247,7 @@ class DibiMsSqlDriver extends DibiObject implements IDibiDriver */ public function applyLimit(&$sql, $limit, $offset) { - // offset suppot is missing... + // offset support is missing if ($limit >= 0) { $sql = 'SELECT TOP ' . (int) $limit . ' * FROM (' . $sql . ')'; } diff --git a/dibi/drivers/odbc.php b/dibi/drivers/odbc.php index 2950a747..cf392186 100644 --- a/dibi/drivers/odbc.php +++ b/dibi/drivers/odbc.php @@ -257,7 +257,7 @@ class DibiOdbcDriver extends DibiObject implements IDibiDriver */ public function applyLimit(&$sql, $limit, $offset) { - // offset suppot is missing... + // offset support is missing if ($limit >= 0) { $sql = 'SELECT TOP ' . (int) $limit . ' * FROM (' . $sql . ')'; } diff --git a/dibi/drivers/pdo.php b/dibi/drivers/pdo.php index c919552a..2e60265c 100644 --- a/dibi/drivers/pdo.php +++ b/dibi/drivers/pdo.php @@ -305,7 +305,36 @@ class DibiPdoDriver extends DibiObject implements IDibiDriver */ public function applyLimit(&$sql, $limit, $offset) { - throw new NotSupportedException('PDO does not support applying limit or offset.'); + if ($limit < 0 && $offset < 1) return; + + switch ($this->connection->getAttribute(PDO::ATTR_DRIVER_NAME)) { + case 'mysql': + $sql .= ' LIMIT ' . ($limit < 0 ? '18446744073709551615' : (int) $limit) + . ($offset > 0 ? ' OFFSET ' . (int) $offset : ''); + break; + + case 'pgsql': + if ($limit >= 0) $sql .= ' LIMIT ' . (int) $limit; + if ($offset > 0) $sql .= ' OFFSET ' . (int) $offset; + break; + + case 'sqlite': + case 'sqlite2': + case 'oci': + $sql .= ' LIMIT ' . $limit . ($offset > 0 ? ' OFFSET ' . (int) $offset : ''); + break; + + case 'odbc': + case 'mssql': + if ($offset < 1) { + $sql = 'SELECT TOP ' . (int) $limit . ' * FROM (' . $sql . ')'; + break; + } + // intentionally break omitted + + default: + throw new NotSupportedException('PDO or driver does not support applying limit or offset.'); + } } diff --git a/dibi/libs/DibiProfiler.php b/dibi/libs/DibiProfiler.php index 11ed7702..e58d54ac 100644 --- a/dibi/libs/DibiProfiler.php +++ b/dibi/libs/DibiProfiler.php @@ -133,7 +133,6 @@ class DibiProfiler extends DibiObject implements IDibiProfiler header("X-Wf-dibi-1-1-d$num: |$s|\\"); // protocol-, structure-, plugin-, message-index } header("X-Wf-dibi-1-1-d$num: |$s|"); - header("X-Wf-dibi-Index: d$num"); } if ($this->file) {