1
1
Fork 0
mirror of https://code.mensbeam.com/MensBeam/Arsse.git synced 2024-12-22 21:22:40 +00:00

Re-order SQLite3 driver initialization

Should handle error reporting better
This commit is contained in:
J. King 2017-03-13 19:13:06 -04:00
parent bb8af5a62c
commit 6413d3a489

View file

@ -22,15 +22,9 @@ class Driver extends \JKingWeb\NewsSync\Db\AbstractDriver {
if(!class_exists("SQLite3")) throw new Exception("extMissing", self::driverName()); if(!class_exists("SQLite3")) throw new Exception("extMissing", self::driverName());
$this->data = $data; $this->data = $data;
$file = $data->conf->dbSQLite3File; $file = $data->conf->dbSQLite3File;
// if the file exists (or we're initializing the database), try to open it and set initial options // if the file exists (or we're initializing the database), try to open it
try { try {
$this->db = new \SQLite3($file, ($install) ? \SQLITE3_OPEN_READWRITE | \SQLITE3_OPEN_CREATE : \SQLITE3_OPEN_READWRITE, $data->conf->dbSQLite3Key); $this->db = new \SQLite3($file, ($install) ? \SQLITE3_OPEN_READWRITE | \SQLITE3_OPEN_CREATE : \SQLITE3_OPEN_READWRITE, $data->conf->dbSQLite3Key);
$this->db->enableExceptions(true);
$this->exec("PRAGMA journal_mode = wal");
$this->exec("PRAGMA foreign_keys = yes");
// Create custom functions
$this->db->createFunction('DATEFORMAT', CustomFunctions::dateFormat, 2);
} catch(\Throwable $e) { } catch(\Throwable $e) {
// if opening the database doesn't work, check various pre-conditions to find out what the problem might be // if opening the database doesn't work, check various pre-conditions to find out what the problem might be
if(!file_exists($file)) { if(!file_exists($file)) {
@ -43,6 +37,17 @@ class Driver extends \JKingWeb\NewsSync\Db\AbstractDriver {
// otherwise the database is probably corrupt // otherwise the database is probably corrupt
throw new Exception("fileCorrupt", $mainfile); throw new Exception("fileCorrupt", $mainfile);
} }
try {
// set initial options
$this->db->enableExceptions(true);
$this->exec("PRAGMA journal_mode = wal");
$this->exec("PRAGMA foreign_keys = yes");
// Create custom functions
$this->db->createFunction('DATEFORMAT', CustomFunctions::dateFormat, 2);
} catch(\Exception $e) {
list($excClass, $excMsg, $excData) = $this->exceptionBuild();
throw new $excClass($excMsg, $excData);
}
} }
public function __destruct() { public function __destruct() {