| 1 |
lars |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/**
|
|
|
4 |
* Tests the drivers' limitQuery() method
|
|
|
5 |
*
|
|
|
6 |
* Executed by driver/13limit.phpt
|
|
|
7 |
*
|
|
|
8 |
* PHP versions 4 and 5
|
|
|
9 |
*
|
|
|
10 |
* LICENSE: This source file is subject to version 3.0 of the PHP license
|
|
|
11 |
* that is available through the world-wide-web at the following URI:
|
|
|
12 |
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
|
|
|
13 |
* the PHP License and are unable to obtain it through the web, please
|
|
|
14 |
* send a note to license@php.net so we can mail you a copy immediately.
|
|
|
15 |
*
|
|
|
16 |
* @category Database
|
|
|
17 |
* @package DB
|
|
|
18 |
* @author Daniel Convissor <danielc@php.net>
|
|
|
19 |
* @copyright 1997-2007 The PHP Group
|
|
|
20 |
* @license http://www.php.net/license/3_0.txt PHP License 3.0
|
|
|
21 |
* @version $Id: limit.inc 239211 2007-07-06 05:19:21Z aharvey $
|
|
|
22 |
* @link http://pear.php.net/package/DB
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
error_reporting(E_ALL);
|
|
|
26 |
|
|
|
27 |
/**
|
|
|
28 |
* Local error callback handler
|
|
|
29 |
*
|
|
|
30 |
* Drops the phptest table, prints out an error message and kills the
|
|
|
31 |
* process.
|
|
|
32 |
*
|
|
|
33 |
* @param object $o PEAR error object automatically passed to this method
|
|
|
34 |
* @return void
|
|
|
35 |
* @see PEAR::setErrorHandling()
|
|
|
36 |
*/
|
|
|
37 |
function pe($o) {
|
|
|
38 |
global $dbh;
|
|
|
39 |
|
|
|
40 |
$dbh->setErrorHandling(PEAR_ERROR_RETURN);
|
|
|
41 |
drop_table($dbh, 'phptest');
|
|
|
42 |
|
|
|
43 |
die($o->toString());
|
|
|
44 |
}
|
|
|
45 |
|
|
|
46 |
|
|
|
47 |
$dbh->setErrorHandling(PEAR_ERROR_RETURN);
|
|
|
48 |
drop_table($dbh, 'php_limit');
|
|
|
49 |
|
|
|
50 |
$dbh->setErrorHandling(PEAR_ERROR_CALLBACK, 'pe');
|
|
|
51 |
|
|
|
52 |
$dbh->query('CREATE TABLE php_limit (a CHAR(20))');
|
|
|
53 |
|
|
|
54 |
|
|
|
55 |
$from = 0;
|
|
|
56 |
$count = 10;
|
|
|
57 |
$numrows = 30;
|
|
|
58 |
|
|
|
59 |
for ($i=0; $i<=$numrows+2; $i++) {
|
|
|
60 |
$dbh->query("INSERT INTO php_limit VALUES('result $i')");
|
|
|
61 |
}
|
|
|
62 |
for ($i = 0; $i <= 3; $i++) {
|
|
|
63 |
$from = 10 * $i;
|
|
|
64 |
$res = $dbh->limitQuery("select * from php_limit", $from, $count);
|
|
|
65 |
echo "======= From: $from || Number of rows to fetch: $count =======\n";
|
|
|
66 |
while ($row = $res->fetchRow(DB_FETCHMODE_ASSOC)) {
|
|
|
67 |
echo $res->getRowCounter() . '.- ' . $row['a'] . "\n";
|
|
|
68 |
}
|
|
|
69 |
$count = $res->numRows();
|
|
|
70 |
echo "Row count for limited result: $count\n";
|
|
|
71 |
$res->free(); // keep fbsql happy.
|
|
|
72 |
}
|
|
|
73 |
|
|
|
74 |
|
|
|
75 |
$from = 11;
|
|
|
76 |
$count = 3;
|
|
|
77 |
|
|
|
78 |
echo "======= Passing \$params || From: $from || Number of rows to fetch: $count =======\n";
|
|
|
79 |
$res = $dbh->limitQuery('SELECT * FROM php_limit WHERE a < ?', $from, $count, array('result 99'));
|
|
|
80 |
while ($row = $res->fetchRow(DB_FETCHMODE_ASSOC)) {
|
|
|
81 |
echo $res->getRowCounter() . '.- ' . $row['a'] . "\n";
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
$res->free(); // keep fbsql happy.
|
|
|
85 |
// keep ibase happy: can't drop tbl that has results open against it.
|
|
|
86 |
|
|
|
87 |
// Regression test for bug #7502.
|
|
|
88 |
$from = 0;
|
|
|
89 |
$count = 3;
|
|
|
90 |
$iter = 10;
|
|
|
91 |
echo "======= From: $from || Number of rows to fetch: $count || Iterations: $iter =======\n";
|
|
|
92 |
$res = $dbh->limitQuery("select * from php_limit", $from, $count);
|
|
|
93 |
if (!in_array($dbh->phptype, array('ibase', 'oci8'))) {
|
|
|
94 |
for ($i = 0; $i < $iter; ++$i) {
|
|
|
95 |
if (is_null($row = $res->fetchRow(DB_FETCHMODE_ASSOC, 1))) {
|
|
|
96 |
echo "Error in iteration $i: {$row['a']}\n";
|
|
|
97 |
}
|
|
|
98 |
}
|
|
|
99 |
}
|
|
|
100 |
$count = $res->numRows();
|
|
|
101 |
echo "Row count for limited result: $count\n";
|
|
|
102 |
$res->free(); // keep fbsql happy.
|
|
|
103 |
|
|
|
104 |
$dbh->setErrorHandling(PEAR_ERROR_RETURN);
|
|
|
105 |
drop_table($dbh, 'php_limit');
|