-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdb_mysql_lite.php
112 lines (95 loc) · 3.05 KB
/
db_mysql_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
<?php
// CubicleSoft MySQL/Maria DB lightweight database interface.
// (C) 2021 CubicleSoft. All Rights Reserved.
if (!class_exists("CSDB", false)) require_once str_replace("\\", "/", dirname(__FILE__)) . "/db.php";
class CSDB_mysql_lite extends CSDB
{
public function IsAvailable()
{
return (class_exists("PDO") && in_array("mysql", PDO::getAvailableDrivers()) ? "mysql" : false);
}
public function GetDisplayName()
{
return CSDB::DB_Translate("MySQL/Maria DB (via PDO, Lite version)");
}
public function Connect($dsn, $username = false, $password = false, $options = array())
{
parent::Connect($dsn, $username, $password, $options);
// Set Unicode support.
$this->Query("SET", "NAMES 'utf8mb4'");
}
public function GetInsertID($name = null)
{
return $this->GetOne("SELECT", array("LAST_INSERT_ID()"));
}
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(
"PRECOLUMN" => array("DISTINCT" => "bool", "HIGH_PRIORITY" => "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(
"PREINTO" => array("LOW_PRIORITY" => "bool", "DELAYED" => "bool", "HIGH_PRIORITY" => "bool", "IGNORE" => "bool"),
"SELECT" => true,
"BULKINSERT" => true
);
return $this->ProcessINSERT($master, $sql, $opts, $queryinfo, $args, $subquery, $supported);
}
case "UPDATE":
{
$supported = array(
"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(
"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":
{
$sql = "SET " . $queryinfo;
return array("success" => true);
}
case "USE":
{
$sql = "USE " . $this->QuoteIdentifier($queryinfo);
return array("success" => true);
}
case "TRUNCATE TABLE":
{
$master = true;
$sql = "TRUNCATE TABLE " . $this->QuoteIdentifier($queryinfo[0]);
return array("success" => true);
}
}
return array("success" => false, "error" => CSDB::DB_Translate("Unknown query command '%s'.", $cmd), "errorcode" => "unknown_query_command");
}
}
?>