mirror of
https://github.com/abraunegg/onedrive
synced 2024-06-09 01:12:29 +02:00
Update patch for issue #77
* Update logging to use log.error & log.log where relevant * Dont pass dbVersion to createTable
This commit is contained in:
parent
deabc0d212
commit
0a848a04fa
12
src/itemdb.d
12
src/itemdb.d
|
@ -2,9 +2,9 @@ import std.datetime;
|
|||
import std.exception;
|
||||
import std.path;
|
||||
import std.string;
|
||||
import std.stdio;
|
||||
import core.stdc.stdlib;
|
||||
import sqlite;
|
||||
static import log;
|
||||
|
||||
enum ItemType {
|
||||
file,
|
||||
|
@ -48,16 +48,16 @@ final class ItemDatabase
|
|||
dbVersion = db.getVersion();
|
||||
} catch (SqliteException e) {
|
||||
// An error was generated - what was the error?
|
||||
writeln("\nAn internal database error occurred: " ~ e.msg ~ "\n");
|
||||
log.error("\nAn internal database error occurred: " ~ e.msg ~ "\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
if (dbVersion == 0) {
|
||||
createTable(dbVersion);
|
||||
createTable();
|
||||
} else if (db.getVersion() != itemDatabaseVersion) {
|
||||
writeln("The item database is incompatible, re-creating database table structures");
|
||||
log.log("The item database is incompatible, re-creating database table structures");
|
||||
db.exec("DROP TABLE item");
|
||||
createTable(dbVersion);
|
||||
createTable();
|
||||
}
|
||||
db.exec("PRAGMA foreign_keys = ON");
|
||||
db.exec("PRAGMA recursive_triggers = ON");
|
||||
|
@ -81,7 +81,7 @@ final class ItemDatabase
|
|||
deleteItemByIdStmt = db.prepare("DELETE FROM item WHERE driveId = ? AND id = ?");
|
||||
}
|
||||
|
||||
void createTable(int dbVersion)
|
||||
void createTable()
|
||||
{
|
||||
db.exec("CREATE TABLE item (
|
||||
driveId TEXT NOT NULL,
|
||||
|
|
|
@ -3,6 +3,7 @@ import std.stdio;
|
|||
import etc.c.sqlite3;
|
||||
import std.string: fromStringz, toStringz;
|
||||
import core.stdc.stdlib;
|
||||
static import log;
|
||||
|
||||
extern (C) immutable(char)* sqlite3_errstr(int); // missing from the std library
|
||||
|
||||
|
@ -51,12 +52,12 @@ struct Database
|
|||
int rc = sqlite3_open(toStringz(filename), &pDb);
|
||||
if (rc == SQLITE_CANTOPEN) {
|
||||
// Database cannot be opened
|
||||
writeln("\nThe database cannot be opened. Please check the permissions of ~/.config/onedrive/items.sqlite3\n");
|
||||
log.error("\nThe database cannot be opened. Please check the permissions of ~/.config/onedrive/items.sqlite3\n");
|
||||
close();
|
||||
exit(-1);
|
||||
}
|
||||
if (rc != SQLITE_OK) {
|
||||
writeln("\nA database access error occurred: " ~ getErrorMessage() ~ "\n");
|
||||
log.error("\nA database access error occurred: " ~ getErrorMessage() ~ "\n");
|
||||
close();
|
||||
exit(-1);
|
||||
}
|
||||
|
@ -68,7 +69,7 @@ struct Database
|
|||
// https://www.sqlite.org/c3ref/exec.html
|
||||
int rc = sqlite3_exec(pDb, toStringz(sql), null, null, null);
|
||||
if (rc != SQLITE_OK) {
|
||||
writeln("\nA database execution error occurred: "~ getErrorMessage() ~ "\n");
|
||||
log.error("\nA database execution error occurred: "~ getErrorMessage() ~ "\n");
|
||||
close();
|
||||
exit(-1);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue