-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathSqliteDriver.php
More file actions
65 lines (51 loc) · 1.58 KB
/
SqliteDriver.php
File metadata and controls
65 lines (51 loc) · 1.58 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
<?php
declare(strict_types=1);
namespace CzProject\SqlGenerator\Drivers;
use CzProject\SqlGenerator\IDriver;
use DateTimeInterface;
use SQLite3;
/**
* @see https://sqlite.org/lang_keywords.html
*/
class SqliteDriver implements IDriver
{
use DateParserTrait;
public bool $modifyColumn = false;
/**
* @var string[]
*/
private const TRANSACTION = [
'start' => 'BEGIN TRANSACTION;',
'commit' => 'COMMIT TRANSACTION;',
'rollback' => 'ROLLBACK TRANSACTION;',
];
private const LAST_ID = 'LAST_INSERT_ROWID()';
public function escapeIdentifier(string $value): string
{
return '"'.str_replace('"', '""', $value).'"';
}
public function escapeText(string $value): string
{
return "'".SQLite3::escapeString($value)."'";
}
public function escapeBool(bool $value): string
{
return strval($value ? 1 : 0);
}
public function escapeDate(DateTimeInterface|string $value): string
{
return $this->escapeText($this->dateFormat($value, 'Y-m-d'));
}
public function escapeDateTime(DateTimeInterface|string $value): string
{
return $this->escapeText($this->dateFormat($value, 'Y-m-d H:i:s'));
}
public function transaction(string $action): string
{
return self::TRANSACTION[$action];
}
public function lastId(): string
{
return self::LAST_ID;
}
}