|
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
|
|
|
/** |
|
14
|
|
|
* |
|
15
|
|
|
* @var \Zend\Db\Adapter\Adapter |
|
16
|
|
|
*/ |
|
17
|
|
|
protected $zendAdapter; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* |
|
21
|
|
|
* @var ZendDb2Connection |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $connection; |
|
24
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Constructor |
|
28
|
|
|
* |
|
29
|
|
|
* @param \Zend\Db\Adapter\Adapter $zendAdapter |
|
30
|
|
|
*/ |
|
31
|
6 |
|
public function __construct(\Zend\Db\Adapter\Adapter $zendAdapter) |
|
32
|
|
|
{ |
|
33
|
6 |
|
$this->zendAdapter = $zendAdapter; |
|
34
|
6 |
|
$this->connection = new ZendDb2Connection($this, $zendAdapter); |
|
35
|
6 |
|
} |
|
36
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* {@inheritdoc} |
|
40
|
|
|
*/ |
|
41
|
1 |
|
public function quoteValue($value) |
|
42
|
|
|
{ |
|
43
|
1 |
|
return $this->zendAdapter->getPlatform()->quoteValue($value); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* {@inheritdoc} |
|
49
|
|
|
*/ |
|
50
|
3 |
|
public function query($query, $resultsetType = Resultset::TYPE_ARRAY) |
|
51
|
|
|
{ |
|
52
|
|
|
try { |
|
53
|
|
|
//$r = $this->zendAdapter->query($query, \Zend\Db\Adapter\Adapter::QUERY_MODE_EXECUTE); |
|
54
|
3 |
|
$r = $this->zendAdapter->query($query)->execute(); |
|
|
|
|
|
|
55
|
3 |
|
$results = new Resultset($resultsetType); |
|
56
|
3 |
|
if ($r === false) { |
|
57
|
|
|
throw new Exception\InvalidArgumentException( |
|
58
|
|
|
'Query could not be executed ([$query])' |
|
59
|
|
|
); |
|
60
|
3 |
|
} elseif ($r instanceof \Zend\Db\ResultSet\ResultSet) { |
|
61
|
|
|
foreach ($r as $row) { |
|
62
|
|
|
$results->append((array) $row); |
|
63
|
|
|
} |
|
64
|
3 |
|
} elseif ($r instanceof \Zend\Db\Adapter\Driver\ResultInterface && $r->getFieldCount() > 0) { |
|
65
|
2 |
|
foreach ($r as $row) { |
|
66
|
2 |
|
$results->append($row); |
|
67
|
2 |
|
} |
|
68
|
2 |
|
} |
|
69
|
3 |
|
} catch (\Exception $e) { |
|
70
|
2 |
|
$msg = "ZendDb2 adapter query error: {$e->getMessage()} [$query]"; |
|
71
|
2 |
|
throw new Exception\InvalidArgumentException($msg); |
|
72
|
|
|
} |
|
73
|
3 |
|
return $results; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* {@inheritdoc} |
|
78
|
|
|
* @return ZendDb2Connection |
|
79
|
|
|
*/ |
|
80
|
1 |
|
public function getConnection() |
|
81
|
|
|
{ |
|
82
|
1 |
|
return $this->connection; |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: