Commit a269b9cc authored by Dries's avatar Dries
Browse files

- Patch #322458 by hswong3i: tests for queryRange().

parent 3a3c4827
......@@ -683,7 +683,7 @@ public function startTransaction($required = FALSE) {
* A database query result resource, or NULL if the query was not executed
* correctly.
*/
abstract public function queryRange($query, Array $args, $from, $count, Array $options);
abstract public function queryRange($query, Array $args, $from, $count, Array $options = array());
/**
* Runs a SELECT query and stores its results in a temporary table.
......
......@@ -39,10 +39,7 @@ public function __construct(Array $connection_options = array()) {
$this->exec('SET sql_mode=STRICT_ALL_TABLES');
}
public function queryRange($query, Array $args, $from, $count, Array $options) {
// Backward compatibility hack, temporary.
$query = str_replace(array('%d' , '%f' , '%b' , "'%s'"), '?', $query);
public function queryRange($query, Array $args, $from, $count, Array $options = array()) {
return $this->query($query . ' LIMIT ' . $from . ', ' . $count, $args, $options);
}
......
......@@ -75,10 +75,7 @@ public function query($query, Array $args = array(), $options = array()) {
}
}
public function queryRange($query, Array $args, $from, $count, Array $options) {
// Backward compatibility hack, temporary.
$query = str_replace(array('%d' , '%f' , '%b' , "'%s'"), '?', $query);
public function queryRange($query, Array $args, $from, $count, Array $options = array()) {
return $this->query($query . ' LIMIT ' . $count . ' OFFSET ' . $from, $args, $options);
}
......
......@@ -1924,6 +1924,44 @@ class DatabaseLoggingTestCase extends DatabaseTestCase {
}
}
/**
* Range query tests.
*/
class DatabaseRangeQueryTestCase extends DrupalWebTestCase {
/**
* Define metadata for this test subclass.
*/
function getInfo() {
return array(
'name' => t('Range query test'),
'description' => t('Test the Range query functionality.'),
'group' => t('Database'),
);
}
/**
* Implementation of setUp().
*/
function setUp() {
parent::setUp('database_test');
}
/**
* Confirm that range query work and return correct result.
*/
function testRangeQuery() {
// Test if return correct number of rows.
$range_rows = db_query_range("SELECT name FROM {system} ORDER BY name", array(), 2, 3)->fetchAll();
$this->assertEqual(count($range_rows), 3, t('Range query work and return correct number of rows.'));
// Test if return target data.
$raw_rows = db_query("SELECT name FROM {system} ORDER BY name")->fetchAll();
$raw_rows = array_slice($raw_rows, 2, 3);
$this->assertEqual($range_rows, $raw_rows, t('Range query work and return target data.'));
}
}
/**
* Temporary query tests.
*/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment