protected function Query($query) { // SPConfig::debOut( $query, false, false, true ); switch ($this->_driver) { case 'SQLITE': try { if ($r = $this->_db->query($query, SQLITE_ASSOC)) { $r = $r->fetch(); } else { Sobi::Error('cache', sprintf('SQLite error on query: %s', $query), SPC::WARNING, 0, __LINE__, __FILE__); return false; } } catch (SQLiteException $x) { Sobi::Error('cache', sprintf('SQLite error: %s', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__); $this->_enabled = false; $this->cleanAll(); return false; } break; case 'PDO': if ($s = $this->_db->prepare($query)) { $s->execute(); $r = $s->fetch(PDO::FETCH_ASSOC); } else { Sobi::Error('cache', sprintf('SQLite error on query: %s. Error %s', $query, implode("\n", $this->_db->errorInfo())), SPC::WARNING, 0, __LINE__, __FILE__); $this->_enabled = false; $this->cleanAll(); return false; } break; } return $r; }
public function select($filter) { $sql = "SELECT * FROM {$this->name} WHERE " . $this->filterToSql($filter); $res = self::$conn->query($sql); if ($res === false) { $error = self::$conn->errorInfo(); switch ($error[0]) { case 'HY000': throw new DataStoreNoTableError("Table [{$this->name}] doesn't exists in [{$sql}]"); break; default: throw new DataStoreError("Error {$error[2]} ({$error[0]}/{$error[1]}) in query {$sql}"); } return false; } return $res->fetch(); }