[rfc] Row limit support for Pear DB
| From: | Tomas V.V.Cox | Date: | Tue, 30 Oct 2001 23:27:57 +0000 |
| Subject: | [rfc] Row limit support for Pear DB | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-2468@lists.php.net to get a copy of this message | ||
Hi,
Definetly we need that and want/need to implement it :). Here are my
ideas:
## Proto ##
// Modify the query and launch it when needed
(object) DB_"driver"::limitQuery(string $query, int $from, int $to);
// Simply launch the query
(object) DB_common::limitQuery(string $query, int $from, int $to);
$from => row to start from
$to => last row to fetch
// The DB Result interface to the native functions
// and maintain the internal counter
(array) DB_result::fetchRowByLimit([int $fetchmode]);
// Maintains a internal counter of the last fetched row
(int) DB_result::getRowCounter();
// For drivers who supports "limit" somehow
// simple fetch all the rows
(array) DB_"driver"::fetchRowByLimit($to, $from, $current);
// For some drivers emulate this feature with fetch row by number
(array) DB_common::fetchRowByLimit($to, $from, $current);
(Note1: please propose other method names)
(Note2: sacrificing some speed in normal fetchs, this thing could be
integrated into the actual methods fetchRow and fetchInto)
## Usage ##
$res = $dbh->limitQuery($query, 25, 50);
while ($row = $res->fetchRowByLimit($mode) {
echo $res->getRowCounter();
echo '.- ' . $row['name'] . "\n";
}
Outputs:
25.- Peter
26.- Foo
..
50.- Bar
## Planed Support ##
mysql -> altering query
pgsql -> altering query
oci8 -> altering query
ibase -> unsupported
rest -> emulated with the fetch row by number feature
(Note: for the last two I'll be glad to hear better ideas)
This feature is limited to SELECT statements
Tomas V.V.Cox