Test Failed
Pull Request — master (#126)
by Wilmer
20:25 queued 15:55
created

CommandPDO::schema()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Mssql;
6
7
use PDOException;
8
use Yiisoft\Db\Driver\PDO\CommandPDO as AbstractCommandPDO;
9
use Yiisoft\Db\Exception\ConvertException;
10
use Yiisoft\Db\QueryBuilder\QueryBuilderInterface;
11
12
use function is_array;
13
14
final class CommandPDO extends AbstractCommandPDO
15
{
16
    /**
17
     * @inheritDoc
18
     */
19
    public function insertEx(string $table, array $columns): bool|array
20 6
    {
21
        $params = [];
22 6
        $sql = $this->queryBuilder()->insertEx($table, $columns, $params);
23 6
24
        $this->setSql($sql)->bindValues($params);
25 6
        $this->prepare(false);
26 6
27
        /** @psalm-var array|bool $result */
28
        $result = $this->queryOne();
29 6
30
        return is_array($result) ? $result : false;
31 6
    }
32
33
    public function queryBuilder(): QueryBuilderInterface
34 232
    {
35
        return $this->db->getQueryBuilder();
36 232
    }
37
38
    protected function internalExecute(string|null $rawSql): void
39
    {
40
        $attempt = 0;
41
42
        while (true) {
43
            try {
44 221
                if (
45
                    ++$attempt === 1
46 221
                    && $this->isolationLevel !== null
47
                    && $this->db->getTransaction() === null
48 221
                ) {
49
                    $this->db->transaction(
50
                        fn (string $rawSql) => $this->internalExecute($rawSql),
51
                        $this->isolationLevel
52 221
                    );
53 221
                } else {
54
                    $this->pdoStatement?->execute();
55
                }
56
                break;
57
            } catch (PDOException $e) {
58
                $rawSql = $rawSql ?: $this->getRawSql();
59
                $e = (new ConvertException($e, $rawSql))->run();
60 221
61
                if ($this->retryHandler === null || !($this->retryHandler)($e, $attempt)) {
62 220
                    throw $e;
63 6
                }
64 6
            }
65 6
        }
66
    }
67
}
68