Test Failed
Push — dev ( 962df0...7c715d )
by Wilmer
03:39 queued 02:57
created

CommandPDOPgsql::schema()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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