silverstripe-postgresql/code/PostgreSQLQuery.php

53 lines
1.1 KiB
PHP
Raw Normal View History

<?php
2016-07-04 02:44:09 +02:00
namespace SilverStripe\PostgreSQL;
2016-09-09 05:47:01 +02:00
use SilverStripe\ORM\Connect\Query;
2016-07-04 02:44:09 +02:00
/**
* A result-set from a PostgreSQL database.
2016-07-04 02:44:09 +02:00
*
* @package sapphire
* @subpackage model
*/
2016-09-09 05:47:01 +02:00
class PostgreSQLQuery extends Query
2015-12-17 19:18:01 +01:00
{
/**
* The internal Postgres handle that points to the result set.
* @var resource
*/
private $handle;
2015-12-17 19:18:01 +01:00
/**
* Hook the result-set given into a Query class, suitable for use by sapphire.
2016-07-04 02:44:09 +02:00
* @param resource $handle the internal Postgres handle that is points to the resultset.
2015-12-17 19:18:01 +01:00
*/
public function __construct($handle)
{
$this->handle = $handle;
}
2015-12-17 19:18:01 +01:00
public function __destruct()
{
if (is_resource($this->handle)) {
pg_free_result($this->handle);
}
}
2015-12-17 19:18:01 +01:00
public function seek($row)
{
pg_result_seek($this->handle, $row);
return pg_fetch_row($this->handle);
2015-12-17 19:18:01 +01:00
}
2015-12-17 19:18:01 +01:00
public function numRecords()
{
return pg_num_rows($this->handle);
}
2015-12-17 19:18:01 +01:00
public function nextRecord()
{
return pg_fetch_assoc($this->handle);
}
}