|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Licensed to CRATE Technology GmbH("Crate") under one or more contributor |
|
4
|
|
|
* license agreements. See the NOTICE file distributed with this work for |
|
5
|
|
|
* additional information regarding copyright ownership. Crate licenses |
|
6
|
|
|
* this file to you under the Apache License, Version 2.0 (the "License"); |
|
7
|
|
|
* you may not use this file except in compliance with the License. You may |
|
8
|
|
|
* obtain a copy of the License at |
|
9
|
|
|
* |
|
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
|
11
|
|
|
* |
|
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
|
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
|
14
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
|
15
|
|
|
* License for the specific language governing permissions and limitations |
|
16
|
|
|
* under the License. |
|
17
|
|
|
* |
|
18
|
|
|
* However, if you have executed another commercial license agreement |
|
19
|
|
|
* with Crate these terms will supersede the license and you may use the |
|
20
|
|
|
* software solely pursuant to the terms of the relevant commercial agreement. |
|
21
|
|
|
*/ |
|
22
|
|
|
|
|
23
|
|
|
namespace Crate\DBAL\Driver\PDOCrate; |
|
24
|
|
|
|
|
25
|
|
|
use Crate\PDO\PDOStatement; |
|
26
|
|
|
use Crate\PDO\PDOInterface; |
|
27
|
|
|
use Doctrine\DBAL\Driver\PDO\Exception; |
|
|
|
|
|
|
28
|
|
|
use Doctrine\DBAL\Driver\PDOStatementImplementations; |
|
|
|
|
|
|
29
|
|
|
use Doctrine\DBAL\Driver\Statement as StatementInterface; |
|
30
|
|
|
use Doctrine\DBAL\Driver\Result as ResultInterface; |
|
31
|
|
|
use Doctrine\DBAL\ParameterType; |
|
32
|
|
|
use Doctrine\Deprecations\Deprecation; |
|
33
|
|
|
use PDO; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @internal |
|
37
|
|
|
*/ |
|
38
|
|
|
final class CrateStatement implements StatementInterface |
|
39
|
|
|
{ |
|
40
|
|
|
private PDOInterface $pdo; |
|
41
|
|
|
private PDOStatement $stmt; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @param string $sql |
|
45
|
|
|
* @param array<string,mixed> $options |
|
46
|
|
|
*/ |
|
47
|
110 |
|
public function __construct(PDOInterface $pdo, $sql, $options = []) |
|
48
|
|
|
{ |
|
49
|
110 |
|
$this->pdo = $pdo; |
|
50
|
110 |
|
$this->stmt = $pdo->prepare($sql, $options); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* {@inheritDoc} |
|
55
|
|
|
*/ |
|
56
|
108 |
|
public function execute($params = null): ResultInterface |
|
57
|
|
|
{ |
|
58
|
|
|
|
|
59
|
108 |
|
if ($params !== null) { |
|
60
|
6 |
|
Deprecation::trigger( |
|
61
|
6 |
|
'doctrine/dbal', |
|
62
|
6 |
|
'https://github.com/doctrine/dbal/pull/5556', |
|
63
|
6 |
|
'Passing $params to Statement::execute() is deprecated. Bind parameters using' |
|
64
|
6 |
|
. ' Statement::bindParam() or Statement::bindValue() instead.', |
|
65
|
6 |
|
); |
|
66
|
|
|
} |
|
67
|
108 |
|
$this->stmt->execute($params); |
|
68
|
108 |
|
return new Result($this); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* {@inheritDoc} |
|
73
|
|
|
*/ |
|
74
|
|
|
public function columnCount(): int |
|
75
|
|
|
{ |
|
76
|
|
|
return $this->stmt->columnCount(); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* {@inheritDoc} |
|
81
|
|
|
*/ |
|
82
|
90 |
|
public function rowCount(): int |
|
83
|
|
|
{ |
|
84
|
90 |
|
return $this->stmt->rowCount(); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* {@inheritDoc} |
|
89
|
|
|
*/ |
|
90
|
86 |
|
public function bindValue($param, $value, $type = ParameterType::STRING) |
|
91
|
|
|
{ |
|
92
|
86 |
|
return $this->stmt->bindValue($param, $value, $type); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* {@inheritDoc} |
|
97
|
|
|
*/ |
|
98
|
12 |
|
public function bindParam($param, &$variable, $type = ParameterType::STRING, $length = null) |
|
99
|
|
|
{ |
|
100
|
12 |
|
return $this->stmt->bindParam($param, $variable, $type, $length); |
|
|
|
|
|
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* {@inheritDoc} |
|
105
|
|
|
*/ |
|
106
|
72 |
|
public function fetch( |
|
107
|
|
|
$fetch_style = PDO::FETCH_ASSOC, |
|
108
|
|
|
$cursor_orientation = PDO::FETCH_ORI_NEXT, |
|
109
|
|
|
$cursor_offset = 0, |
|
110
|
|
|
) { |
|
111
|
72 |
|
return $this->stmt->fetch($fetch_style, $cursor_orientation, $cursor_offset); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* @phpstan-param PDO::FETCH_* $mode |
|
116
|
|
|
* |
|
117
|
|
|
* @return list<mixed> |
|
|
|
|
|
|
118
|
|
|
* |
|
119
|
|
|
* @throws Exception |
|
120
|
|
|
*/ |
|
121
|
|
|
public function fetchAll(int $mode): array |
|
122
|
|
|
{ |
|
123
|
|
|
return $this->stmt->fetchAll($mode); |
|
|
|
|
|
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
8 |
|
public function fetchColumn($column_number = 0) |
|
127
|
|
|
{ |
|
128
|
8 |
|
return $this->stmt->fetchColumn($column_number); |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* {@inheritDoc} |
|
133
|
|
|
*/ |
|
134
|
|
|
public function closeCursor(): bool |
|
135
|
|
|
{ |
|
136
|
|
|
return $this->stmt->closeCursor(); |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* Gets the wrapped CrateDB PDOStatement. |
|
141
|
|
|
* |
|
142
|
|
|
* @return PDOStatement |
|
143
|
|
|
*/ |
|
144
|
2 |
|
public function getWrappedStatement(): PDOStatement |
|
145
|
|
|
{ |
|
146
|
2 |
|
return $this->stmt; |
|
147
|
|
|
} |
|
148
|
|
|
} |
|
149
|
|
|
|
Let?s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let?s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: