Completed
Push — 4 ( afb3c8...0b5f5e )
by Loz
43s queued 20s
created

PDOQuery::fetchAllPgsql()   A

Complexity

Conditions 5
Paths 2

Size

Total Lines 23
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 13
nc 2
nop 1
dl 0
loc 23
rs 9.5222
c 0
b 0
f 0
1
<?php
2
3
namespace SilverStripe\ORM\Connect;
4
5
/**
6
 * A result-set from a PDO database.
7
 */
8
class PDOQuery extends Query
9
{
10
    /**
11
     * @var array
12
     */
13
    protected $results = null;
14
15
    /**
16
     * Hook the result-set given into a Query class, suitable for use by SilverStripe.
17
     * @param PDOStatement $statement The internal PDOStatement containing the results
18
     */
19
    public function __construct(PDOStatementHandle $statement)
20
    {
21
        // Since no more than one PDOStatement for any one connection can be safely
22
        // traversed, each statement simply requests all rows at once for safety.
23
        // This could be re-engineered to call fetchAll on an as-needed basis
24
25
        $this->results = $statement->typeCorrectedFetchAll();
26
        $statement->closeCursor();
27
    }
28
29
    public function seek($row)
30
    {
31
        $this->rowNum = $row - 1;
32
        return $this->nextRecord();
33
    }
34
35
    public function numRecords()
36
    {
37
        return count($this->results);
38
    }
39
40
    public function nextRecord()
41
    {
42
        $index = $this->rowNum + 1;
43
44
        if (isset($this->results[$index])) {
45
            return $this->results[$index];
46
        } else {
47
            return false;
48
        }
49
    }
50
}
51