diff options
| author | 2016-10-30 20:15:11 +0100 | |
|---|---|---|
| committer | 2016-10-30 20:15:11 +0100 | |
| commit | 1d3e5bdee069434fd65c2717ae8fcce8c54fe81d (patch) | |
| tree | 39b0ae9ac0b0d1ed7fa11c747a0523cb3faa384b /app/Models/DatabaseDAOPGSQL.php | |
| parent | 17c8c039df675b3b0f8d88d14f7316a240eabe76 (diff) | |
| parent | 29e1f048159b7a580bdf1bab184e928f11d104b4 (diff) | |
Merge pull request #1346 from FreshRSS/dev1.6.0
Merge 1.6.0-dev in master
Diffstat (limited to 'app/Models/DatabaseDAOPGSQL.php')
| -rw-r--r-- | app/Models/DatabaseDAOPGSQL.php | 43 |
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'], + ); + } +} |
