yiisoft /
db-sqlite
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace Yiisoft\Db\Sqlite; |
||
| 6 | |||
| 7 | use Yiisoft\Db\Driver\Pdo\AbstractPdoConnection; |
||
| 8 | use Yiisoft\Db\Driver\Pdo\PdoCommandInterface; |
||
| 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 AbstractPdoConnection |
||
| 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 | 308 | public function createCommand(string $sql = null, array $params = []): PdoCommandInterface |
|
| 38 | { |
||
| 39 | 308 | $command = new Command($this); |
|
| 40 | |||
| 41 | 308 | if ($sql !== null) { |
|
| 42 | 271 | $command->setSql($sql); |
|
| 43 | } |
||
| 44 | |||
| 45 | 308 | if ($this->logger !== null) { |
|
| 46 | 3 | $command->setLogger($this->logger); |
|
| 47 | } |
||
| 48 | |||
| 49 | 308 | if ($this->profiler !== null) { |
|
| 50 | 4 | $command->setProfiler($this->profiler); |
|
| 51 | } |
||
| 52 | |||
| 53 | 308 | return $command->bindValues($params); |
|
| 54 | } |
||
| 55 | |||
| 56 | 15 | public function createTransaction(): TransactionInterface |
|
| 57 | { |
||
| 58 | 15 | return new Transaction($this); |
|
| 59 | } |
||
| 60 | |||
| 61 | 547 | public function getQueryBuilder(): QueryBuilderInterface |
|
| 62 | { |
||
| 63 | 547 | if ($this->queryBuilder === null) { |
|
| 64 | 547 | $this->queryBuilder = new QueryBuilder( |
|
| 65 | 547 | $this->getQuoter(), |
|
| 66 | 547 | $this->getSchema(), |
|
| 67 | 547 | ); |
|
| 68 | } |
||
| 69 | |||
| 70 | 547 | return $this->queryBuilder; |
|
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 71 | } |
||
| 72 | |||
| 73 | 584 | public function getQuoter(): QuoterInterface |
|
| 74 | { |
||
| 75 | 584 | if ($this->quoter === null) { |
|
| 76 | 584 | $this->quoter = new Quoter('`', '`', $this->getTablePrefix()); |
|
| 77 | } |
||
| 78 | |||
| 79 | 584 | return $this->quoter; |
|
|
0 ignored issues
–
show
|
|||
| 80 | } |
||
| 81 | |||
| 82 | 574 | public function getSchema(): SchemaInterface |
|
| 83 | { |
||
| 84 | 574 | if ($this->schema === null) { |
|
| 85 | 574 | $this->schema = new Schema($this, $this->schemaCache); |
|
| 86 | } |
||
| 87 | |||
| 88 | 574 | return $this->schema; |
|
|
0 ignored issues
–
show
|
|||
| 89 | } |
||
| 90 | } |
||
| 91 |