PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » HTML » Pager » Bug #7127

problem with rewriteCountQuery function

Details

Submitted2006-03-15 09:15 UTC
Fromveneoth at gmail dot com
Assignedquipo
StatusClosed
PackagePager
PHP VersionIrrelevant
Roadmaps(Not assigned)

Comments

[2006-03-15 09:15 UTC] veneoth at gmail dot com

Description:
------------
the bug is in file: Pager_Wrapper.php, in function rewriteCountQuery()

replace, used for replacing everything before "FROM" statemant isn't working with some complex queries, that i use im my application

example below

it would be nice if you coud wrote a preg_replace pattern that would replace everything before "FROM", but only if "FROM" isn't enclosed in parentheses

Test script:
---------------
$sql = 'SELECT `id`, `ip`, (
SELECT TIMEDIFF(MAX(P.`time`), MIN(P.`time`))
FROM `przejscia` as P
WHERE P.`id_wejscia`=W.`id`
) as `czas`
FROM `wejscia` as W
WHERE W.id_domeny=?
ORDER BY W.czas_wejscia DESC
';
$queryCount = preg_replace('/^(?:.*)\bFROM\b\s+/Uims', 'SELECT COUNT(*) FROM ', $sql, 1);
echo $queryCount;

Expected result:
----------------
SELECT COUNT(*)
FROM `wejscia` as W
WHERE W.id_domeny=?
ORDER BY W.czas_wejscia DESC

Actual result:
--------------
SELECT COUNT(*)
FROM `przejscia` as P
WHERE P.`id_wejscia`=W.`id`
) as `czas`
FROM `wejscia` as W
WHERE W.id_domeny=?