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