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\CommandPDO as 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 insertEx(string $table, array $columns): bool|array |
23
|
|
|
{ |
24
|
6 |
|
$params = []; |
25
|
6 |
|
$sql = $this->queryBuilder()->insertEx($table, $columns, $params); |
26
|
|
|
|
27
|
6 |
|
$this->setSql($sql)->bindValues($params); |
28
|
6 |
|
$this->prepare(false); |
29
|
|
|
|
30
|
|
|
/** @psalm-var array|bool $result */ |
31
|
6 |
|
$result = $this->queryOne(); |
32
|
|
|
|
33
|
6 |
|
return is_array($result) ? $result : false; |
34
|
|
|
} |
35
|
|
|
|
36
|
268 |
|
public function queryBuilder(): QueryBuilderInterface |
37
|
|
|
{ |
38
|
268 |
|
return $this->db->getQueryBuilder(); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @psalm-suppress UnusedClosureParam |
43
|
|
|
* |
44
|
|
|
* @throws Exception |
45
|
|
|
* @throws Throwable |
46
|
|
|
*/ |
47
|
256 |
|
protected function internalExecute(string|null $rawSql): void |
48
|
|
|
{ |
49
|
256 |
|
$attempt = 0; |
50
|
|
|
|
51
|
256 |
|
while (true) { |
52
|
|
|
try { |
53
|
|
|
if ( |
54
|
|
|
++$attempt === 1 |
55
|
256 |
|
&& $this->isolationLevel !== null |
56
|
256 |
|
&& $this->db->getTransaction() === null |
57
|
|
|
) { |
58
|
1 |
|
$this->db->transaction( |
59
|
1 |
|
fn (ConnectionPDOInterface $db) => $this->internalExecute($rawSql), |
|
|
|
|
60
|
1 |
|
$this->isolationLevel |
61
|
|
|
); |
62
|
|
|
} else { |
63
|
256 |
|
$this->pdoStatement?->execute(); |
64
|
|
|
} |
65
|
255 |
|
break; |
66
|
9 |
|
} catch (PDOException $e) { |
67
|
9 |
|
$rawSql = $rawSql ?: $this->getRawSql(); |
68
|
9 |
|
$e = (new ConvertException($e, $rawSql))->run(); |
69
|
|
|
|
70
|
9 |
|
if ($this->retryHandler === null || !($this->retryHandler)($e, $attempt)) { |
71
|
9 |
|
throw $e; |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.