Skip to content

Commit

Permalink
#22 Changes fetch results to return null when at end
Browse files Browse the repository at this point in the history
  • Loading branch information
sbuberl committed Mar 8, 2019
1 parent fff942c commit 6e67415
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,7 @@ private function query_insert($query)
return $this->set_error('Invalid INSERT Query ');
$result = $this->query_select($the_rest);
$dataRows = [];
while (($values = $result->fetchRow()) !== false) {
while (($values = $result->fetchRow()) !== null) {
$row = array_map(
function ($value) {
if (is_string($value)) $value = "'$value'";
Expand Down
8 changes: 4 additions & 4 deletions src/ResultSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function fetchAll($type = self::FETCH_ASSOC)
public function fetchArray($type = self::FETCH_ASSOC)
{
if (!$this->dataCursor->valid()) {
return false;
return null;
}

$entry = $this->dataCursor->current();
Expand Down Expand Up @@ -86,14 +86,14 @@ public function fetchSingle($column = 0)
$type = is_numeric($column) ? self::FETCH_NUM : self::FETCH_ASSOC;
$row = $this->fetchArray($type);

return $row !== false && array_key_exists($column, $row) ? $row[$column] : false;
return $row !== null && array_key_exists($column, $row) ? $row[$column] : null;
}

public function fetchObject()
{
$row = $this->fetchAssoc();
if ($row === false) {
return false;
if ($row === null) {
return null;
}

return (object) $row;
Expand Down
12 changes: 6 additions & 6 deletions tests/ResultSetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function testFetchAssoc()
$results = new ResultSet(self::$columns, self::$entries);

$i = 0;
while (($row = $results->fetchAssoc()) !== false) {
while (($row = $results->fetchAssoc()) !== null) {
$this->assertEquals(array_combine(self::$columns, self::$entries[$i++]), $row);
}
$this->assertEquals(count(self::$entries), $i);
Expand All @@ -64,7 +64,7 @@ public function testFetchRow()
$results = new ResultSet(self::$columns, self::$entries);

$i = 0;
while (($row = $results->fetchRow()) !== false) {
while (($row = $results->fetchRow()) !== null) {
$this->assertEquals(self::$entries[$i++], $row);
}
$this->assertEquals(count(self::$entries), $i);
Expand All @@ -75,7 +75,7 @@ public function testFetchBoth()
$results = new ResultSet(self::$columns, self::$entries);

$i = 0;
while (($row = $results->fetchBoth()) !== false) {
while (($row = $results->fetchBoth()) !== null) {
$entry = self::$entries[$i++];
$this->assertEquals(array_merge($entry, array_combine(self::$columns, $entry)), $row);
}
Expand All @@ -85,7 +85,7 @@ public function testFetchBoth()
public function testFetchSingleEmpty()
{
$results = new ResultSet(self::$columns, array());
$this->assertFalse($results->fetchSingle(5));
$this->assertnull($results->fetchSingle(5));
}

public function testFetchSingleIndex()
Expand All @@ -105,7 +105,7 @@ public function testFetchObject()
$results = new ResultSet(self::$columns, self::$entries);

$i = 0;
while (($row = $results->fetchObject()) !== false) {
while (($row = $results->fetchObject()) !== null) {
$this->assertEquals((object) array_combine(self::$columns, self::$entries[$i++]), $row);
}
$this->assertEquals(count(self::$entries), $i);
Expand All @@ -124,7 +124,7 @@ public function testDataSeek()
$results = new ResultSet(self::$columns, self::$entries);

$success = $results->dataSeek(7);
$this->assertTrue($success !== false);
$this->assertTrue($success !== null);

$row = $results->fetchRow();
$this->assertEquals(self::$entries[7], $row);
Expand Down
4 changes: 2 additions & 2 deletions tests/SQL/ShowTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function testShowDatabasesNone()
$this->assertTrue($result !== false);

$result = $this->fsql->fetch_row($result);
$this->assertEquals(false, $result);
$this->assertEquals(null, $result);
}

public function testShowDatabases()
Expand All @@ -65,7 +65,7 @@ public function testShowTablesNone()
$this->assertTrue($result !== false);

$result = $this->fsql->fetch_row($result);
$this->assertEquals(false, $result);
$this->assertEquals(null, $result);
}

public function testShowTables()
Expand Down

0 comments on commit 6e67415

Please sign in to comment.