1
0
mirror of https://github.com/dg/dibi.git synced 2025-08-05 13:47:33 +02:00

- implemented applyLimit() in PDO driver

This commit is contained in:
David Grudl
2008-11-07 10:47:57 +00:00
parent d08a5d3856
commit 9f8b19f1fb
4 changed files with 32 additions and 4 deletions

View File

@@ -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 . ')';
}

View File

@@ -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 . ')';
}

View File

@@ -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.');
}
}

View File

@@ -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) {