DatabaseDAOSQLite.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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->pdo->query($sql);
  9. $res = $stm->fetchAll(PDO::FETCH_ASSOC);
  10. $tables = array(
  11. $this->pdo->prefix() . 'category' => false,
  12. $this->pdo->prefix() . 'feed' => false,
  13. $this->pdo->prefix() . 'entry' => false,
  14. $this->pdo->prefix() . 'entrytmp' => false,
  15. $this->pdo->prefix() . 'tag' => false,
  16. $this->pdo->prefix() . 'entrytag' => false,
  17. );
  18. foreach ($res as $value) {
  19. $tables[$value['name']] = true;
  20. }
  21. return count(array_keys($tables, true, true)) == count($tables);
  22. }
  23. public function getSchema($table) {
  24. $sql = 'PRAGMA table_info(' . $table . ')';
  25. $stm = $this->pdo->query($sql);
  26. return $this->listDaoToSchema($stm->fetchAll(PDO::FETCH_ASSOC));
  27. }
  28. public function entryIsCorrect() {
  29. return $this->checkTable('entry', array(
  30. 'id', 'guid', 'title', 'author', 'content', 'link', 'date', 'lastSeen', 'hash', 'is_read',
  31. 'is_favorite', 'id_feed', 'tags',
  32. ));
  33. }
  34. public function entrytmpIsCorrect() {
  35. return $this->checkTable('entrytmp', array(
  36. 'id', 'guid', 'title', 'author', 'content', 'link', 'date', 'lastSeen', 'hash', 'is_read',
  37. 'is_favorite', 'id_feed', 'tags',
  38. ));
  39. }
  40. public function daoToSchema($dao) {
  41. return array(
  42. 'name' => $dao['name'],
  43. 'type' => strtolower($dao['type']),
  44. 'notnull' => $dao['notnull'] === '1' ? true : false,
  45. 'default' => $dao['dflt_value'],
  46. );
  47. }
  48. public function size($all = false) {
  49. return @filesize(join_path(DATA_PATH, 'users', $this->current_user, 'db.sqlite'));
  50. }
  51. public function optimize() {
  52. return $this->exec('VACUUM') !== false;
  53. }
  54. }