1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Yiisoft\Db\Pgsql\PDO; |
6
|
|
|
|
7
|
|
|
use PDO; |
8
|
|
|
use Yiisoft\Db\Command\CommandInterface; |
9
|
|
|
use Yiisoft\Db\Connection\ConnectionPDO; |
10
|
|
|
use Yiisoft\Db\Exception\Exception; |
11
|
|
|
use Yiisoft\Db\Exception\InvalidArgumentException; |
12
|
|
|
use Yiisoft\Db\Exception\InvalidConfigException; |
13
|
|
|
use Yiisoft\Db\Query\QueryBuilderInterface; |
|
|
|
|
14
|
|
|
use Yiisoft\Db\Schema\Quoter; |
15
|
|
|
use Yiisoft\Db\Schema\QuoterInterface; |
16
|
|
|
use Yiisoft\Db\Schema\SchemaInterface; |
17
|
|
|
use Yiisoft\Db\Transaction\TransactionInterface; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Database connection class prefilled for PgSQL Server. |
21
|
|
|
* The class Connection represents a connection to a database via [PDO](https://secure.php.net/manual/en/book.pdo.php). |
22
|
|
|
*/ |
23
|
|
|
final class ConnectionPDOPgsql extends ConnectionPDO |
24
|
|
|
{ |
25
|
406 |
|
public function createCommand(?string $sql = null, array $params = []): CommandInterface |
26
|
|
|
{ |
27
|
406 |
|
$command = new CommandPDOPgsql($this, $this->queryCache); |
28
|
|
|
|
29
|
406 |
|
if ($sql !== null) { |
30
|
196 |
|
$command->setSql($sql); |
31
|
|
|
} |
32
|
|
|
|
33
|
406 |
|
if ($this->logger !== null) { |
34
|
406 |
|
$command->setLogger($this->logger); |
35
|
|
|
} |
36
|
|
|
|
37
|
406 |
|
if ($this->profiler !== null) { |
38
|
406 |
|
$command->setProfiler($this->profiler); |
39
|
|
|
} |
40
|
|
|
|
41
|
406 |
|
return $command->bindValues($params); |
42
|
|
|
} |
43
|
|
|
|
44
|
8 |
|
public function createTransaction(): TransactionInterface |
45
|
|
|
{ |
46
|
8 |
|
return new TransactionPDOPgsql($this); |
47
|
|
|
} |
48
|
|
|
|
49
|
11 |
|
public function getDriverName(): string |
50
|
|
|
{ |
51
|
11 |
|
return 'pgsql'; |
52
|
|
|
} |
53
|
|
|
|
54
|
5 |
|
public function getLastInsertID(?string $sequenceName = null): string |
55
|
|
|
{ |
56
|
5 |
|
if ($sequenceName === null) { |
57
|
1 |
|
throw new InvalidArgumentException('PgSQL not support lastInsertId without sequence name'); |
58
|
|
|
} |
59
|
|
|
|
60
|
4 |
|
return parent::getLastInsertID($sequenceName); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @throws Exception|InvalidConfigException |
65
|
|
|
*/ |
66
|
406 |
|
public function getQueryBuilder(): QueryBuilderInterface |
67
|
|
|
{ |
68
|
406 |
|
if ($this->queryBuilder === null) { |
69
|
406 |
|
$this->queryBuilder = new QueryBuilderPDOPgsql( |
70
|
406 |
|
$this->createCommand(), |
71
|
406 |
|
$this->getQuoter(), |
72
|
406 |
|
$this->getSchema(), |
73
|
|
|
); |
74
|
|
|
} |
75
|
|
|
|
76
|
406 |
|
return $this->queryBuilder; |
|
|
|
|
77
|
|
|
} |
78
|
|
|
|
79
|
419 |
|
public function getQuoter(): QuoterInterface |
80
|
|
|
{ |
81
|
419 |
|
if ($this->quoter === null) { |
82
|
419 |
|
$this->quoter = new Quoter('"', '"', $this->getTablePrefix()); |
83
|
|
|
} |
84
|
|
|
|
85
|
419 |
|
return $this->quoter; |
|
|
|
|
86
|
|
|
} |
87
|
|
|
|
88
|
420 |
|
public function getSchema(): SchemaInterface |
89
|
|
|
{ |
90
|
420 |
|
if ($this->schema === null) { |
91
|
420 |
|
$this->schema = new SchemaPDOPgsql($this, $this->schemaCache); |
92
|
|
|
} |
93
|
|
|
|
94
|
420 |
|
return $this->schema; |
|
|
|
|
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Initializes the DB connection. |
99
|
|
|
* |
100
|
|
|
* This method is invoked right after the DB connection is established. |
101
|
|
|
* |
102
|
|
|
* The default implementation turns on `PDO::ATTR_EMULATE_PREPARES`. |
103
|
|
|
* |
104
|
|
|
* if {@see emulatePrepare} is true, and sets the database {@see charset} if it is not empty. |
105
|
|
|
* |
106
|
|
|
* It then triggers an {@see EVENT_AFTER_OPEN} event. |
107
|
|
|
*/ |
108
|
200 |
|
protected function initConnection(): void |
109
|
|
|
{ |
110
|
200 |
|
if ($this->pdo === null) { |
111
|
200 |
|
$this->pdo = $this->driver->createConnection(); |
112
|
|
|
} |
113
|
|
|
|
114
|
200 |
|
$this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
|
|
|
|
115
|
|
|
|
116
|
200 |
|
if ($this->getEmulatePrepare() !== null && constant('PDO::ATTR_EMULATE_PREPARES')) { |
117
|
1 |
|
$this->pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, $this->getEmulatePrepare()); |
118
|
|
|
} |
119
|
|
|
|
120
|
200 |
|
$charset = $this->driver->getCharset(); |
121
|
|
|
|
122
|
200 |
|
if ($charset !== null) { |
123
|
|
|
$this->pdo->exec('SET NAMES ' . $this->pdo->quote($charset)); |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths