DatabaseDAOPGSQL.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. /**
  3. * This class is used to test database is well-constructed.
  4. */
  5. class FreshRSS_DatabaseDAOPGSQL extends FreshRSS_DatabaseDAO {
  6. public function tablesAreCorrect() {
  7. $db = FreshRSS_Context::$system_conf->db;
  8. $dbowner = $db['user'];
  9. $sql = 'SELECT * FROM pg_catalog.pg_tables where tableowner=?';
  10. $stm = $this->bd->prepare($sql);
  11. $values = array($dbowner);
  12. $stm->execute($values);
  13. $res = $stm->fetchAll(PDO::FETCH_ASSOC);
  14. $tables = array(
  15. $this->prefix . 'category' => false,
  16. $this->prefix . 'feed' => false,
  17. $this->prefix . 'entry' => false,
  18. );
  19. foreach ($res as $value) {
  20. $tables[array_pop($value)] = true;
  21. }
  22. return count(array_keys($tables, true, true)) == count($tables);
  23. }
  24. public function getSchema($table) {
  25. $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 = ?';
  26. $stm = $this->bd->prepare($sql);
  27. $stm->execute(array($this->prefix . $table));
  28. return $this->listDaoToSchema($stm->fetchAll(PDO::FETCH_ASSOC));
  29. }
  30. public function daoToSchema($dao) {
  31. return array(
  32. 'name' => $dao['field'],
  33. 'type' => strtolower($dao['type']),
  34. 'notnull' => (bool)$dao['null'],
  35. 'default' => $dao['default'],
  36. );
  37. }
  38. }