Skip to content

Commit

Permalink
FIX: Don’t drop first row on repeated iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Minnee and ScopeyNZ committed Jul 3, 2019
1 parent 3d6920c commit 75f4a35
Showing 1 changed file with 27 additions and 16 deletions.
43 changes: 27 additions & 16 deletions code/PostgreSQLQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ public function __destruct()

public function seek($row)
{
pg_result_seek($this->handle, $row);
return $this->nextRecord();
// Specifying the zero-th record here will reset the pointer
$result = pg_fetch_array($this->handle, $row, PGSQL_NUM);

return $this->parseResult($result);
}

public function numRecords()
Expand All @@ -73,26 +75,35 @@ public function nextRecord()

// Correct non-string types
if ($row) {
$record = [];
return $this->parseResult($row);
}

foreach ($row as $i => $v) {
$k = $this->columnNames[$i];
$record[$k] = $v;
$type = pg_field_type($this->handle, $i);
if (isset(self::$typeMapping[$type])) {
if ($type === 'bool' && $record[$k] === 't') {
$record[$k] = 1;
return false;
}

/**
* @param array $row
* @return array
*/
protected function parseResult(array $row)
{
$record = [];

foreach ($row as $i => $v) {
$k = $this->columnNames[$i];
$record[$k] = $v;
$type = pg_field_type($this->handle, $i);
if (isset(self::$typeMapping[$type])) {
if ($type === 'bool' && $record[$k] === 't') {
$record[$k] = 1;

// Note that boolean 'f' will be converted to 0 by this
} else {
settype($record[$k], self::$typeMapping[$type]);
}
} else {
settype($record[$k], self::$typeMapping[$type]);
}
}

return $record;
}

return false;
return $record;
}
}

0 comments on commit 75f4a35

Please sign in to comment.