Passed
Branch dev (7c715d)
by Wilmer
32:02 queued 29:10
created

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