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
|
235 |
|
public function createCommand(string $sql = null, array $params = []): CommandPDOInterface |
37
|
|
|
{ |
38
|
235 |
|
$command = new CommandPDO($this, $this->queryCache); |
39
|
|
|
|
40
|
235 |
|
if ($sql !== null) { |
41
|
203 |
|
$command->setSql($sql); |
42
|
|
|
} |
43
|
|
|
|
44
|
235 |
|
if ($this->logger !== null) { |
45
|
97 |
|
$command->setLogger($this->logger); |
46
|
|
|
} |
47
|
|
|
|
48
|
235 |
|
if ($this->profiler !== null) { |
49
|
97 |
|
$command->setProfiler($this->profiler); |
50
|
|
|
} |
51
|
|
|
|
52
|
235 |
|
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
|
452 |
|
public function getQueryBuilder(): QueryBuilderInterface |
64
|
|
|
{ |
65
|
452 |
|
if ($this->queryBuilder === null) { |
66
|
452 |
|
$this->queryBuilder = new QueryBuilder( |
67
|
452 |
|
$this->getQuoter(), |
68
|
452 |
|
$this->getSchema(), |
69
|
|
|
); |
70
|
|
|
} |
71
|
|
|
|
72
|
452 |
|
return $this->queryBuilder; |
|
|
|
|
73
|
|
|
} |
74
|
|
|
|
75
|
490 |
|
public function getQuoter(): QuoterInterface |
76
|
|
|
{ |
77
|
490 |
|
if ($this->quoter === null) { |
78
|
490 |
|
$this->quoter = new Quoter('`', '`', $this->getTablePrefix()); |
79
|
|
|
} |
80
|
|
|
|
81
|
490 |
|
return $this->quoter; |
|
|
|
|
82
|
|
|
} |
83
|
|
|
|
84
|
473 |
|
public function getSchema(): SchemaInterface |
85
|
|
|
{ |
86
|
473 |
|
if ($this->schema === null) { |
87
|
473 |
|
$this->schema = new Schema($this, $this->schemaCache); |
88
|
|
|
} |
89
|
|
|
|
90
|
473 |
|
return $this->schema; |
|
|
|
|
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|