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