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