1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Yiisoft\Db\Mssql; |
6
|
|
|
|
7
|
|
|
use PDOException; |
8
|
|
|
use Throwable; |
9
|
|
|
use Yiisoft\Db\Driver\PDO\AbstractCommandPDO; |
10
|
|
|
use Yiisoft\Db\Driver\PDO\ConnectionPDOInterface; |
11
|
|
|
use Yiisoft\Db\Exception\ConvertException; |
12
|
|
|
use Yiisoft\Db\Exception\Exception; |
13
|
|
|
use Yiisoft\Db\QueryBuilder\QueryBuilderInterface; |
14
|
|
|
|
15
|
|
|
use function is_array; |
16
|
|
|
|
17
|
|
|
final class CommandPDO extends AbstractCommandPDO |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @inheritDoc |
21
|
|
|
*/ |
22
|
6 |
|
public function insertWithReturningPks(string $table, array $columns): bool|array |
23
|
|
|
{ |
24
|
6 |
|
$params = []; |
25
|
|
|
|
26
|
6 |
|
$sql = $this->queryBuilder()->insertWithReturningPks($table, $columns, $params); |
|
|
|
|
27
|
|
|
|
28
|
6 |
|
$this->setSql($sql)->bindValues($params); |
29
|
6 |
|
$this->prepare(false); |
30
|
|
|
|
31
|
|
|
/** @psalm-var array|bool $result */ |
32
|
6 |
|
$result = $this->queryOne(); |
33
|
|
|
|
34
|
6 |
|
return is_array($result) ? $result : false; |
35
|
|
|
} |
36
|
|
|
|
37
|
280 |
|
public function queryBuilder(): QueryBuilderInterface |
38
|
|
|
{ |
39
|
280 |
|
return $this->db->getQueryBuilder(); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @psalm-suppress UnusedClosureParam |
44
|
|
|
* |
45
|
|
|
* @throws Exception |
46
|
|
|
* @throws Throwable |
47
|
|
|
*/ |
48
|
257 |
|
protected function internalExecute(string|null $rawSql): void |
49
|
|
|
{ |
50
|
257 |
|
$attempt = 0; |
51
|
|
|
|
52
|
257 |
|
while (true) { |
53
|
|
|
try { |
54
|
|
|
if ( |
55
|
257 |
|
++$attempt === 1 |
56
|
257 |
|
&& $this->isolationLevel !== null |
57
|
257 |
|
&& $this->db->getTransaction() === null |
58
|
|
|
) { |
59
|
1 |
|
$this->db->transaction( |
60
|
1 |
|
fn (ConnectionPDOInterface $db) => $this->internalExecute($rawSql), |
|
|
|
|
61
|
1 |
|
$this->isolationLevel |
62
|
1 |
|
); |
63
|
|
|
} else { |
64
|
257 |
|
$this->pdoStatement?->execute(); |
65
|
|
|
} |
66
|
256 |
|
break; |
67
|
7 |
|
} catch (PDOException $e) { |
68
|
7 |
|
$rawSql = $rawSql ?: $this->getRawSql(); |
69
|
7 |
|
$e = (new ConvertException($e, $rawSql))->run(); |
70
|
|
|
|
71
|
7 |
|
if ($this->retryHandler === null || !($this->retryHandler)($e, $attempt)) { |
72
|
7 |
|
throw $e; |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.