11
11
12
12
namespace FOD \DBALClickHouse ;
13
13
14
+ use Doctrine \DBAL \FetchMode ;
15
+ use Doctrine \DBAL \ParameterType ;
14
16
use Doctrine \DBAL \Platforms \AbstractPlatform ;
15
17
16
18
/**
@@ -60,7 +62,7 @@ class ClickHouseStatement implements \IteratorAggregate, \Doctrine\DBAL\Driver\S
60
62
/**
61
63
* @var integer
62
64
*/
63
- private $ fetchMode = \ PDO :: FETCH_BOTH ;
65
+ private $ fetchMode = FetchMode:: MIXED ;
64
66
65
67
/**
66
68
* @param \ClickHouseDB\Client $client
@@ -125,13 +127,12 @@ protected function assumeFetchMode($fetchMode = null)
125
127
{
126
128
$ mode = $ fetchMode ?: $ this ->fetchMode ;
127
129
if (!\in_array ($ mode , [
128
- \PDO ::FETCH_ASSOC ,
129
- \PDO ::FETCH_NUM ,
130
- \PDO ::FETCH_BOTH ,
131
- \PDO ::FETCH_OBJ ,
130
+ FetchMode::ASSOCIATIVE ,
131
+ FetchMode::NUMERIC ,
132
+ FetchMode::STANDARD_OBJECT ,
132
133
\PDO ::FETCH_KEY_PAIR ,
133
134
], true )) {
134
- $ mode = \ PDO :: FETCH_BOTH ;
135
+ $ mode = FetchMode:: MIXED ;
135
136
}
136
137
137
138
return $ mode ;
@@ -150,15 +151,15 @@ public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NE
150
151
151
152
$ this ->getIterator ()->next ();
152
153
153
- if (\ PDO :: FETCH_NUM === $ this ->assumeFetchMode ($ fetchMode )) {
154
+ if (FetchMode:: NUMERIC === $ this ->assumeFetchMode ($ fetchMode )) {
154
155
return array_values ($ data );
155
156
}
156
157
157
- if (\ PDO :: FETCH_BOTH === $ this ->assumeFetchMode ($ fetchMode )) {
158
+ if (FetchMode:: MIXED === $ this ->assumeFetchMode ($ fetchMode )) {
158
159
return array_values ($ data ) + $ data ;
159
160
}
160
161
161
- if (\ PDO :: FETCH_OBJ === $ this ->assumeFetchMode ($ fetchMode )) {
162
+ if (FetchMode:: STANDARD_OBJECT === $ this ->assumeFetchMode ($ fetchMode )) {
162
163
return (object )$ data ;
163
164
}
164
165
@@ -178,14 +179,14 @@ public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NE
178
179
*/
179
180
public function fetchAll ($ fetchMode = null , $ fetchArgument = null , $ ctorArgs = null )
180
181
{
181
- if (\ PDO :: FETCH_NUM === $ this ->assumeFetchMode ($ fetchMode )) {
182
+ if (FetchMode:: NUMERIC === $ this ->assumeFetchMode ($ fetchMode )) {
182
183
return array_map (
183
184
'array_values ' ,
184
185
$ this ->rows
185
186
);
186
187
}
187
188
188
- if (\ PDO :: FETCH_BOTH === $ this ->assumeFetchMode ($ fetchMode )) {
189
+ if (FetchMode:: MIXED === $ this ->assumeFetchMode ($ fetchMode )) {
189
190
return array_map (
190
191
function ($ row ) {
191
192
return array_values ($ row ) + $ row ;
@@ -194,7 +195,7 @@ function ($row) {
194
195
);
195
196
}
196
197
197
- if (\ PDO :: FETCH_OBJ === $ this ->assumeFetchMode ($ fetchMode )) {
198
+ if (FetchMode:: STANDARD_OBJECT === $ this ->assumeFetchMode ($ fetchMode )) {
198
199
return array_map (
199
200
function ($ row ) {
200
201
return (object )$ row ;
@@ -224,7 +225,7 @@ function ($row) {
224
225
*/
225
226
public function fetchColumn ($ columnIndex = 0 )
226
227
{
227
- if ($ elem = $ this ->fetch (\ PDO :: FETCH_NUM )) {
228
+ if ($ elem = $ this ->fetch (FetchMode:: NUMERIC )) {
228
229
return $ elem [$ columnIndex ] ?? $ elem [0 ];
229
230
}
230
231
@@ -342,10 +343,10 @@ protected function getTypedParam($key)
342
343
// if param type was not setted - trying to get db-type by php-var-type
343
344
if (null === $ type ) {
344
345
if (\is_bool ($ this ->values [$ key ])) {
345
- $ type = \ PDO :: PARAM_BOOL ;
346
+ $ type = ParameterType:: BOOLEAN ;
346
347
} else {
347
348
if (\is_int ($ this ->values [$ key ]) || \is_float ($ this ->values [$ key ])) {
348
- $ type = \ PDO :: PARAM_INT ;
349
+ $ type = ParameterType:: INTEGER ;
349
350
} else {
350
351
if (\is_array ($ this ->values [$ key ])) {
351
352
@@ -372,15 +373,15 @@ function ($value) {
372
373
}
373
374
}
374
375
375
- if (\ PDO :: PARAM_NULL === $ type ) {
376
+ if (ParameterType:: NULL === $ type ) {
376
377
throw new ClickHouseException ('NULLs are not supported by ClickHouse ' );
377
378
}
378
379
379
- if (\ PDO :: PARAM_INT === $ type ) {
380
+ if (ParameterType:: INTEGER === $ type ) {
380
381
return $ this ->values [$ key ];
381
382
}
382
383
383
- if (\ PDO :: PARAM_BOOL === $ type ) {
384
+ if (ParameterType:: BOOLEAN === $ type ) {
384
385
return (int )(bool )$ this ->values [$ key ];
385
386
}
386
387
0 commit comments