|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Yiisoft\Db\Sqlite; |
|
6
|
|
|
|
|
7
|
|
|
use PDO; |
|
8
|
|
|
use Yiisoft\Db\Driver\PDO\CommandPDOInterface; |
|
9
|
|
|
use Yiisoft\Db\Driver\PDO\ConnectionPDO as AbstractConnectionPDO; |
|
10
|
|
|
use Yiisoft\Db\Exception\Exception; |
|
11
|
|
|
use Yiisoft\Db\Exception\InvalidConfigException; |
|
12
|
|
|
use Yiisoft\Db\QueryBuilder\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
|
|
|
/** |
|
19
|
|
|
* Database connection class prefilled for SQLite Server. |
|
20
|
|
|
*/ |
|
21
|
|
|
final class ConnectionPDO extends AbstractConnectionPDO |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* Reset the connection after cloning. |
|
25
|
|
|
*/ |
|
26
|
1 |
|
public function __clone() |
|
27
|
|
|
{ |
|
28
|
1 |
|
$this->transaction = null; |
|
29
|
|
|
|
|
30
|
1 |
|
if (!str_starts_with($this->driver->getDsn(), 'sqlite::memory:')) { |
|
31
|
|
|
/** reset PDO connection, unless its sqlite in-memory, which can only have one connection */ |
|
32
|
1 |
|
$this->pdo = null; |
|
33
|
|
|
} |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
231 |
|
public function createCommand(string $sql = null, array $params = []): CommandPDOInterface |
|
37
|
|
|
{ |
|
38
|
231 |
|
$command = new CommandPDO($this, $this->queryCache); |
|
39
|
|
|
|
|
40
|
231 |
|
if ($sql !== null) { |
|
41
|
199 |
|
$command->setSql($sql); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
231 |
|
if ($this->logger !== null) { |
|
45
|
97 |
|
$command->setLogger($this->logger); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
231 |
|
if ($this->profiler !== null) { |
|
49
|
97 |
|
$command->setProfiler($this->profiler); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
231 |
|
return $command->bindValues($params); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
12 |
|
public function createTransaction(): TransactionInterface |
|
56
|
|
|
{ |
|
57
|
12 |
|
return new TransactionPDO($this); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @throws Exception|InvalidConfigException |
|
62
|
|
|
*/ |
|
63
|
449 |
|
public function getQueryBuilder(): QueryBuilderInterface |
|
64
|
|
|
{ |
|
65
|
449 |
|
if ($this->queryBuilder === null) { |
|
66
|
449 |
|
$this->queryBuilder = new QueryBuilder( |
|
67
|
449 |
|
$this->getQuoter(), |
|
68
|
449 |
|
$this->getSchema(), |
|
69
|
|
|
); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
449 |
|
return $this->queryBuilder; |
|
|
|
|
|
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
487 |
|
public function getQuoter(): QuoterInterface |
|
76
|
|
|
{ |
|
77
|
487 |
|
if ($this->quoter === null) { |
|
78
|
487 |
|
$this->quoter = new Quoter('`', '`', $this->getTablePrefix()); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
487 |
|
return $this->quoter; |
|
|
|
|
|
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
470 |
|
public function getSchema(): SchemaInterface |
|
85
|
|
|
{ |
|
86
|
470 |
|
if ($this->schema === null) { |
|
87
|
470 |
|
$this->schema = new Schema($this, $this->schemaCache); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
470 |
|
return $this->schema; |
|
|
|
|
|
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|