1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Lagdo\DbAdmin\Driver\Sqlite; |
4
|
|
|
|
5
|
|
|
use Lagdo\DbAdmin\Driver\Exception\AuthException; |
6
|
|
|
use Lagdo\DbAdmin\Driver\Driver as AbstractDriver; |
7
|
|
|
|
8
|
|
|
use function class_exists; |
9
|
|
|
use function extension_loaded; |
10
|
|
|
|
11
|
|
|
class Driver extends AbstractDriver |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @inheritDoc |
15
|
|
|
*/ |
16
|
|
|
protected function initDriver() |
17
|
|
|
{ |
18
|
|
|
// Init config |
19
|
|
|
$this->config->jush = 'sqlite'; |
20
|
|
|
$this->config->drivers = ["SQLite3", "PDO_SQLite"]; |
21
|
|
|
$this->config->setTypes([ //! arrays |
22
|
|
|
'Numbers' => ["integer" => 0, "real" => 0, "numeric" => 0], |
23
|
|
|
'Strings' => ["text" => 0], |
24
|
|
|
'Binary' => ["blob" => 0], |
25
|
|
|
]); |
26
|
|
|
// $this->config->unsigned = []; |
27
|
|
|
$this->config->operators = ["=", "<", ">", "<=", ">=", "!=", "LIKE", "LIKE %%", |
28
|
|
|
"IN", "IS NULL", "NOT LIKE", "NOT IN", "IS NOT NULL", "SQL"]; // REGEXP can be user defined function; |
29
|
|
|
$this->config->functions = ["hex", "length", "lower", "round", "unixepoch", "upper"]; |
30
|
|
|
$this->config->grouping = ["avg", "count", "count distinct", "group_concat", "max", "min", "sum"]; |
31
|
|
|
$this->config->editFunctions = [[ |
32
|
|
|
// "text" => "date('now')/time('now')/datetime('now')", |
33
|
|
|
],[ |
34
|
|
|
"integer|real|numeric" => "+/-", |
35
|
|
|
// "text" => "date/time/datetime", |
36
|
|
|
"text" => "||", |
37
|
|
|
]]; |
38
|
|
|
$this->config->features = ['columns', 'database', 'drop_col', 'dump', 'indexes', 'descidx', |
39
|
|
|
'move_col', 'sql', 'status', 'table', 'trigger', 'variables', 'view', 'view_trigger']; |
40
|
|
|
|
41
|
|
|
$this->server = new Db\Server($this, $this->util, $this->trans); |
42
|
|
|
$this->database = new Db\Database($this, $this->util, $this->trans); |
43
|
|
|
$this->table = new Db\Table($this, $this->util, $this->trans); |
44
|
|
|
$this->query = new Db\Query($this, $this->util, $this->trans); |
45
|
|
|
$this->grammar = new Db\Grammar($this, $this->util, $this->trans); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @inheritDoc |
50
|
|
|
*/ |
51
|
|
|
public function name() |
52
|
|
|
{ |
53
|
|
|
return "SQLite 3"; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @inheritDoc |
58
|
|
|
* @throws AuthException |
59
|
|
|
*/ |
60
|
|
|
public function createConnection() |
61
|
|
|
{ |
62
|
|
|
if (!$this->options('prefer_pdo', false) && class_exists("SQLite3")) { |
63
|
|
|
$connection = new Db\Sqlite\Connection($this, $this->util, $this->trans, 'SQLite3'); |
64
|
|
|
return $this->connection = $connection; |
65
|
|
|
} |
66
|
|
|
if (extension_loaded("pdo_sqlite")) { |
67
|
|
|
$connection = new Db\Pdo\Connection($this, $this->util, $this->trans, 'PDO_SQLite'); |
68
|
|
|
return $this->connection = $connection; |
69
|
|
|
} |
70
|
|
|
throw new AuthException($this->trans->lang('No package installed to open a Sqlite database.')); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|