mirror of
https://github.com/FreshRSS/FreshRSS.git
synced 2026-02-25 11:06:22 -05:00
* PDO refactor * Automatic prefix when using the syntax `_tableName` * Uniformity: MySQL is now PDO::ATTR_EMULATE_PREPARES = false just like SQLite and PostgreSQL, with consequences such as only one statement per query * Use PDO methods exec(), query(), prepare() + execute() in a more efficient way * Remove auto-update SQL code for versions older than FreshRSS 1.5 (3 years old) * The name of the default category is set in PHP instead of in the DB (simplies SQL and allows changing the name according to the FreshRSS language) * Rename `->bd` to `->pdo` (less of a frenshism, and more informative) * Fix some requests, which were not compatible with MySQL prepared statements * Whitespace * Fix syntax for PostgreSQL sequences + MySQL install * Minor formatting * Fix lastInsertId for PostgreSQL * Use PHP 5.6+ const Take advantage of https://github.com/FreshRSS/FreshRSS/pull/2527 https://www.php.net/manual/en/migration56.new-features.php * A bit of forgotten PHP 5.6 simplification for cURL * Forgotten $s * Mini fix custom user config https://github.com/FreshRSS/FreshRSS/pull/2490/files#r326290346 * More work on install.php but not finished * install.php working * More cleaning of PDO in install * Even more simplification Take advantage of PDO->exec() to run multiple statements * Disallow changing the name of the default category https://github.com/FreshRSS/FreshRSS/pull/2522#discussion_r326967724
64 lines
1.8 KiB
PHP
64 lines
1.8 KiB
PHP
<?php
|
|
|
|
/**
|
|
* This class is used to test database is well-constructed (SQLite).
|
|
*/
|
|
class FreshRSS_DatabaseDAOSQLite extends FreshRSS_DatabaseDAO {
|
|
public function tablesAreCorrect() {
|
|
$sql = 'SELECT name FROM sqlite_master WHERE type="table"';
|
|
$stm = $this->pdo->query($sql);
|
|
$res = $stm->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
$tables = array(
|
|
$this->pdo->prefix() . 'category' => false,
|
|
$this->pdo->prefix() . 'feed' => false,
|
|
$this->pdo->prefix() . 'entry' => false,
|
|
$this->pdo->prefix() . 'entrytmp' => false,
|
|
$this->pdo->prefix() . 'tag' => false,
|
|
$this->pdo->prefix() . 'entrytag' => false,
|
|
);
|
|
foreach ($res as $value) {
|
|
$tables[$value['name']] = true;
|
|
}
|
|
|
|
return count(array_keys($tables, true, true)) == count($tables);
|
|
}
|
|
|
|
public function getSchema($table) {
|
|
$sql = 'PRAGMA table_info(' . $table . ')';
|
|
$stm = $this->pdo->query($sql);
|
|
return $this->listDaoToSchema($stm->fetchAll(PDO::FETCH_ASSOC));
|
|
}
|
|
|
|
public function entryIsCorrect() {
|
|
return $this->checkTable('entry', array(
|
|
'id', 'guid', 'title', 'author', 'content', 'link', 'date', 'lastSeen', 'hash', 'is_read',
|
|
'is_favorite', 'id_feed', 'tags',
|
|
));
|
|
}
|
|
|
|
public function entrytmpIsCorrect() {
|
|
return $this->checkTable('entrytmp', array(
|
|
'id', 'guid', 'title', 'author', 'content', 'link', 'date', 'lastSeen', 'hash', 'is_read',
|
|
'is_favorite', 'id_feed', 'tags',
|
|
));
|
|
}
|
|
|
|
public function daoToSchema($dao) {
|
|
return array(
|
|
'name' => $dao['name'],
|
|
'type' => strtolower($dao['type']),
|
|
'notnull' => $dao['notnull'] === '1' ? true : false,
|
|
'default' => $dao['dflt_value'],
|
|
);
|
|
}
|
|
|
|
public function size($all = false) {
|
|
return @filesize(join_path(DATA_PATH, 'users', $this->current_user, 'db.sqlite'));
|
|
}
|
|
|
|
public function optimize() {
|
|
return $this->exec('VACUUM') !== false;
|
|
}
|
|
}
|