1
0
mirror of https://github.com/dg/dibi.git synced 2025-02-22 01:48:05 +01:00

applyLimit support

This commit is contained in:
David Grudl 2006-09-23 07:55:11 +00:00
parent da608c2db2
commit d705f4089d
8 changed files with 74 additions and 19 deletions

File diff suppressed because one or more lines are too long

View File

@ -1,5 +1,3 @@
limit/offset support for select?
1) better logging, error logging, exceptions
complete phpdoc
better logging, error logging, exceptions
2) complete phpdoc

View File

@ -176,22 +176,24 @@ class DibiMySqlDriver extends DibiDriver {
}
/*
// is this really needed?
/**
* @see DibiDriver::applyLimit()
*/
public function applyLimit(&$sql, $limit, $offset = 0)
{
if ($limit < 0 && $offset < 1) return;
// see http://dev.mysql.com/doc/refman/5.0/en/select.html
$sql .= ' LIMIT ' . ($limit < 0 ? '18446744073709551615' : (int) $limit)
. ($offset > 0 ? ' OFFSET ' . (int) $offset : '');
}
/* is this really needed?
public function getResource()
{
return $this->conn;
}
// experimental
public function applyLimit(&$sql, $offset, $limit)
{
if ($limit > 0) {
$sql .= " LIMIT " . (int) $limit . ($offset > 0 ? " OFFSET " . (int) $offset : "");
} elseif ($offset > 0) {
$sql .= " LIMIT " . $offset . ", 18446744073709551615";
}
}
*/
} // DibiMySqlDriver

View File

@ -157,6 +157,19 @@ class DibiMySqliDriver extends DibiDriver {
}
/**
* @see DibiDriver::applyLimit()
*/
public function applyLimit(&$sql, $limit, $offset = 0)
{
if ($limit < 0 && $offset < 1) return;
// see http://dev.mysql.com/doc/refman/5.0/en/select.html
$sql .= ' LIMIT ' . ($limit < 0 ? '18446744073709551615' : (int) $limit)
. ($offset > 0 ? ' OFFSET ' . (int) $offset : '');
}
} // class DibiMySqliDriver

View File

@ -153,6 +153,18 @@ class DibiOdbcDriver extends DibiDriver {
trigger_error('Meta is not implemented yet.', E_USER_WARNING);
}
/**
* @see DibiDriver::applyLimit()
*/
public function applyLimit(&$sql, $limit, $offset = 0)
{
// offset suppot is missing...
if ($limit >= 0)
$sql = 'SELECT TOP ' . (int) $limit . ' * FROM (' . $sql . ')';
}
} // class DibiOdbcDriver

View File

@ -148,6 +148,19 @@ class DibiPostgreDriver extends DibiDriver {
/**
* @see DibiDriver::applyLimit()
*/
public function applyLimit(&$sql, $limit, $offset = 0)
{
if ($limit >= 0)
$sql .= ' LIMIT ' . (int) $limit;
if ($offset > 0)
$sql .= ' OFFSET ' . (int) $offset;
}
} // class DibiPostgreDriver

View File

@ -148,6 +148,15 @@ class DibiSqliteDriver extends DibiDriver {
/**
* @see DibiDriver::applyLimit()
*/
public function applyLimit(&$sql, $limit, $offset = 0)
{
if ($limit < 0 && $offset < 1) return;
$sql .= ' LIMIT ' . $limit . ($offset > 0 ? ' OFFSET ' . (int) $offset : '');
}
} // class DibiSqliteDriver

View File

@ -142,7 +142,6 @@ abstract class DibiDriver
/**
* Gets a information of the current database.
*
@ -151,5 +150,14 @@ abstract class DibiDriver
abstract public function getMetaData();
/**
* Experimental - injects LIMIT/OFFSET to the SQL query
* @param string &$sql The SQL query that will be modified.
* @param int $limit
* @param int $offset
* @return void
*/
abstract public function applyLimit(&$sql, $limit, $offset = 0);
} // class DibiDriver