Fix DB optimize for MySQL (#2647)

`pdo->exec()` is not appropriate for MySQL `OPTIMIZE` because `OPTIMIZE`
returns some data and not only a code and then fails.
pull/2661/head
Alexandre Alapetite 5 years ago committed by GitHub
parent 6a643d180e
commit 6fb60d470a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      app/Models/DatabaseDAO.php
  2. 6
      app/Models/DatabaseDAOPGSQL.php
  3. 7
      app/Models/DatabaseDAOSQLite.php

@ -156,7 +156,12 @@ class FreshRSS_DatabaseDAO extends Minz_ModelPdo {
foreach ($tables as $table) {
$sql = 'OPTIMIZE TABLE `_' . $table . '`'; //MySQL
$ok &= ($this->pdo->exec($sql) !== false);
$stm = $this->pdo->query($sql);
if ($stm == false || $stm->fetchAll(PDO::FETCH_ASSOC) === false) {
$ok = false;
$info = $stm == null ? $this->pdo->errorInfo() : $stm->errorInfo();
Minz_Log::warning(__METHOD__ . ' error: ' . $sql . ' : ' . json_encode($info));
}
}
return $ok;
}

@ -79,7 +79,11 @@ class FreshRSS_DatabaseDAOPGSQL extends FreshRSS_DatabaseDAOSQLite {
foreach ($tables as $table) {
$sql = 'VACUUM `_' . $table . '`';
$ok &= ($this->pdo->exec($sql) !== false);
if ($this->pdo->exec($sql) === false) {
$ok = false;
$info = $this->pdo->errorInfo();
Minz_Log::warning(__METHOD__ . ' error: ' . $sql . ' : ' . json_encode($info));
}
}
return $ok;
}

@ -66,6 +66,11 @@ class FreshRSS_DatabaseDAOSQLite extends FreshRSS_DatabaseDAO {
}
public function optimize() {
return $this->pdo->exec('VACUUM') !== false;
$ok = $this->pdo->exec('VACUUM') !== false;
if (!$ok) {
$info = $this->pdo->errorInfo();
Minz_Log::warning(__METHOD__ . ' error: ' . $sql . ' : ' . json_encode($info));
}
return $ok;
}
}

Loading…
Cancel
Save