Rev 1086 | Rev 1148 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1086 | Rev 1116 | ||
---|---|---|---|
Line 23... | Line 23... | ||
23 | \defined('INSIDE_OIDPLUS') or die; |
23 | \defined('INSIDE_OIDPLUS') or die; |
24 | // phpcs:enable PSR1.Files.SideEffects |
24 | // phpcs:enable PSR1.Files.SideEffects |
25 | 25 | ||
26 | class OIDplusSqlSlangPluginSQLite extends OIDplusSqlSlangPlugin { |
26 | class OIDplusSqlSlangPluginSQLite extends OIDplusSqlSlangPlugin { |
27 | 27 | ||
- | 28 | /** |
|
- | 29 | * @return string |
|
- | 30 | */ |
|
28 | public static function id(): string { |
31 | public static function id(): string { |
29 | return 'sqlite'; |
32 | return 'sqlite'; |
30 | } |
33 | } |
31 | 34 | ||
- | 35 | /** |
|
- | 36 | * @param string $fieldname |
|
- | 37 | * @param string $order |
|
- | 38 | * @return string |
|
- | 39 | * @throws OIDplusException |
|
- | 40 | */ |
|
32 | public function natOrder($fieldname, $order='asc'): string { |
41 | public function natOrder(string $fieldname, string $order='asc'): string { |
33 | 42 | ||
34 | $order = strtolower($order); |
43 | $order = strtolower($order); |
35 | if (($order != 'asc') && ($order != 'desc')) { |
44 | if (($order != 'asc') && ($order != 'desc')) { |
36 | throw new OIDplusException(_L('Invalid order "%1" (needs to be "asc" or "desc")',$order)); |
45 | throw new OIDplusException(_L('Invalid order "%1" (needs to be "asc" or "desc")',$order)); |
37 | } |
46 | } |
Line 71... | Line 80... | ||
71 | 80 | ||
72 | return implode(', ', $out); |
81 | return implode(', ', $out); |
73 | 82 | ||
74 | } |
83 | } |
75 | 84 | ||
- | 85 | /** |
|
- | 86 | * @return string |
|
- | 87 | */ |
|
76 | public function sqlDate(): string { |
88 | public function sqlDate(): string { |
77 | return 'datetime()'; |
89 | return 'datetime()'; |
78 | } |
90 | } |
79 | 91 | ||
- | 92 | /** |
|
- | 93 | * @param OIDplusDatabaseConnection $db |
|
- | 94 | * @return bool |
|
- | 95 | */ |
|
80 | public function detect(OIDplusDatabaseConnection $db): bool { |
96 | public function detect(OIDplusDatabaseConnection $db): bool { |
81 | try { |
97 | try { |
82 | $db->query("select sqlite_version as dbms_version"); |
98 | $db->query("select sqlite_version as dbms_version"); |
83 | return true; |
99 | return true; |
84 | } catch (\Exception $e) { |
100 | } catch (\Exception $e) { |
85 | return false; |
101 | return false; |
86 | } |
102 | } |
87 | } |
103 | } |
88 | 104 | ||
- | 105 | /** |
|
- | 106 | * @param OIDplusDatabaseConnection $db |
|
- | 107 | * @return int |
|
- | 108 | * @throws OIDplusException |
|
- | 109 | */ |
|
89 | public function insert_id(OIDplusDatabaseConnection $db): int { |
110 | public function insert_id(OIDplusDatabaseConnection $db): int { |
90 | $res = $db->query("SELECT last_insert_rowid() AS ID"); |
111 | $res = $db->query("SELECT last_insert_rowid() AS ID"); |
91 | $row = $res->fetch_array(); |
112 | $row = $res->fetch_array(); |
92 | return (int)$row['ID']; |
113 | return (int)$row['ID']; |
93 | } |
114 | } |
94 | 115 | ||
- | 116 | /** |
|
- | 117 | * @param string $cont |
|
- | 118 | * @param string $table |
|
- | 119 | * @param string $prefix |
|
- | 120 | * @return string |
|
- | 121 | */ |
|
95 | public function setupSetTablePrefix($cont, $table, $prefix): string { |
122 | public function setupSetTablePrefix(string $cont, string $table, string $prefix): string { |
96 | $cont = str_replace('`'.$table.'`', '`'.$prefix.$table.'`', $cont); |
123 | $cont = str_replace('`'.$table.'`', '`'.$prefix.$table.'`', $cont); |
97 | return $cont; |
124 | return $cont; |
98 | } |
125 | } |
99 | 126 | ||
- | 127 | /** |
|
- | 128 | * @param string $database |
|
- | 129 | * @return string |
|
- | 130 | */ |
|
100 | public function setupCreateDbIfNotExists($database): string { |
131 | public function setupCreateDbIfNotExists(string $database): string { |
101 | return ""; |
132 | return ""; |
102 | } |
133 | } |
103 | 134 | ||
- | 135 | /** |
|
- | 136 | * @param string $database |
|
- | 137 | * @return string |
|
- | 138 | */ |
|
104 | public function setupUseDatabase($database): string { |
139 | public function setupUseDatabase(string $database): string { |
105 | return ""; |
140 | return ""; |
106 | } |
141 | } |
107 | 142 | ||
- | 143 | /** |
|
- | 144 | * @param string $expr1 |
|
- | 145 | * @param string $expr2 |
|
- | 146 | * @return string |
|
- | 147 | */ |
|
108 | public function isNullFunction($expr1, $expr2): string { |
148 | public function isNullFunction(string $expr1, string $expr2): string { |
109 | return "ifnull($expr1, $expr2)"; |
149 | return "ifnull($expr1, $expr2)"; |
110 | } |
150 | } |
111 | 151 | ||
- | 152 | /** |
|
- | 153 | * @param string $sql |
|
- | 154 | * @return string |
|
- | 155 | */ |
|
112 | public function filterQuery($sql): string { |
156 | public function filterQuery(string $sql): string { |
113 | return $sql; |
157 | return $sql; |
114 | } |
158 | } |
115 | 159 | ||
- | 160 | /** |
|
- | 161 | * @param bool $bool |
|
- | 162 | * @return string |
|
- | 163 | */ |
|
116 | public function getSQLBool($bool): string { |
164 | public function getSQLBool(bool $bool): string { |
117 | return $bool ? '1' : '0'; |
165 | return $bool ? '1' : '0'; |
118 | } |
166 | } |
119 | 167 | ||
- | 168 | /** |
|
- | 169 | * @param string $str |
|
- | 170 | * @return string |
|
- | 171 | */ |
|
120 | public function escapeString($str): string { |
172 | public function escapeString(string $str): string { |
121 | return str_replace("'", "''", $str); |
173 | return str_replace("'", "''", $str); |
122 | } |
174 | } |
123 | } |
175 | } |