Completed
Push — master ( 577988...bb5bda )
by Daniel
8s
created

PostgreSQLQuery::nextRecord()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace SilverStripe\PostgreSQL;
4
5
use SilverStripe\ORM\Connect\Query;
6
7
/**
8
 * A result-set from a PostgreSQL database.
9
 *
10
 * @package sapphire
11
 * @subpackage model
12
 */
13
class PostgreSQLQuery extends Query
14
{
15
    /**
16
     * The internal Postgres handle that points to the result set.
17
     * @var resource
18
     */
19
    private $handle;
20
21
    /**
22
     * Hook the result-set given into a Query class, suitable for use by sapphire.
23
     * @param resource $handle the internal Postgres handle that is points to the resultset.
24
     */
25
    public function __construct($handle)
26
    {
27
        $this->handle = $handle;
28
    }
29
30
    public function __destruct()
31
    {
32
        if (is_resource($this->handle)) {
33
            pg_free_result($this->handle);
34
        }
35
    }
36
37
    public function getIterator()
38
    {
39
        while ($data = pg_fetch_assoc($this->handle)) {
40
            yield $data;
41
        }
42
    }
43
44
    public function numRecords()
45
    {
46
        return pg_num_rows($this->handle);
47
    }
48
}
49