aboutsummaryrefslogtreecommitdiff
path: root/app/Models/DatabaseDAOPGSQL.php
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2016-08-02 23:02:47 +0200
committerGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2016-08-02 23:02:47 +0200
commitd5382ff0d06fd9f202ca2e6d3fb3cb757ed912e3 (patch)
tree4d401bfdfabba98f3429f35cc608d4bf94f26f71 /app/Models/DatabaseDAOPGSQL.php
parent7c1b5e322cca0134f57b3a436129985ba9170b9f (diff)
DatabaseDAO for PostgreSQL
From https://github.com/Damstre/FreshRSS/blob/be2b15d12c413755be64ecb0625dce5a8ad280bf/app/Models/DatabaseDAOpgSQL.php
Diffstat (limited to 'app/Models/DatabaseDAOPGSQL.php')
-rw-r--r--app/Models/DatabaseDAOPGSQL.php43
1 files changed, 43 insertions, 0 deletions
diff --git a/app/Models/DatabaseDAOPGSQL.php b/app/Models/DatabaseDAOPGSQL.php
new file mode 100644
index 000000000..a4edaa448
--- /dev/null
+++ b/app/Models/DatabaseDAOPGSQL.php
@@ -0,0 +1,43 @@
+<?php
+
+/**
+ * This class is used to test database is well-constructed.
+ */
+class FreshRSS_DatabaseDAOPGSQL extends FreshRSS_DatabaseDAO {
+ public function tablesAreCorrect() {
+ $db = FreshRSS_Context::$system_conf->db;
+ $dbowner = $db['user'];
+ $sql = 'SELECT * FROM pg_catalog.pg_tables where tableowner=?';
+ $stm = $this->bd->prepare($sql);
+ $values = array($dbowner);
+ $stm->execute($values);
+ $res = $stm->fetchAll(PDO::FETCH_ASSOC);
+
+ $tables = array(
+ $this->prefix . 'category' => false,
+ $this->prefix . 'feed' => false,
+ $this->prefix . 'entry' => false,
+ );
+ foreach ($res as $value) {
+ $tables[array_pop($value)] = true;
+ }
+
+ return count(array_keys($tables, true, true)) == count($tables);
+ }
+
+ public function getSchema($table) {
+ $sql = 'select column_name as field, data_type as type, column_default as default, is_nullable as null from INFORMATION_SCHEMA.COLUMNS where table_name = ?';
+ $stm = $this->bd->prepare($sql);
+ $stm->execute(array($this->prefix . $table));
+ return $this->listDaoToSchema($stm->fetchAll(PDO::FETCH_ASSOC));
+ }
+
+ public function daoToSchema($dao) {
+ return array(
+ 'name' => $dao['field'],
+ 'type' => strtolower($dao['type']),
+ 'notnull' => (bool)$dao['null'],
+ 'default' => $dao['default'],
+ );
+ }
+}