Actualizaciones varias: mejoras en cuenta, sincronización, UI
This commit is contained in:
+108
-30
@@ -1,28 +1,40 @@
|
||||
#include "accountdao.h"
|
||||
|
||||
bool AccountDao::insert(const Account& account)
|
||||
qint64 AccountDao::insert(const Account& account)
|
||||
{
|
||||
QSqlDatabase& db = DatabaseManager::instance().database();
|
||||
QSqlQuery query(db);
|
||||
query.prepare(
|
||||
"INSERT INTO Account (email, displayName, type, accessToken, refreshToken, tokenExpires) "
|
||||
"VALUES (:email, :displayName, :type, :accessToken, :refreshToken, :tokenExpires)"
|
||||
);
|
||||
"INSERT INTO Account (email, displayName, signature, type, accessToken, refreshToken, tokenExpires, "
|
||||
"incomingHost, incomingPort, incomingSsl, outgoingHost, outgoingPort, outgoingSsl, "
|
||||
"connUsername, connPassword, authMethod) "
|
||||
"VALUES (:email, :displayName, :type, :accessToken, :refreshToken, :tokenExpires, "
|
||||
":incomingHost, :incomingPort, :incomingSsl, :outgoingHost, :outgoingPort, :outgoingSsl, "
|
||||
":connUsername, :connPassword, :authMethod)");
|
||||
query.bindValue(":email", account.email());
|
||||
query.bindValue(":displayName", account.displayName());
|
||||
query.bindValue(":signature", account.signature());
|
||||
query.bindValue(":type", static_cast<int>(account.type()));
|
||||
query.bindValue(":accessToken", account.accessToken());
|
||||
query.bindValue(":refreshToken", account.refreshToken());
|
||||
query.bindValue(":tokenExpires", account.tokenExpires());
|
||||
const auto& settings = account.connectionSettings();
|
||||
query.bindValue(":incomingHost", settings.incomingHost);
|
||||
query.bindValue(":incomingPort", settings.incomingPort);
|
||||
query.bindValue(":incomingSsl", settings.incomingSsl ? 1 : 0);
|
||||
query.bindValue(":outgoingHost", settings.outgoingHost);
|
||||
query.bindValue(":outgoingPort", settings.outgoingPort);
|
||||
query.bindValue(":outgoingSsl", settings.outgoingSsl ? 1 : 0);
|
||||
query.bindValue(":connUsername", settings.username);
|
||||
query.bindValue(":connPassword", Account::encryptPassword(settings.password));
|
||||
query.bindValue(":authMethod", settings.authMethod);
|
||||
|
||||
if (!query.exec()) {
|
||||
qWarning() << "Failed to insert account:" << query.lastError().text();
|
||||
return false;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Optionally set the id on the account object if needed (pass by reference?)
|
||||
// Since account is const, we cannot modify it. Caller can retrieve lastInsertId.
|
||||
return true;
|
||||
return query.lastInsertId().toLongLong();
|
||||
}
|
||||
|
||||
bool AccountDao::update(const Account& account)
|
||||
@@ -36,16 +48,34 @@ bool AccountDao::update(const Account& account)
|
||||
"type = :type, "
|
||||
"accessToken = :accessToken, "
|
||||
"refreshToken = :refreshToken, "
|
||||
"tokenExpires = :tokenExpires "
|
||||
"WHERE id = :id"
|
||||
);
|
||||
"tokenExpires = :tokenExpires, "
|
||||
"incomingHost = :incomingHost, "
|
||||
"incomingPort = :incomingPort, "
|
||||
"incomingSsl = :incomingSsl, "
|
||||
"outgoingHost = :outgoingHost, "
|
||||
"outgoingPort = :outgoingPort, "
|
||||
"outgoingSsl = :outgoingSsl, "
|
||||
"connUsername = :connUsername, "
|
||||
"connPassword = :connPassword, "
|
||||
"authMethod = :authMethod "
|
||||
"WHERE id = :id");
|
||||
query.bindValue(":id", account.id());
|
||||
query.bindValue(":email", account.email());
|
||||
query.bindValue(":displayName", account.displayName());
|
||||
query.bindValue(":signature", account.signature());
|
||||
query.bindValue(":type", static_cast<int>(account.type()));
|
||||
query.bindValue(":accessToken", account.accessToken());
|
||||
query.bindValue(":refreshToken", account.refreshToken());
|
||||
query.bindValue(":tokenExpires", account.tokenExpires());
|
||||
const auto& settings = account.connectionSettings();
|
||||
query.bindValue(":incomingHost", settings.incomingHost);
|
||||
query.bindValue(":incomingPort", settings.incomingPort);
|
||||
query.bindValue(":incomingSsl", settings.incomingSsl ? 1 : 0);
|
||||
query.bindValue(":outgoingHost", settings.outgoingHost);
|
||||
query.bindValue(":outgoingPort", settings.outgoingPort);
|
||||
query.bindValue(":outgoingSsl", settings.outgoingSsl ? 1 : 0);
|
||||
query.bindValue(":connUsername", settings.username);
|
||||
query.bindValue(":connPassword", Account::encryptPassword(settings.password));
|
||||
query.bindValue(":authMethod", settings.authMethod);
|
||||
|
||||
if (!query.exec()) {
|
||||
qWarning() << "Failed to update account:" << query.lastError().text();
|
||||
@@ -72,7 +102,11 @@ Account* AccountDao::findById(int id)
|
||||
{
|
||||
QSqlDatabase& db = DatabaseManager::instance().database();
|
||||
QSqlQuery query(db);
|
||||
query.prepare("SELECT id, email, displayName, type, accessToken, refreshToken, tokenExpires FROM Account WHERE id = :id");
|
||||
query.prepare(
|
||||
"SELECT id, email, displayName, type, accessToken, refreshToken, tokenExpires, "
|
||||
"incomingHost, incomingPort, incomingSsl, outgoingHost, outgoingPort, outgoingSsl, "
|
||||
"connUsername, connPassword, authMethod "
|
||||
"FROM Account WHERE id = :id");
|
||||
query.bindValue(":id", id);
|
||||
|
||||
if (!query.exec()) {
|
||||
@@ -82,13 +116,25 @@ Account* AccountDao::findById(int id)
|
||||
|
||||
if (query.next()) {
|
||||
Account* account = new Account();
|
||||
account->setId(query.value("id").toLongLong());
|
||||
account->setId(query.value("id").toInt());
|
||||
account->setEmail(query.value("email").toString());
|
||||
account->setDisplayName(query.value("displayName").toString());
|
||||
account->setSignature(query.value("signature").toString());
|
||||
account->setType(static_cast<AccountType>(query.value("type").toInt()));
|
||||
account->setAccessToken(query.value("accessToken").toString());
|
||||
account->setRefreshToken(query.value("refreshToken").toString());
|
||||
account->setTokenExpires(query.value("tokenExpires").toDateTime());
|
||||
Account::ConnectionSettings settings;
|
||||
settings.incomingHost = query.value("incomingHost").toString();
|
||||
settings.incomingPort = query.value("incomingPort").toInt();
|
||||
settings.incomingSsl = query.value("incomingSsl").toBool();
|
||||
settings.outgoingHost = query.value("outgoingHost").toString();
|
||||
settings.outgoingPort = query.value("outgoingPort").toInt();
|
||||
settings.outgoingSsl = query.value("outgoingSsl").toBool();
|
||||
settings.username = query.value("connUsername").toString();
|
||||
settings.password = Account::decryptPassword(query.value("connPassword").toString());
|
||||
settings.authMethod = query.value("authMethod").toString();
|
||||
account->setConnectionSettings(settings);
|
||||
return account;
|
||||
}
|
||||
|
||||
@@ -100,20 +146,35 @@ QVector<Account> AccountDao::findAll()
|
||||
QVector<Account> accounts;
|
||||
QSqlDatabase& db = DatabaseManager::instance().database();
|
||||
QSqlQuery query(db);
|
||||
if (!query.exec("SELECT id, email, displayName, type, accessToken, refreshToken, tokenExpires FROM Account")) {
|
||||
if (!query.exec(
|
||||
"SELECT id, email, displayName, type, accessToken, refreshToken, tokenExpires, "
|
||||
"incomingHost, incomingPort, incomingSsl, outgoingHost, outgoingPort, outgoingSsl, "
|
||||
"connUsername, connPassword, authMethod "
|
||||
"FROM Account")) {
|
||||
qWarning() << "Failed to fetch all accounts:" << query.lastError().text();
|
||||
return accounts;
|
||||
}
|
||||
|
||||
while (query.next()) {
|
||||
Account acc;
|
||||
acc.setId(query.value(0).toInt());
|
||||
acc.setEmail(query.value(1).toString());
|
||||
acc.setDisplayName(query.value(2).toString());
|
||||
acc.setType(static_cast<AccountType>(query.value(3).toInt()));
|
||||
acc.setAccessToken(query.value(4).toString());
|
||||
acc.setRefreshToken(query.value(5).toString());
|
||||
acc.setTokenExpires(query.value(6).toDateTime());
|
||||
acc.setId(query.value("id").toInt());
|
||||
acc.setEmail(query.value("email").toString());
|
||||
acc.setDisplayName(query.value("displayName").toString());
|
||||
acc.setType(static_cast<AccountType>(query.value("type").toInt()));
|
||||
acc.setAccessToken(query.value("accessToken").toString());
|
||||
acc.setRefreshToken(query.value("refreshToken").toString());
|
||||
acc.setTokenExpires(query.value("tokenExpires").toDateTime());
|
||||
Account::ConnectionSettings settings;
|
||||
settings.incomingHost = query.value("incomingHost").toString();
|
||||
settings.incomingPort = query.value("incomingPort").toInt();
|
||||
settings.incomingSsl = query.value("incomingSsl").toBool();
|
||||
settings.outgoingHost = query.value("outgoingHost").toString();
|
||||
settings.outgoingPort = query.value("outgoingPort").toInt();
|
||||
settings.outgoingSsl = query.value("outgoingSsl").toBool();
|
||||
settings.username = query.value("connUsername").toString();
|
||||
settings.password = Account::decryptPassword(query.value("connPassword").toString());
|
||||
settings.authMethod = query.value("authMethod").toString();
|
||||
acc.setConnectionSettings(settings);
|
||||
accounts.append(acc);
|
||||
}
|
||||
return accounts;
|
||||
@@ -123,7 +184,11 @@ Account* AccountDao::findByEmail(const QString& email)
|
||||
{
|
||||
QSqlDatabase& db = DatabaseManager::instance().database();
|
||||
QSqlQuery query(db);
|
||||
query.prepare("SELECT id, email, displayName, type, accessToken, refreshToken, tokenExpires FROM Account WHERE email = :email");
|
||||
query.prepare(
|
||||
"SELECT id, email, displayName, type, accessToken, refreshToken, tokenExpires, "
|
||||
"incomingHost, incomingPort, incomingSsl, outgoingHost, outgoingPort, outgoingSsl, "
|
||||
"connUsername, connPassword, authMethod "
|
||||
"FROM Account WHERE email = :email");
|
||||
query.bindValue(":email", email);
|
||||
|
||||
if (!query.exec()) {
|
||||
@@ -133,14 +198,27 @@ Account* AccountDao::findByEmail(const QString& email)
|
||||
|
||||
if (query.next()) {
|
||||
Account* acc = new Account();
|
||||
acc->setId(query.value(0).toLongLong());
|
||||
acc->setEmail(query.value(1).toString());
|
||||
acc->setDisplayName(query.value(2).toString());
|
||||
acc->setType(static_cast<AccountType>(query.value(3).toInt()));
|
||||
acc->setAccessToken(query.value(4).toString());
|
||||
acc->setRefreshToken(query.value(5).toString());
|
||||
acc->setTokenExpires(query.value(6).toDateTime());
|
||||
acc->setId(query.value("id").toInt());
|
||||
acc->setEmail(query.value("email").toString());
|
||||
acc->setDisplayName(query.value("displayName").toString());
|
||||
acc->setSignature(query.value("signature").toString());
|
||||
acc->setType(static_cast<AccountType>(query.value("type").toInt()));
|
||||
acc->setAccessToken(query.value("accessToken").toString());
|
||||
acc->setRefreshToken(query.value("refreshToken").toString());
|
||||
acc->setTokenExpires(query.value("tokenExpires").toDateTime());
|
||||
Account::ConnectionSettings settings;
|
||||
settings.incomingHost = query.value("incomingHost").toString();
|
||||
settings.incomingPort = query.value("incomingPort").toInt();
|
||||
settings.incomingSsl = query.value("incomingSsl").toBool();
|
||||
settings.outgoingHost = query.value("outgoingHost").toString();
|
||||
settings.outgoingPort = query.value("outgoingPort").toInt();
|
||||
settings.outgoingSsl = query.value("outgoingSsl").toBool();
|
||||
settings.username = query.value("connUsername").toString();
|
||||
settings.password = Account::decryptPassword(query.value("connPassword").toString());
|
||||
settings.authMethod = query.value("authMethod").toString();
|
||||
acc->setConnectionSettings(settings);
|
||||
return acc;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -10,10 +10,10 @@
|
||||
class AccountDao
|
||||
{
|
||||
public:
|
||||
static bool insert(const Account& account);
|
||||
static qint64 insert(const Account& account); // returns the new row ID, or -1 on failure
|
||||
static bool update(const Account& account);
|
||||
static bool remove(int id);
|
||||
static Account* findById(int id);
|
||||
static QVector<Account> findAll();
|
||||
static Account* findByEmail(const QString& email);
|
||||
};
|
||||
};
|
||||
|
||||
@@ -129,7 +129,7 @@ QVector<Folder> FolderDao::findAll()
|
||||
fld.setTrash(query.value(7).toBool());
|
||||
fld.setUnreadCount(query.value(8).toInt());
|
||||
fld.setLastSynced(query.value(9).toDateTime());
|
||||
folders.append(fld);
|
||||
folders.push_back(fld);
|
||||
}
|
||||
return folders;
|
||||
}
|
||||
@@ -159,7 +159,21 @@ QVector<Folder> FolderDao::findByAccountId(int accountId)
|
||||
fld.setTrash(query.value(7).toBool());
|
||||
fld.setUnreadCount(query.value(8).toInt());
|
||||
fld.setLastSynced(query.value(9).toDateTime());
|
||||
folders.append(fld);
|
||||
folders.push_back(fld);
|
||||
}
|
||||
return folders;
|
||||
}
|
||||
|
||||
bool FolderDao::removeByAccountId(int accountId)
|
||||
{
|
||||
QSqlDatabase& db = DatabaseManager::instance().database();
|
||||
QSqlQuery query(db);
|
||||
query.prepare("DELETE FROM Folder WHERE accountId = :accountId");
|
||||
query.bindValue(":accountId", accountId);
|
||||
|
||||
if (!query.exec()) {
|
||||
qWarning() << "Failed to delete folders by account id:" << query.lastError().text();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -11,6 +11,7 @@ public:
|
||||
static bool insert(const Folder& folder);
|
||||
static bool update(const Folder& folder);
|
||||
static bool remove(int id);
|
||||
static bool removeByAccountId(int accountId);
|
||||
static std::optional<Folder> findById(int id);
|
||||
static QVector<Folder> findAll();
|
||||
static QVector<Folder> findByAccountId(int accountId);
|
||||
|
||||
+14
-12
@@ -8,8 +8,8 @@ bool MailItemDao::insert(const MailItem& item)
|
||||
QSqlDatabase& db = DatabaseManager::instance().database();
|
||||
QSqlQuery query(db);
|
||||
query.prepare(
|
||||
"INSERT INTO MailCopy (folderId, messageId, subject, sender, recipient, date, read, flagged, hasAttachment, size, fileId) "
|
||||
"VALUES (:folderId, :messageId, :subject, :sender, :recipient, :date, :read, :flagged, :hasAttachment, :size, :fileId)"
|
||||
"INSERT INTO MailCopy (folderId, messageId, subject, sender, recipient, date, read, flagged, hasAttachment, size, fileId, uid) "
|
||||
"VALUES (:folderId, :messageId, :subject, :sender, :recipient, :date, :read, :flagged, :hasAttachment, :size, :fileId, :uid)"
|
||||
);
|
||||
query.bindValue(":folderId", item.folderId());
|
||||
query.bindValue(":messageId", item.messageId());
|
||||
@@ -22,6 +22,7 @@ bool MailItemDao::insert(const MailItem& item)
|
||||
query.bindValue(":hasAttachment", !item.attachments().isEmpty() ? 1 : 0);
|
||||
query.bindValue(":size", item.size());
|
||||
query.bindValue(":fileId", item.fileId());
|
||||
query.bindValue(":uid", item.uid());
|
||||
|
||||
if (!query.exec()) {
|
||||
qWarning() << "Failed to insert mail item:" << query.lastError().text();
|
||||
@@ -46,7 +47,8 @@ bool MailItemDao::update(const MailItem& item)
|
||||
"flagged = :flagged, "
|
||||
"hasAttachment = :hasAttachment, "
|
||||
"size = :size, "
|
||||
"fileId = :fileId "
|
||||
"fileId = :fileId, "
|
||||
"uid = :uid "
|
||||
"WHERE id = :id"
|
||||
);
|
||||
query.bindValue(":id", item.id());
|
||||
@@ -61,6 +63,7 @@ bool MailItemDao::update(const MailItem& item)
|
||||
query.bindValue(":hasAttachment", !item.attachments().isEmpty() ? 1 : 0);
|
||||
query.bindValue(":size", item.size());
|
||||
query.bindValue(":fileId", item.fileId());
|
||||
query.bindValue(":uid", item.uid());
|
||||
|
||||
if (!query.exec()) {
|
||||
qWarning() << "Failed to update mail item:" << query.lastError().text();
|
||||
@@ -87,7 +90,7 @@ std::optional<MailItem> MailItemDao::findById(qint64 id)
|
||||
{
|
||||
QSqlDatabase& db = DatabaseManager::instance().database();
|
||||
QSqlQuery query(db);
|
||||
query.prepare("SELECT id, folderId, messageId, subject, sender, recipient, date, read, flagged, hasAttachment, size, fileId FROM MailCopy WHERE id = :id");
|
||||
query.prepare("SELECT id, folderId, messageId, subject, sender, recipient, date, read, flagged, hasAttachment, size, fileId, uid FROM MailCopy WHERE id = :id");
|
||||
query.bindValue(":id", id);
|
||||
|
||||
if (!query.exec()) {
|
||||
@@ -106,12 +109,9 @@ std::optional<MailItem> MailItemDao::findById(qint64 id)
|
||||
item.setDate(query.value(6).toDateTime());
|
||||
item.setRead(query.value(7).toBool());
|
||||
item.setFlagged(query.value(8).toBool());
|
||||
// attachments, size, fileId: we don't have them in the select? Actually we do.
|
||||
// We need to fetch attachments? Not stored in DB as separate column? We have hasAttachment flag but not list.
|
||||
// For simplicity, we leave attachments empty.
|
||||
// We'll set size and fileId.
|
||||
item.setSize(query.value(10).toLongLong());
|
||||
item.setFileId(query.value(11).toString());
|
||||
item.setUid(query.value(12).toLongLong());
|
||||
return item;
|
||||
}
|
||||
return std::nullopt;
|
||||
@@ -122,7 +122,7 @@ QVector<MailItem> MailItemDao::findAll()
|
||||
QVector<MailItem> items;
|
||||
QSqlDatabase& db = DatabaseManager::instance().database();
|
||||
QSqlQuery query(db);
|
||||
if (!query.exec("SELECT id, folderId, messageId, subject, sender, recipient, date, read, flagged, hasAttachment, size, fileId FROM MailCopy")) {
|
||||
if (!query.exec("SELECT id, folderId, messageId, subject, sender, recipient, date, read, flagged, hasAttachment, size, fileId, uid FROM MailCopy")) {
|
||||
qWarning() << "Failed to fetch all mail items:" << query.lastError().text();
|
||||
return items;
|
||||
}
|
||||
@@ -138,9 +138,9 @@ QVector<MailItem> MailItemDao::findAll()
|
||||
item.setDate(query.value(6).toDateTime());
|
||||
item.setRead(query.value(7).toBool());
|
||||
item.setFlagged(query.value(8).toBool());
|
||||
// attachments: we don't have the list, just a flag. We'll leave empty.
|
||||
item.setSize(query.value(10).toLongLong());
|
||||
item.setFileId(query.value(11).toString());
|
||||
item.setUid(query.value(12).toLongLong());
|
||||
items.append(item);
|
||||
}
|
||||
return items;
|
||||
@@ -151,7 +151,7 @@ QVector<MailItem> MailItemDao::findByFolderId(int folderId)
|
||||
QVector<MailItem> items;
|
||||
QSqlDatabase& db = DatabaseManager::instance().database();
|
||||
QSqlQuery query(db);
|
||||
query.prepare("SELECT id, folderId, messageId, subject, sender, recipient, date, read, flagged, hasAttachment, size, fileId FROM MailCopy WHERE folderId = :folderId");
|
||||
query.prepare("SELECT id, folderId, messageId, subject, sender, recipient, date, read, flagged, hasAttachment, size, fileId, uid FROM MailCopy WHERE folderId = :folderId");
|
||||
query.bindValue(":folderId", folderId);
|
||||
|
||||
if (!query.exec()) {
|
||||
@@ -172,6 +172,7 @@ QVector<MailItem> MailItemDao::findByFolderId(int folderId)
|
||||
item.setFlagged(query.value(8).toBool());
|
||||
item.setSize(query.value(10).toLongLong());
|
||||
item.setFileId(query.value(11).toString());
|
||||
item.setUid(query.value(12).toLongLong());
|
||||
items.append(item);
|
||||
}
|
||||
return items;
|
||||
@@ -182,7 +183,7 @@ QVector<MailItem> MailItemDao::findByFolderIdSinceUid(int folderId, qint64 since
|
||||
QVector<MailItem> items;
|
||||
QSqlDatabase& db = DatabaseManager::instance().database();
|
||||
QSqlQuery query(db);
|
||||
query.prepare("SELECT id, folderId, messageId, subject, sender, recipient, date, read, flagged, hasAttachment, size, fileId FROM MailCopy WHERE folderId = :folderId AND id > :sinceUid");
|
||||
query.prepare("SELECT id, folderId, messageId, subject, sender, recipient, date, read, flagged, hasAttachment, size, fileId, uid FROM MailCopy WHERE folderId = :folderId AND id > :sinceUid");
|
||||
query.bindValue(":folderId", folderId);
|
||||
query.bindValue(":sinceUid", sinceUid);
|
||||
|
||||
@@ -204,6 +205,7 @@ QVector<MailItem> MailItemDao::findByFolderIdSinceUid(int folderId, qint64 since
|
||||
item.setFlagged(query.value(8).toBool());
|
||||
item.setSize(query.value(10).toLongLong());
|
||||
item.setFileId(query.value(11).toString());
|
||||
item.setUid(query.value(12).toLongLong());
|
||||
items.append(item);
|
||||
}
|
||||
return items;
|
||||
|
||||
@@ -45,21 +45,31 @@ bool DatabaseManager::initialize(const QString& databasePath)
|
||||
return false;
|
||||
}
|
||||
|
||||
// Create tables if they don't exist
|
||||
QSqlQuery query(m_db);
|
||||
// We'll create a minimal set of tables for now; can be expanded later.
|
||||
// Based on Wino Mail schema: Account, Folder, MailCopy (mail items), etc.
|
||||
// Enable foreign keys
|
||||
query.exec("PRAGMA foreign_keys = ON;");
|
||||
|
||||
// Create tables if they don't exist
|
||||
|
||||
// Account table
|
||||
if (!query.exec(
|
||||
"CREATE TABLE IF NOT EXISTS Account ("
|
||||
"id INTEGER PRIMARY KEY AUTOINCREMENT, "
|
||||
"email TEXT NOT NULL, "
|
||||
"displayName TEXT, "
|
||||
"displayName TEXT, ""signature TEXT, "
|
||||
"type INTEGER NOT NULL, " // 0=Outlook,1=Gmail,2=IMAP
|
||||
"accessToken TEXT, "
|
||||
"refreshToken TEXT, "
|
||||
"tokenExpires DATETIME"
|
||||
"tokenExpires DATETIME, "
|
||||
"incomingHost TEXT, "
|
||||
"incomingPort INTEGER, "
|
||||
"incomingSsl INTEGER, "
|
||||
"outgoingHost TEXT, "
|
||||
"outgoingPort INTEGER, "
|
||||
"outgoingSsl INTEGER, "
|
||||
"connUsername TEXT, "
|
||||
"connPassword TEXT, "
|
||||
"authMethod TEXT"
|
||||
");")) {
|
||||
qWarning() << "Failed to create Account table:" << query.lastError().text();
|
||||
return false;
|
||||
@@ -78,7 +88,7 @@ bool DatabaseManager::initialize(const QString& databasePath)
|
||||
"isTrash BOOLEAN DEFAULT 0, "
|
||||
"unreadCount INTEGER DEFAULT 0, "
|
||||
"lastSynced DATETIME, "
|
||||
"FOREIGN KEY(accountId) REFERENCES Account(id)"
|
||||
"FOREIGN KEY(accountId) REFERENCES Account(id) ON DELETE CASCADE"
|
||||
");")) {
|
||||
qWarning() << "Failed to create Folder table:" << query.lastError().text();
|
||||
return false;
|
||||
@@ -98,8 +108,9 @@ bool DatabaseManager::initialize(const QString& databasePath)
|
||||
"flagged BOOLEAN DEFAULT 0, "
|
||||
"hasAttachment BOOLEAN DEFAULT 0, "
|
||||
"size INTEGER, "
|
||||
"uid INTEGER, "
|
||||
"fileId TEXT, " // references the .eml file in storage
|
||||
"FOREIGN KEY(folderId) REFERENCES Folder(id)"
|
||||
"FOREIGN KEY(folderId) REFERENCES Folder(id) ON DELETE CASCADE"
|
||||
");")) {
|
||||
qWarning() << "Failed to create MailCopy table:" << query.lastError().text();
|
||||
return false;
|
||||
@@ -114,7 +125,7 @@ bool DatabaseManager::initialize(const QString& databasePath)
|
||||
"mimeType TEXT, "
|
||||
"size INTEGER, "
|
||||
"contentId TEXT, "
|
||||
"FOREIGN KEY(mailCopyId) REFERENCES MailCopy(id)"
|
||||
"FOREIGN KEY(mailCopyId) REFERENCES MailCopy(id) ON DELETE CASCADE"
|
||||
");")) {
|
||||
qWarning() << "Failed to create Attachment table:" << query.lastError().text();
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user