1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Yiisoft\Db\Sqlite; |
6
|
|
|
|
7
|
|
|
use Yiisoft\Db\Driver\PDO\AbstractConnectionPDO; |
8
|
|
|
use Yiisoft\Db\Driver\PDO\CommandPDOInterface; |
9
|
|
|
use Yiisoft\Db\QueryBuilder\QueryBuilderInterface; |
10
|
|
|
use Yiisoft\Db\Schema\Quoter; |
11
|
|
|
use Yiisoft\Db\Schema\QuoterInterface; |
12
|
|
|
use Yiisoft\Db\Schema\SchemaInterface; |
13
|
|
|
use Yiisoft\Db\Transaction\TransactionInterface; |
14
|
|
|
|
15
|
|
|
use function str_starts_with; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Implements a connection to a database via PDO (PHP Data Objects) for SQLite Server. |
19
|
|
|
* |
20
|
|
|
* @link https://www.php.net/manual/en/ref.pdo-sqlite.php |
21
|
|
|
*/ |
22
|
|
|
final class Connection extends AbstractConnectionPDO |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* Reset the connection after cloning. |
26
|
|
|
*/ |
27
|
1 |
|
public function __clone() |
28
|
|
|
{ |
29
|
1 |
|
$this->transaction = null; |
30
|
|
|
|
31
|
1 |
|
if (!str_starts_with($this->driver->getDsn(), 'sqlite::memory:')) { |
32
|
|
|
/** Reset PDO connection, unless its sqlite in-memory, which can only have one connection. */ |
33
|
1 |
|
$this->pdo = null; |
34
|
|
|
} |
35
|
|
|
} |
36
|
|
|
|
37
|
286 |
|
public function createCommand(string $sql = null, array $params = []): CommandPDOInterface |
38
|
|
|
{ |
39
|
286 |
|
$command = new Command($this); |
40
|
|
|
|
41
|
286 |
|
if ($sql !== null) { |
42
|
249 |
|
$command->setSql($sql); |
43
|
|
|
} |
44
|
|
|
|
45
|
286 |
|
if ($this->logger !== null) { |
46
|
3 |
|
$command->setLogger($this->logger); |
47
|
|
|
} |
48
|
|
|
|
49
|
286 |
|
if ($this->profiler !== null) { |
50
|
4 |
|
$command->setProfiler($this->profiler); |
51
|
|
|
} |
52
|
|
|
|
53
|
286 |
|
return $command->bindValues($params); |
54
|
|
|
} |
55
|
|
|
|
56
|
15 |
|
public function createTransaction(): TransactionInterface |
57
|
|
|
{ |
58
|
15 |
|
return new Transaction($this); |
59
|
|
|
} |
60
|
|
|
|
61
|
508 |
|
public function getQueryBuilder(): QueryBuilderInterface |
62
|
|
|
{ |
63
|
508 |
|
if ($this->queryBuilder === null) { |
64
|
508 |
|
$this->queryBuilder = new QueryBuilder( |
65
|
508 |
|
$this->getQuoter(), |
66
|
508 |
|
$this->getSchema(), |
67
|
508 |
|
); |
68
|
|
|
} |
69
|
|
|
|
70
|
508 |
|
return $this->queryBuilder; |
|
|
|
|
71
|
|
|
} |
72
|
|
|
|
73
|
538 |
|
public function getQuoter(): QuoterInterface |
74
|
|
|
{ |
75
|
538 |
|
if ($this->quoter === null) { |
76
|
538 |
|
$this->quoter = new Quoter('`', '`', $this->getTablePrefix()); |
77
|
|
|
} |
78
|
|
|
|
79
|
538 |
|
return $this->quoter; |
|
|
|
|
80
|
|
|
} |
81
|
|
|
|
82
|
536 |
|
public function getSchema(): SchemaInterface |
83
|
|
|
{ |
84
|
536 |
|
if ($this->schema === null) { |
85
|
536 |
|
$this->schema = new Schema($this, $this->schemaCache); |
86
|
|
|
} |
87
|
|
|
|
88
|
536 |
|
return $this->schema; |
|
|
|
|
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|