1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Yiisoft\Db\Sqlite\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\InvalidConfigException; |
12
|
|
|
use Yiisoft\Db\Query\QueryBuilderInterface; |
|
|
|
|
13
|
|
|
use Yiisoft\Db\Schema\Quoter; |
14
|
|
|
use Yiisoft\Db\Schema\QuoterInterface; |
15
|
|
|
use Yiisoft\Db\Schema\SchemaInterface; |
16
|
|
|
use Yiisoft\Db\Transaction\TransactionInterface; |
17
|
|
|
|
18
|
|
|
use function constant; |
19
|
|
|
use function strncmp; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Database connection class prefilled for SQLite Server. |
23
|
|
|
*/ |
24
|
|
|
final class ConnectionPDOSqlite extends ConnectionPDO |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* Reset the connection after cloning. |
28
|
380 |
|
*/ |
29
|
|
|
public function __clone() |
30
|
|
|
{ |
31
|
|
|
$this->transaction = null; |
32
|
|
|
|
33
|
380 |
|
if (strncmp($this->driver->getDsn(), 'sqlite::memory:', 15) !== 0) { |
34
|
|
|
/** reset PDO connection, unless its sqlite in-memory, which can only have one connection */ |
35
|
|
|
$this->pdo = null; |
36
|
328 |
|
} |
37
|
|
|
} |
38
|
328 |
|
|
39
|
|
|
public function createCommand(?string $sql = null, array $params = []): CommandInterface |
40
|
328 |
|
{ |
41
|
172 |
|
$command = new CommandPDOSqlite($this, $this->queryCache); |
|
|
|
|
42
|
|
|
|
43
|
|
|
if ($sql !== null) { |
44
|
328 |
|
$command->setSql($sql); |
45
|
328 |
|
} |
46
|
|
|
|
47
|
|
|
if ($this->logger !== null) { |
48
|
328 |
|
$command->setLogger($this->logger); |
49
|
328 |
|
} |
50
|
|
|
|
51
|
|
|
if ($this->profiler !== null) { |
52
|
328 |
|
$command->setProfiler($this->profiler); |
53
|
|
|
} |
54
|
|
|
|
55
|
8 |
|
return $command->bindValues($params); |
56
|
|
|
} |
57
|
8 |
|
|
58
|
|
|
public function createTransaction(): TransactionInterface |
59
|
|
|
{ |
60
|
9 |
|
return new TransactionPDOSqlite($this); |
61
|
|
|
} |
62
|
9 |
|
|
63
|
|
|
public function getDriverName(): string |
64
|
|
|
{ |
65
|
|
|
return 'sqlite'; |
66
|
|
|
} |
67
|
|
|
|
68
|
328 |
|
/** |
69
|
|
|
* @throws Exception|InvalidConfigException |
70
|
328 |
|
*/ |
71
|
328 |
|
public function getQueryBuilder(): QueryBuilderInterface |
72
|
328 |
|
{ |
73
|
328 |
|
if ($this->queryBuilder === null) { |
74
|
328 |
|
$this->queryBuilder = new QueryBuilderPDOSqlite( |
75
|
|
|
$this->createCommand(), |
76
|
|
|
$this->getQuoter(), |
77
|
|
|
$this->getSchema(), |
78
|
328 |
|
); |
79
|
|
|
} |
80
|
|
|
|
81
|
344 |
|
return $this->queryBuilder; |
|
|
|
|
82
|
|
|
} |
83
|
344 |
|
|
84
|
344 |
|
public function getQuoter(): QuoterInterface |
85
|
|
|
{ |
86
|
|
|
if ($this->quoter === null) { |
87
|
344 |
|
$this->quoter = new Quoter('`', '`', $this->getTablePrefix()); |
88
|
|
|
} |
89
|
|
|
|
90
|
342 |
|
return $this->quoter; |
|
|
|
|
91
|
|
|
} |
92
|
342 |
|
|
93
|
342 |
|
public function getSchema(): SchemaInterface |
94
|
|
|
{ |
95
|
|
|
if ($this->schema === null) { |
96
|
342 |
|
$this->schema = new SchemaPDOSqlite($this, $this->schemaCache); |
|
|
|
|
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
return $this->schema; |
|
|
|
|
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Initializes the DB connection. |
104
|
|
|
* |
105
|
|
|
* This method is invoked right after the DB connection is established. |
106
|
|
|
* |
107
|
|
|
* The default implementation turns on `PDO::ATTR_EMULATE_PREPARES`. |
108
|
|
|
* |
109
|
|
|
* if {@see emulatePrepare} is true, and sets the database {@see charset} if it is not empty. |
110
|
176 |
|
* |
111
|
|
|
* It then triggers an {@see EVENT_AFTER_OPEN} event. |
112
|
176 |
|
*/ |
113
|
176 |
|
protected function initConnection(): void |
114
|
|
|
{ |
115
|
176 |
|
$this->pdo = $this->driver->createConnection(); |
116
|
|
|
$this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
117
|
|
|
|
118
|
|
|
if ($this->getEmulatePrepare() !== null && constant('PDO::ATTR_EMULATE_PREPARES')) { |
119
|
|
|
$this->pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, $this->getEmulatePrepare()); |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
|
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