Skip to content

Commit

Permalink
Merge branch '2.2' into 2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
robbieaverill committed Nov 28, 2019
2 parents 4e3d3df + f2ec228 commit 3d50b3f
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 3d50b3f

Please sign in to comment.