forked from php-db/phpdb-sqlite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSqlite.php
More file actions
88 lines (71 loc) · 1.87 KB
/
Sqlite.php
File metadata and controls
88 lines (71 loc) · 1.87 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
86
87
88
<?php
declare(strict_types=1);
namespace PhpDb\Adapter\Sqlite\Platform;
use Override;
use PDO;
use PhpDb\Adapter\Driver\PdoDriverInterface;
use PhpDb\Adapter\Platform\AbstractPlatform;
use PhpDb\Adapter\Sqlite\Sql\Platform\Sqlite as SqlPlatformDecorator;
use PhpDb\Sql\Platform\PlatformDecoratorInterface;
class Sqlite extends AbstractPlatform
{
public final const PLATFORM_NAME = 'SQLite';
/** @var string[] */
protected $quoteIdentifier = ['"', '"'];
/** @var PDO */
protected $resource;
/**
* {@inheritDoc}
*/
protected $quoteIdentifierTo = '\'';
public function __construct(
protected readonly PdoDriverInterface|PDO $driver
) {
}
/**
* {@inheritDoc}
*/
#[Override]
public function quoteValue(string $value): string
{
$resource = $this->resource;
if ($resource instanceof PdoDriverInterface) {
$resource = $resource->getConnection()->getResource();
}
if ($resource instanceof \PDO) {
return $resource->quote($value);
}
return parent::quoteValue($value);
}
/**
* {@inheritDoc}
*/
#[Override]
public function quoteTrustedValue(int|float|string|bool $value): ?string
{
$resource = $this->resource;
if ($resource instanceof PdoDriverInterface) {
$resource = $resource->getConnection()->getResource();
}
if ($resource instanceof \PDO) {
return $resource->quote($value);
}
return parent::quoteTrustedValue($value);
}
/**
* {@inheritDoc}
*/
#[Override]
public function getName(): string
{
return self::PLATFORM_NAME;
}
/**
* {@inheritDoc}
*/
#[Override]
public function getSqlPlatformDecorator(): PlatformDecoratorInterface
{
return new SqlPlatformDecorator();
}
}