Rev 496 | Rev 511 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 496 | Rev 502 | ||
---|---|---|---|
Line 19... | Line 19... | ||
19 | 19 | ||
20 | abstract class OIDplusDatabaseConnection { |
20 | abstract class OIDplusDatabaseConnection { |
21 | protected /*bool*/ $connected = false; |
21 | protected /*bool*/ $connected = false; |
22 | protected /*?bool*/ $html = null; |
22 | protected /*?bool*/ $html = null; |
23 | protected /*?string*/ $last_query = null; |
23 | protected /*?string*/ $last_query = null; |
- | 24 | protected /*bool*/ $slangDetectionDone = false; |
|
24 | 25 | ||
25 | public abstract static function getPlugin(): OIDplusDatabasePlugin; |
26 | public abstract static function getPlugin(): OIDplusDatabasePlugin; |
26 | protected abstract function doQuery(string $sql, /*?array*/ $prepared_args=null): OIDplusQueryResult; |
27 | protected abstract function doQuery(string $sql, /*?array*/ $prepared_args=null): OIDplusQueryResult; |
27 | public abstract function error(): string; |
28 | public abstract function error(): string; |
28 | public abstract function transaction_begin()/*: void*/; |
29 | public abstract function transaction_begin()/*: void*/; |
Line 55... | Line 56... | ||
55 | file_put_contents($query_logfile, "$ts <$log_session_id$file> $sql\n", FILE_APPEND); |
56 | file_put_contents($query_logfile, "$ts <$log_session_id$file> $sql\n", FILE_APPEND); |
56 | } |
57 | } |
57 | 58 | ||
58 | $this->last_query = $sql; |
59 | $this->last_query = $sql; |
59 | $sql = str_replace('###', OIDplus::baseConfig()->getValue('TABLENAME_PREFIX', ''), $sql); |
60 | $sql = str_replace('###', OIDplus::baseConfig()->getValue('TABLENAME_PREFIX', ''), $sql); |
- | 61 | ||
- | 62 | if ($this->slangDetectionDone) { |
|
- | 63 | $slang = $this->getSlang(); |
|
- | 64 | if ($slang) { |
|
- | 65 | $sql = $slang->filterQuery($sql); |
|
- | 66 | } |
|
- | 67 | } |
|
- | 68 | ||
60 | return $this->doQuery($sql, $prepared_args); |
69 | return $this->doQuery($sql, $prepared_args); |
61 | } |
70 | } |
62 | 71 | ||
63 | public final function connect()/*: void*/ { |
72 | public final function connect()/*: void*/ { |
64 | if ($this->connected) return; |
73 | if ($this->connected) return; |
Line 184... | Line 193... | ||
184 | } else { |
193 | } else { |
185 | return "'" . date('Y-m-d H:i:s') . "'"; |
194 | return "'" . date('Y-m-d H:i:s') . "'"; |
186 | } |
195 | } |
187 | } |
196 | } |
188 | 197 | ||
189 | public function getSlang(bool $mustExist=true)/*: ?OIDplusSqlSlangPlugin*/ { |
198 | protected function doGetSlang(bool $mustExist=true)/*: ?OIDplusSqlSlangPlugin*/ { |
190 | static /*?OIDplusSqlSlangPlugin*/ $slangCache = null; |
199 | $res = null; |
191 | 200 | ||
192 | if (is_null($slangCache)) { |
- | |
193 | if (OIDplus::baseConfig()->exists('FORCE_DBMS_SLANG')) { |
201 | if (OIDplus::baseConfig()->exists('FORCE_DBMS_SLANG')) { |
194 | $name = OIDplus::baseConfig()->getValue('FORCE_DBMS_SLANG', ''); |
202 | $name = OIDplus::baseConfig()->getValue('FORCE_DBMS_SLANG', ''); |
195 | $slangCache = OIDplus::getSqlSlangPlugin($name); |
203 | $res = OIDplus::getSqlSlangPlugin($name); |
196 | if ($mustExist && is_null($slangCache)) { |
204 | if ($mustExist && is_null($res)) { |
197 | throw new OIDplusConfigInitializationException(_L('Enforced SQL slang (via setting FORCE_DBMS_SLANG) "%1" does not exist.',$name)); |
205 | throw new OIDplusConfigInitializationException(_L('Enforced SQL slang (via setting FORCE_DBMS_SLANG) "%1" does not exist.',$name)); |
198 | } |
206 | } |
199 | } else { |
207 | } else { |
200 | foreach (OIDplus::getSqlSlangPlugins() as $plugin) { |
208 | foreach (OIDplus::getSqlSlangPlugins() as $plugin) { |
201 | if ($plugin->detect($this)) { |
209 | if ($plugin->detect($this)) { |
- | 210 | if (OIDplus::baseConfig()->getValue('DEBUG') && !is_null($res)) { |
|
- | 211 | throw new OIDplusException(_L('DB-Slang detection failed: Multiple slangs were detected. Use base config setting FORCE_DBMS_SLANG to define one.')); |
|
- | 212 | } |
|
- | 213 | ||
202 | $slangCache = $plugin; |
214 | $res = $plugin; |
- | 215 | ||
- | 216 | if (!OIDplus::baseConfig()->getValue('DEBUG')) { |
|
203 | break; |
217 | break; |
204 | } |
218 | } |
205 | } |
219 | } |
- | 220 | } |
|
206 | if ($mustExist && is_null($slangCache)) { |
221 | if ($mustExist && is_null($res)) { |
207 | throw new OIDplusException(_L('Cannot determine the SQL slang of your DBMS. Your DBMS is probably not supported.')); |
222 | throw new OIDplusException(_L('Cannot determine the SQL slang of your DBMS. Your DBMS is probably not supported.')); |
208 | } |
223 | } |
209 | } |
224 | } |
- | 225 | ||
- | 226 | return $res; |
|
- | 227 | } |
|
- | 228 | ||
- | 229 | public final function getSlang(bool $mustExist=true)/*: ?OIDplusSqlSlangPlugin*/ { |
|
- | 230 | static /*?OIDplusSqlSlangPlugin*/ $slangCache = null; |
|
- | 231 | ||
- | 232 | if ($this->slangDetectionDone) { |
|
- | 233 | return $slangCache; |
|
210 | } |
234 | } |
211 | 235 | ||
- | 236 | $slangCache = $this->doGetSlang(); |
|
- | 237 | $this->slangDetectionDone = true; |
|
212 | return $slangCache; |
238 | return $slangCache; |
213 | } |
239 | } |
214 | } |
240 | } |