diff --git a/core/DB/SQLitePDO.class.php b/core/DB/SQLitePDO.class.php new file mode 100644 index 0000000000..3f62865a27 --- /dev/null +++ b/core/DB/SQLitePDO.class.php @@ -0,0 +1,175 @@ +link = new PDO( + "sqlite:{$this->basename}", + '', + '', + array(PDO::ATTR_PERSISTENT => $this->persistent) + ); + } catch (PDOException $e) { + throw new DatabaseException( + 'can not open SQLitePDO base: ' + .$e->getMessage() + ); + } + + return $this; + } + + /** + * @return SQLitePDO + **/ + public function disconnect() + { + if ($this->link) { + $this->link = null; + } + + return $this; + } + + public function isConnected() + { + return $this->link !== null; + } + + /** + * misc + **/ + public function setDbEncoding() + { + throw new UnsupportedMethodException(); + } + + /** + * query methods + **/ + public function queryRaw($queryString) + { + try { + $res = $this->link->query($queryString); + return $res; + } catch (PDOException $e) { + $code = $e->getCode(); + + if ($code == self::ERROR_CONSTRAINT) + $e = 'DuplicateObjectException'; + else + $e = 'DatabaseException'; + + throw new $e( + $e->getMessage(), + $code + ); + } + } + + /** + * Same as query, but returns number of affected rows + * Returns number of affected rows in insert/update queries + **/ + public function queryCount(Query $query) + { + $res = $this->queryNull($query); + /* @var $res PDOStatement */ + + return $res->rowCount(); + } + + public function queryRow(Query $query) + { + $res = $this->query($query); + /* @var $res PDOStatement */ + + $array = $res->fetchAll(PDO::FETCH_ASSOC); + if (count($array) > 1) + throw new TooManyRowsException( + 'query returned too many rows (we need only one)' + ); + elseif (count($array) == 1) + return reset($array); + else + return null; + } + + public function queryColumn(Query $query) + { + $res = $this->query($query); + /* @var $res PDOStatement */ + + $resArray = $res->fetchAll(PDO::FETCH_ASSOC); + if ($resArray) { + $array = array(); + foreach ($resArray as $row) { + $array[] = reset($row); + } + + return $array; + } else + return null; + } + + public function querySet(Query $query) + { + $res = $this->query($query); + /* @var $res PDOStatement */ + + return $res->fetchAll(PDO::FETCH_ASSOC) ?: null; + } + + public function hasQueue() + { + return false; + } + + public function getTableInfo($table) + { + throw new UnimplementedFeatureException(); + } + + protected function getInsertId() + { + return $this->link->lastInsertId(); + } + } +?> \ No newline at end of file