Re: [rfc] Row limit support for Pear DB
| From: | John Lim | Date: | Wed, 31 Oct 2001 16:03:23 +0000 |
| Subject: | Re: [rfc] Row limit support for Pear DB | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-2486@lists.php.net to get a copy of this message | ||
Tomas V.V.Cox <cox@idecnet.com> wrote in message
news:3BDF377D.B496D8BD@idecnet.com...
>
> ## 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);
>
Hi Tomas,
As 60-70% of PHP programmers use mysql/postgresql, I think that using
limitQuery($selectSql, $limit, $offset)
is more natural. Also since only selects are supported, I suggest calling
it limitSelect().
> $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
>
Personally I'm not keen on this - the first row returned should be 1 and
not 25 in the above example as getRowCounter() just adds complexity.
Just store the offset and limit in DB_Result and let the users read the
values from there if they need getRowCounter() equivalents.
Using fetchRow() and fetchInto() is nice in my opinion because a smaller API
means that people can switch sql without switching fetch API's. Also there
is no loss in speed if implemented carefully.
> ## Planed Support ##
>
> mysql -> altering query
> pgsql -> altering query
> oci8 -> altering query
I didn't know Oracle supported this. I am interested
in this - what's the sql syntax?
> ibase -> unsupported
> rest -> emulated with the fetch row by number feature
> (Note: for the last two I'll be glad to hear better ideas)
Store data in a disconnected recordset like Cache_DB's and
emulate using it.
>
> This feature is limited to SELECT statements
>
>
> Tomas V.V.Cox