Passed
Push — master ( 91737d...b67073 )
by Sam
08:30
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
use ArrayIterator;
6
use PDO;
7
use PDOStatement;
8
9
/**
10
 * A result-set from a PDO database.
11
 */
12
class PDOQuery extends Query
13
{
14
    /**
15
     * @var array
16
     */
17
    protected $results = null;
18
19
    /**
20
     * Hook the result-set given into a Query class, suitable for use by SilverStripe.
21
     * @param PDOStatement $statement The internal PDOStatement containing the results
22
     */
23
    public function __construct(PDOStatementHandle $statement)
24
    {
25
        // Since no more than one PDOStatement for any one connection can be safely
26
        // traversed, each statement simply requests all rows at once for safety.
27
        // This could be re-engineered to call fetchAll on an as-needed basis
28
29
        $this->results = $statement->typeCorrectedFetchAll();
30
        $statement->closeCursor();
31
    }
32
33
    public function getIterator()
34
    {
35
        return new ArrayIterator($this->results);
36
    }
37
38
    public function numRecords()
39
    {
40
        return count($this->results);
41
    }
42
}
43