cleanup and better test queryWalk()
This commit is contained in:
@@ -821,9 +821,9 @@ class MeekroDB {
|
|||||||
$this->runHook('run_success', $hookHash);
|
$this->runHook('run_success', $hookHash);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!($result instanceof MySQLi_Result)) return $result; // no results returned?
|
|
||||||
if ($opts_raw) return $result;
|
|
||||||
if ($opts_walk) return new MeekroDBWalk($db, $result);
|
if ($opts_walk) return new MeekroDBWalk($db, $result);
|
||||||
|
if (!($result instanceof MySQLi_Result)) return $result; // query was not a SELECT?
|
||||||
|
if ($opts_raw) return $result;
|
||||||
|
|
||||||
$return = array();
|
$return = array();
|
||||||
|
|
||||||
@@ -938,18 +938,21 @@ class MeekroDBWalk {
|
|||||||
protected $result;
|
protected $result;
|
||||||
protected $freed;
|
protected $freed;
|
||||||
|
|
||||||
function __construct(MySQLi $mysqli, MySQLi_Result $result) {
|
function __construct(MySQLi $mysqli, $result) {
|
||||||
$this->mysqli = $mysqli;
|
$this->mysqli = $mysqli;
|
||||||
$this->result = $result;
|
$this->result = $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
function next() {
|
function next() {
|
||||||
|
// $result can be non-object if the query was not a SELECT
|
||||||
|
if (! ($this->result instanceof MySQLi_Result)) return;
|
||||||
if ($row = $this->result->fetch_assoc()) return $row;
|
if ($row = $this->result->fetch_assoc()) return $row;
|
||||||
else $this->free();
|
else $this->free();
|
||||||
}
|
}
|
||||||
|
|
||||||
function free() {
|
function free() {
|
||||||
if ($this->freed) return;
|
if ($this->freed) return;
|
||||||
|
if (! ($this->result instanceof MySQLi_Result)) return;
|
||||||
|
|
||||||
$this->result->free();
|
$this->result->free();
|
||||||
while ($this->mysqli->more_results()) {
|
while ($this->mysqli->more_results()) {
|
||||||
|
|||||||
@@ -13,7 +13,31 @@ class WalkTest extends SimpleTest {
|
|||||||
$this->assert($results[7]['username'] == 'vookoo');
|
$this->assert($results[7]['username'] == 'vookoo');
|
||||||
}
|
}
|
||||||
|
|
||||||
function test_2_walk_stop() {
|
function test_2_walk_empty() {
|
||||||
|
$Walk = DB::queryWalk("SELECT * FROM accounts WHERE id>100");
|
||||||
|
|
||||||
|
$results = array();
|
||||||
|
while ($row = $Walk->next()) {
|
||||||
|
$results[] = $row;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->assert(count($results) == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
function test_3_walk_insert() {
|
||||||
|
$Walk = DB::queryWalk("INSERT INTO profile (id) VALUES (100)");
|
||||||
|
|
||||||
|
$results = array();
|
||||||
|
while ($row = $Walk->next()) {
|
||||||
|
$results[] = $row;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->assert(count($results) == 0);
|
||||||
|
|
||||||
|
DB::query("DELETE FROM profile WHERE id=100");
|
||||||
|
}
|
||||||
|
|
||||||
|
function test_4_walk_incomplete() {
|
||||||
$Walk = DB::queryWalk("SELECT * FROM accounts");
|
$Walk = DB::queryWalk("SELECT * FROM accounts");
|
||||||
$Walk->next();
|
$Walk->next();
|
||||||
unset($Walk);
|
unset($Walk);
|
||||||
|
|||||||
Reference in New Issue
Block a user