DatabaseDAOSQLite.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /**
  3. * This class is used to test database is well-constructed (SQLite).
  4. */
  5. class FreshRSS_DatabaseDAOSQLite extends FreshRSS_DatabaseDAO {
  6. public function tablesAreCorrect() {
  7. $sql = 'SELECT name FROM sqlite_master WHERE type="table"';
  8. $stm = $this->bd->prepare($sql);
  9. $stm->execute();
  10. $res = $stm->fetchAll(PDO::FETCH_ASSOC);
  11. $tables = array(
  12. 'category' => false,
  13. 'feed' => false,
  14. 'entry' => false,
  15. );
  16. foreach ($res as $value) {
  17. $tables[$value['name']] = true;
  18. }
  19. return count(array_keys($tables, true, true)) == count($tables);
  20. }
  21. public function getSchema($table) {
  22. $sql = 'PRAGMA table_info(' . $table . ')';
  23. $stm = $this->bd->prepare($sql);
  24. $stm->execute();
  25. return $this->listDaoToSchema($stm->fetchAll(PDO::FETCH_ASSOC));
  26. }
  27. public function entryIsCorrect() {
  28. return $this->checkTable('entry', array(
  29. 'id', 'guid', 'title', 'author', 'content', 'link', 'date', 'is_read',
  30. 'is_favorite', 'id_feed', 'tags'
  31. ));
  32. }
  33. public function daoToSchema($dao) {
  34. return array(
  35. 'name' => $dao['name'],
  36. 'type' => strtolower($dao['type']),
  37. 'notnull' => $dao['notnull'] === '1' ? true : false,
  38. 'default' => $dao['dflt_value'],
  39. );
  40. }
  41. }