silverstripe-postgresql/code/PostgreSQLQuery.php

49 lines
989 B
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);
}
}
public function getIterator()
2015-12-17 19:18:01 +01:00
{
while ($data = pg_fetch_assoc($this->handle)) {
yield $data;
}
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);
}
}