-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdb_sqlite_lite.php
126 lines (107 loc) · 3.47 KB
/
db_sqlite_lite.php
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?php
// CubicleSoft SQLite lightweight database interface.
// (C) 2016 CubicleSoft. All Rights Reserved.
if (!class_exists("CSDB", false)) require_once str_replace("\\", "/", dirname(__FILE__)) . "/db.php";
class CSDB_sqlite_lite extends CSDB
{
protected $dbprefix;
public function IsAvailable()
{
return (class_exists("PDO") && in_array("sqlite", PDO::getAvailableDrivers()) ? "sqlite" : false);
}
public function GetDisplayName()
{
return CSDB::DB_Translate("SQLite (via PDO, Lite version)");
}
public function Connect($dsn, $username = false, $password = false, $options = array())
{
$this->dbprefix = "";
parent::Connect($dsn, $username, $password, $options);
}
public function GetInsertID($name = null)
{
return $this->GetOne("SELECT", array("LAST_INSERT_ROWID()"));
}
public function QuoteIdentifier($str)
{
return "\"" . str_replace(array("\"", "?"), array("\"\"", ""), $str) . "\"";
}
protected function GenerateSQL(&$master, &$sql, &$opts, $cmd, $queryinfo, $args, $subquery)
{
switch ($cmd)
{
case "SELECT":
{
$supported = array(
"DBPREFIX" => $this->dbprefix,
"PRECOLUMN" => array("DISTINCT" => "bool", "SUBQUERIES" => true),
"FROM" => array("SUBQUERIES" => true),
"WHERE" => array("SUBQUERIES" => true),
"GROUP BY" => true,
"HAVING" => true,
"ORDER BY" => true,
"LIMIT" => ", "
);
return $this->ProcessSELECT($master, $sql, $opts, $queryinfo, $args, $subquery, $supported);
}
case "INSERT":
{
$supported = array(
"DBPREFIX" => $this->dbprefix,
"PREINTO" => array("LOW_PRIORITY" => "bool", "DELAYED" => "bool", "HIGH_PRIORITY" => "bool", "IGNORE" => "bool"),
"SELECT" => true,
"BULKINSERT" => true,
"BULKINSERTLIMIT" => 900,
);
return $this->ProcessINSERT($master, $sql, $opts, $queryinfo, $args, $subquery, $supported);
}
case "UPDATE":
{
$supported = array(
"DBPREFIX" => $this->dbprefix,
"PRETABLE" => array("LOW_PRIORITY" => "bool", "IGNORE" => "bool"),
"WHERE" => array("SUBQUERIES" => true),
"ORDER BY" => true,
"LIMIT" => ", "
);
return $this->ProcessUPDATE($master, $sql, $opts, $queryinfo, $args, $subquery, $supported);
}
case "DELETE":
{
$supported = array(
"DBPREFIX" => $this->dbprefix,
"PREFROM" => array("LOW_PRIORITY" => "bool", "QUICK" => "bool", "IGNORE" => "bool"),
"WHERE" => array("SUBQUERIES" => true),
"ORDER BY" => true,
"LIMIT" => ", "
);
return $this->ProcessDELETE($master, $sql, $opts, $queryinfo, $args, $subquery, $supported);
}
case "SET":
{
return array("success" => false, "errorcode" => "skip_sql_query");
}
case "USE":
{
$this->dbprefix = $this->GetDBPrefix($queryinfo);
return array("success" => false, "errorcode" => "skip_sql_query");
}
case "TRUNCATE TABLE":
{
$supported = array(
"DBPREFIX" => $this->dbprefix,
"PREFROM" => array()
);
$queryinfo = array($queryinfo[0]);
return $this->ProcessDELETE($master, $sql, $opts, $queryinfo, $args, $subquery, $supported);
}
}
return array("success" => false, "error" => CSDB::DB_Translate("Unknown query command '%s'.", $cmd), "errorcode" => "unknown_query_command");
}
private function GetDBPrefix($str)
{
$str = preg_replace('/\s+/', "_", trim(str_replace("_", " ", $str)));
return ($str != "" ? $str . "__" : "");
}
}
?>