|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, https://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Aimeos (aimeos.org), 2021-2022 |
|
6
|
|
|
* @package Base |
|
7
|
|
|
* @subpackage DB |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
namespace Aimeos\Base\DB\Result; |
|
12
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Database result set object for DBAL connections. |
|
16
|
|
|
* |
|
17
|
|
|
* @package Base |
|
18
|
|
|
* @subpackage DB |
|
19
|
|
|
*/ |
|
20
|
|
|
class DBAL extends \Aimeos\Base\DB\Result\Base implements \Aimeos\Base\DB\Result\Iface |
|
21
|
|
|
{ |
|
22
|
|
|
private $result; |
|
23
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Initializes the result object. |
|
27
|
|
|
* |
|
28
|
|
|
* @param \Doctrine\DBAL\Driver\Statement|\Doctrine\DBAL\Driver\Result $result Result object created by DBAL |
|
29
|
|
|
*/ |
|
30
|
|
|
public function __construct( $result ) |
|
31
|
|
|
{ |
|
32
|
|
|
$this->result = $result; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Clears the result set if anything is left. |
|
38
|
|
|
*/ |
|
39
|
|
|
public function __destruct() |
|
40
|
|
|
{ |
|
41
|
|
|
$class = '\Doctrine\DBAL\Driver\Result'; |
|
42
|
|
|
|
|
43
|
|
|
if( $this->result instanceof $class ) { |
|
44
|
|
|
$this->result->free(); |
|
|
|
|
|
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
$class = '\Doctrine\DBAL\Driver\Statement'; |
|
48
|
|
|
|
|
49
|
|
|
if( $this->result instanceof $class ) { |
|
50
|
|
|
$this->result->closeCursor(); |
|
|
|
|
|
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Returns the number of rows affected by a INSERT, UPDATE or DELETE statement. |
|
57
|
|
|
* |
|
58
|
|
|
* @return int Number of touched records |
|
59
|
|
|
* @throws \Aimeos\Base\DB\Exception if an error occured in the unterlying driver |
|
60
|
|
|
*/ |
|
61
|
|
|
public function affectedRows() : int |
|
62
|
|
|
{ |
|
63
|
|
|
try { |
|
64
|
|
|
return $this->result->rowCount(); |
|
|
|
|
|
|
65
|
|
|
} catch( \Doctrine\DBAL\Driver\Exception $e ) { |
|
66
|
|
|
throw new \Aimeos\Base\DB\Exception( $e->getMessage(), $e->getCode() ); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Retrieves the next row from database result set. |
|
73
|
|
|
* |
|
74
|
|
|
* @param int $style The data can be returned as associative or numerical array |
|
75
|
|
|
* @return array|null Numeric or associative array of columns returned by the database or null if no more rows are available |
|
76
|
|
|
* @throws \Aimeos\Base\DB\Exception if an error occured in the unterlying driver or the fetch style is unknown |
|
77
|
|
|
*/ |
|
78
|
|
|
public function fetch( int $style = \Aimeos\Base\DB\Result\Base::FETCH_ASSOC ) : ?array |
|
79
|
|
|
{ |
|
80
|
|
|
try |
|
81
|
|
|
{ |
|
82
|
|
|
$class = '\Doctrine\DBAL\Driver\Statement'; |
|
83
|
|
|
|
|
84
|
|
|
if( $this->result instanceof $class ) |
|
85
|
|
|
{ |
|
86
|
|
|
$fetch = $style === \Aimeos\Base\DB\Result\Base::FETCH_NUM ? \PDO::FETCH_NUM : \PDO::FETCH_ASSOC; |
|
87
|
|
|
return $this->result->fetch( $fetch ) ?: null; |
|
|
|
|
|
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
if( $style === \Aimeos\Base\DB\Result\Base::FETCH_NUM ) { |
|
91
|
|
|
return $this->result->fetchNumeric() ?: null; |
|
|
|
|
|
|
92
|
|
|
} else { |
|
93
|
|
|
return $this->result->fetchAssociative() ?: null; |
|
|
|
|
|
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
catch( \Doctrine\DBAL\Driver\Exception $e ) |
|
97
|
|
|
{ |
|
98
|
|
|
throw new \Aimeos\Base\DB\Exception( $e->getMessage(), $e->getCode() ); |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* Cleans up pending database result sets. |
|
105
|
|
|
* |
|
106
|
|
|
* @return \Aimeos\Base\DB\Result\Iface Result instance for method chaining |
|
107
|
|
|
* @throws \Aimeos\Base\DB\Exception if an error occured in the unterlying driver |
|
108
|
|
|
*/ |
|
109
|
|
|
public function finish() : Iface |
|
110
|
|
|
{ |
|
111
|
|
|
try |
|
112
|
|
|
{ |
|
113
|
|
|
$class = '\Doctrine\DBAL\Driver\Result'; |
|
114
|
|
|
|
|
115
|
|
|
if( $this->result instanceof $class ) { |
|
116
|
|
|
$this->result->free(); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
$class = '\Doctrine\DBAL\Driver\Statement'; |
|
120
|
|
|
|
|
121
|
|
|
if( $this->result instanceof $class ) { |
|
122
|
|
|
$this->result->closeCursor(); |
|
123
|
|
|
} |
|
124
|
|
|
} |
|
125
|
|
|
catch( \Doctrine\DBAL\Driver\Exception $e ) |
|
126
|
|
|
{ |
|
127
|
|
|
throw new \Aimeos\Base\DB\Exception( $e->getMessage(), $e->getCode() ); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
return $this; |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* Retrieves the next database result set. |
|
136
|
|
|
* |
|
137
|
|
|
* @return bool True if another result is available, false if not |
|
138
|
|
|
*/ |
|
139
|
|
|
public function nextResult() : bool |
|
140
|
|
|
{ |
|
141
|
|
|
return false; |
|
142
|
|
|
} |
|
143
|
|
|
} |
|
144
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.