PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Database » DB » Bug #4649

MSSQL: numRows() returns wrong result for limitQuery()

Details

Submitted2005-06-21 14:18 UTC
Fromaleksander dot kmetec at gmail dot com
Assignedaharvey
StatusClosed
PackageDB
PHP Version5.0.4
OSFedora core 3
Roadmaps(Not assigned)

Comments

[2005-06-21 14:18 UTC] aleksander dot kmetec at gmail dot com

Description:
------------
When running a query using limitQuery(), the result object returns wrong number of rows, even with DB_PORTABILITY_NUMROWS enabled. This problem exists with MSSQL driver only.

Reproduce code:
---------------
$db = DB::connect("mssql://testuser:testpass@hostname/testdb");
$db->setOption('portability', DB_PORTABILITY_NUMROWS);

/* test table & data */
$db->query("CREATE TABLE test_1 (id INTEGER NOT NULL, foo VARCHAR(20))");
$db->query("INSERT INTO test_1 VALUES (1, 'foo')");
$db->query("INSERT INTO test_1 VALUES (2, 'bar')");
$db->query("INSERT INTO test_1 VALUES (3, 'baz')");
$db->query("INSERT INTO test_1 VALUES (4, 'quux')");

/* limit result to 2 rows */
$data = $db->limitQuery("SELECT * FROM test_1", 1, 2);

/* this should print 2, but prints 4 instead */
echo "numRows: ".$data->numRows()."<br />\n";

/* this fetches 2 rows (ok) */
while ($row = $data->fetchRow(DB_FETCHMODE_OBJECT)) {
print_r($row);
echo "<br />";
}

/* clean-up */
$db->query("DROP TABLE test_1");

Expected result:
----------------
expected $data->numRows() to return 2

Actual result:
--------------
$data->numRows() to returns 4

[2005-12-01 17:08 UTC] miguelanxo at telefonica dot net

The simplest testcase

$res =& $db->limitQuery ("SELECT * FROM TABLE", 0, 100);
echo $numRows();

if TABLE constains more than 100 rows (mine has 6500), numRows() will return the full number of rows.