ZendDb2Adapter::query()   A
last analyzed

Complexity

Conditions 4
Paths 8

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 19
ccs 12
cts 12
cp 1
rs 9.6333
c 0
b 0
f 0
cc 4
nc 8
nop 2
crap 4
1
<?php
2
3
namespace Soluble\DbWrapper\Adapter\Zend;
4
5
use Soluble\DbWrapper\Exception;
6
use Soluble\DbWrapper\Result\Resultset;
7
use Soluble\DbWrapper\Adapter\AdapterInterface;
8
use Soluble\DbWrapper\Connection\Zend\ZendDb2Connection;
9
10
class ZendDb2Adapter implements AdapterInterface
11
{
12
    /**
13
     * @var \Zend\Db\Adapter\Adapter
14
     */
15
    protected $zendAdapter;
16
17
    /**
18
     * @var ZendDb2Connection
19
     */
20
    protected $connection;
21
22
    /**
23
     * Constructor.
24
     *
25
     * @param \Zend\Db\Adapter\Adapter $zendAdapter
26
     */
27 6
    public function __construct(\Zend\Db\Adapter\Adapter $zendAdapter)
28
    {
29 6
        $this->zendAdapter = $zendAdapter;
30 6
        $this->connection = new ZendDb2Connection($this, $zendAdapter);
31 6
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36 1
    public function quoteValue($value)
37
    {
38 1
        return $this->zendAdapter->getPlatform()->quoteValue($value);
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44 3
    public function query($query, $resultsetType = Resultset::TYPE_ARRAY)
45
    {
46
        try {
47 3
            $stmt = $this->zendAdapter->createStatement($query);
48 3
            $r = $stmt->execute();
49 3
            $results = new Resultset($resultsetType);
50 3
            if ($r->getFieldCount() > 0) {
51 2
                foreach ($r as $row) {
52 2
                    $results->append($row);
53
                }
54
            }
55 3
            unset($r);
56 2
        } catch (\Exception $e) {
57 2
            $msg = "ZendDb2 adapter query error: {$e->getMessage()} [$query]";
58 2
            throw new Exception\InvalidArgumentException($msg);
59
        }
60
61 3
        return $results;
62
    }
63
64
    /**
65
     * {@inheritdoc}
66
     *
67
     * @return ZendDb2Connection
68
     */
69 1
    public function getConnection()
70
    {
71 1
        return $this->connection;
72
    }
73
}
74