1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Yiisoft\Db\Oracle\PDO; |
6
|
|
|
|
7
|
|
|
use PDO; |
8
|
|
|
use PDOException; |
9
|
|
|
use Yiisoft\Db\Cache\QueryCache; |
10
|
|
|
use Yiisoft\Db\Command\Command; |
11
|
|
|
use Yiisoft\Db\Connection\ConnectionPDOInterface; |
12
|
|
|
use Yiisoft\Db\Exception\Exception; |
13
|
|
|
use Yiisoft\Db\Query\QueryBuilderInterface; |
|
|
|
|
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Command represents an Oracle SQL statement to be executed against a database. |
17
|
|
|
*/ |
18
|
|
|
final class CommandPDOOracle extends Command |
19
|
|
|
{ |
20
|
329 |
|
public function __construct(private ConnectionPDOInterface $db, QueryCache $queryCache) |
21
|
|
|
{ |
22
|
329 |
|
parent::__construct($queryCache); |
23
|
|
|
} |
24
|
|
|
|
25
|
167 |
|
public function queryBuilder(): QueryBuilderInterface |
26
|
|
|
{ |
27
|
167 |
|
return $this->db->getQueryBuilder(); |
28
|
|
|
} |
29
|
|
|
|
30
|
158 |
|
public function prepare(?bool $forRead = null): void |
31
|
|
|
{ |
32
|
158 |
|
if (isset($this->pdoStatement)) { |
33
|
4 |
|
$this->bindPendingParams(); |
34
|
|
|
|
35
|
4 |
|
return; |
36
|
|
|
} |
37
|
|
|
|
38
|
158 |
|
$sql = $this->getSql(); |
39
|
|
|
|
40
|
158 |
|
if ($this->db->getTransaction()) { |
41
|
|
|
/** master is in a transaction. use the same connection. */ |
42
|
5 |
|
$forRead = false; |
43
|
|
|
} |
44
|
|
|
|
45
|
158 |
|
if ($forRead || ($forRead === null && $this->db->getSchema()->isReadQuery($sql))) { |
46
|
154 |
|
$pdo = $this->db->getSlavePdo(); |
47
|
|
|
} else { |
48
|
56 |
|
$pdo = $this->db->getMasterPdo(); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
try { |
52
|
158 |
|
$this->pdoStatement = $pdo->prepare($sql); |
53
|
158 |
|
$this->bindPendingParams(); |
54
|
|
|
} catch (PDOException $e) { |
55
|
|
|
$message = $e->getMessage() . "\nFailed to prepare SQL: $sql"; |
56
|
|
|
$errorInfo = $e->errorInfo ?? null; |
57
|
|
|
|
58
|
|
|
throw new Exception($message, $errorInfo, $e); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
62
|
158 |
|
protected function bindPendingParams(): void |
63
|
|
|
{ |
64
|
158 |
|
$paramsPassedByReference = []; |
65
|
|
|
|
66
|
158 |
|
foreach ($this->pendingParams as $name => $value) { |
67
|
138 |
|
if (PDO::PARAM_STR === $value[1]) { |
68
|
133 |
|
$paramsPassedByReference[$name] = $value[0]; |
69
|
133 |
|
$this->pdoStatement?->bindParam( |
70
|
|
|
$name, |
71
|
|
|
$paramsPassedByReference[$name], |
72
|
133 |
|
$value[1], |
73
|
133 |
|
strlen($value[0]) |
74
|
|
|
); |
75
|
|
|
} else { |
76
|
22 |
|
$this->pdoStatement?->bindValue($name, $value[0], $value[1]); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
80
|
158 |
|
$this->pendingParams = []; |
81
|
|
|
} |
82
|
|
|
|
83
|
2 |
|
protected function getCacheKey(string $method, ?int $fetchMode, string $rawSql): array |
84
|
|
|
{ |
85
|
|
|
return [ |
86
|
2 |
|
__CLASS__, |
87
|
|
|
$method, |
88
|
|
|
$fetchMode, |
89
|
2 |
|
$this->db->getDriver()->getDsn(), |
90
|
2 |
|
$this->db->getDriver()->getUsername(), |
91
|
|
|
$rawSql, |
92
|
|
|
]; |
93
|
|
|
} |
94
|
|
|
|
95
|
157 |
|
protected function internalExecute(?string $rawSql): void |
96
|
|
|
{ |
97
|
157 |
|
$attempt = 0; |
98
|
|
|
|
99
|
157 |
|
while (true) { |
100
|
|
|
try { |
101
|
|
|
if ( |
102
|
157 |
|
++$attempt === 1 |
103
|
157 |
|
&& $this->isolationLevel !== null |
104
|
157 |
|
&& $this->db->getTransaction() === null |
105
|
|
|
) { |
106
|
|
|
$this->db->transaction(fn ($rawSql) => $this->internalExecute($rawSql), $this->isolationLevel); |
107
|
|
|
} else { |
108
|
157 |
|
$this->pdoStatement->execute(); |
|
|
|
|
109
|
|
|
} |
110
|
157 |
|
break; |
111
|
6 |
|
} catch (PDOException $e) { |
112
|
6 |
|
$rawSql = $rawSql ?: $this->getRawSql(); |
113
|
6 |
|
$e = $this->db->getSchema()->convertException($e, $rawSql); |
114
|
|
|
|
115
|
6 |
|
if ($this->retryHandler === null || !($this->retryHandler)($e, $attempt)) { |
116
|
6 |
|
throw $e; |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths