2013-04-03 06:27:11 +02:00
|
|
|
<?php
|
|
|
|
|
2016-07-04 02:44:09 +02:00
|
|
|
namespace SilverStripe\PostgreSQL;
|
|
|
|
|
|
|
|
use SilverStripe\ORM\Connect\SS_Query;
|
|
|
|
|
2013-04-03 06:27:11 +02:00
|
|
|
/**
|
|
|
|
* A result-set from a PostgreSQL database.
|
2016-07-04 02:44:09 +02:00
|
|
|
*
|
2013-04-03 06:27:11 +02:00
|
|
|
* @package sapphire
|
|
|
|
* @subpackage model
|
|
|
|
*/
|
2015-12-17 19:18:01 +01:00
|
|
|
class PostgreSQLQuery extends SS_Query
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The internal Postgres handle that points to the result set.
|
|
|
|
* @var resource
|
|
|
|
*/
|
|
|
|
private $handle;
|
2013-04-03 06:27:11 +02:00
|
|
|
|
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;
|
|
|
|
}
|
2013-04-03 06:27:11 +02:00
|
|
|
|
2015-12-17 19:18:01 +01:00
|
|
|
public function __destruct()
|
|
|
|
{
|
|
|
|
if (is_resource($this->handle)) {
|
|
|
|
pg_free_result($this->handle);
|
|
|
|
}
|
|
|
|
}
|
2013-04-03 06:27:11 +02:00
|
|
|
|
2015-12-17 19:18:01 +01:00
|
|
|
public function seek($row)
|
|
|
|
{
|
|
|
|
return pg_result_seek($this->handle, $row);
|
|
|
|
}
|
2013-04-03 06:27:11 +02:00
|
|
|
|
2015-12-17 19:18:01 +01:00
|
|
|
public function numRecords()
|
|
|
|
{
|
|
|
|
return pg_num_rows($this->handle);
|
|
|
|
}
|
2013-04-03 06:27:11 +02:00
|
|
|
|
2015-12-17 19:18:01 +01:00
|
|
|
public function nextRecord()
|
|
|
|
{
|
|
|
|
return pg_fetch_assoc($this->handle);
|
|
|
|
}
|
2013-04-03 06:27:11 +02:00
|
|
|
}
|