Big refactoring due to MySQL feature.
This commit is contained in:
parent
e134f1609f
commit
f0d1fbbd5a
@ -51,7 +51,7 @@ QSqlDatabase DatabaseFactory::sqliteInitializeInMemoryDatabase() {
|
|||||||
database.setDatabaseName(":memory:");
|
database.setDatabaseName(":memory:");
|
||||||
|
|
||||||
if (!database.open()) {
|
if (!database.open()) {
|
||||||
qFatal("In-memory database was NOT opened. Delivered error message: '%s'",
|
qFatal("In-memory SQLite database was NOT opened. Delivered error message: '%s'",
|
||||||
qPrintable(database.lastError().text()));
|
qPrintable(database.lastError().text()));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -70,13 +70,13 @@ QSqlDatabase DatabaseFactory::sqliteInitializeInMemoryDatabase() {
|
|||||||
query_db.exec("SELECT inf_value FROM Information WHERE inf_key = 'schema_version'");
|
query_db.exec("SELECT inf_value FROM Information WHERE inf_key = 'schema_version'");
|
||||||
|
|
||||||
if (query_db.lastError().isValid()) {
|
if (query_db.lastError().isValid()) {
|
||||||
qWarning("Error occurred. In-memory database is not initialized. Initializing now.");
|
qWarning("Error occurred. In-memory SQLite database is not initialized. Initializing now.");
|
||||||
|
|
||||||
QFile file_init(APP_MISC_PATH + QDir::separator() + APP_DB_INIT_SQLITE_MEMORY);
|
QFile file_init(APP_MISC_PATH + QDir::separator() + APP_DB_INIT_SQLITE_MEMORY);
|
||||||
|
|
||||||
if (!file_init.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
if (!file_init.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||||
// Database initialization file not opened. HUGE problem.
|
// Database initialization file not opened. HUGE problem.
|
||||||
qFatal("In-memory database initialization file '%s' from directory '%s' was not found. In-memory database is uninitialized.",
|
qFatal("In-memory SQLite database initialization file '%s' from directory '%s' was not found. In-memory database is uninitialized.",
|
||||||
APP_DB_INIT_SQLITE,
|
APP_DB_INIT_SQLITE,
|
||||||
qPrintable(APP_MISC_PATH));
|
qPrintable(APP_MISC_PATH));
|
||||||
}
|
}
|
||||||
@ -89,19 +89,19 @@ QSqlDatabase DatabaseFactory::sqliteInitializeInMemoryDatabase() {
|
|||||||
query_db.exec(statement);
|
query_db.exec(statement);
|
||||||
|
|
||||||
if (query_db.lastError().isValid()) {
|
if (query_db.lastError().isValid()) {
|
||||||
qFatal("In-memory database initialization failed. Initialization script '%s' is not correct.",
|
qFatal("In-memory SQLite database initialization failed. Initialization script '%s' is not correct.",
|
||||||
APP_DB_INIT_SQLITE);
|
APP_DB_INIT_SQLITE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
database.commit();
|
database.commit();
|
||||||
qDebug("In-memory database backend should be ready now.");
|
qDebug("In-memory SQLite database backend should be ready now.");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
query_db.next();
|
query_db.next();
|
||||||
|
|
||||||
qDebug("In-memory database connection seems to be established.");
|
qDebug("In-memory SQLite database connection seems to be established.");
|
||||||
qDebug("In-memory database has version '%s'.", qPrintable(query_db.value(0).toString()));
|
qDebug("In-memory SQLite database has version '%s'.", qPrintable(query_db.value(0).toString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Loading messages from file-based database.
|
// Loading messages from file-based database.
|
||||||
@ -142,7 +142,7 @@ QSqlDatabase DatabaseFactory::sqliteInitializeFileBasedDatabase(const QString &c
|
|||||||
if (!db_path.exists()) {
|
if (!db_path.exists()) {
|
||||||
if (!db_path.mkpath(db_path.absolutePath())) {
|
if (!db_path.mkpath(db_path.absolutePath())) {
|
||||||
// Failure when create database file path.
|
// Failure when create database file path.
|
||||||
qFatal("Directory '%s' for database file '%s' was NOT created."
|
qFatal("Directory '%s' for SQLite database file '%s' was NOT created."
|
||||||
"This is HUGE problem.",
|
"This is HUGE problem.",
|
||||||
qPrintable(db_path.absolutePath()),
|
qPrintable(db_path.absolutePath()),
|
||||||
qPrintable(db_file.symLinkTarget()));
|
qPrintable(db_file.symLinkTarget()));
|
||||||
@ -157,7 +157,7 @@ QSqlDatabase DatabaseFactory::sqliteInitializeFileBasedDatabase(const QString &c
|
|||||||
database.setDatabaseName(db_file.fileName());
|
database.setDatabaseName(db_file.fileName());
|
||||||
|
|
||||||
if (!database.open()) {
|
if (!database.open()) {
|
||||||
qFatal("File-based database was NOT opened. Delivered error message: '%s'",
|
qFatal("File-based SQLite database was NOT opened. Delivered error message: '%s'",
|
||||||
qPrintable(database.lastError().text()));
|
qPrintable(database.lastError().text()));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -173,16 +173,16 @@ QSqlDatabase DatabaseFactory::sqliteInitializeFileBasedDatabase(const QString &c
|
|||||||
query_db.exec("PRAGMA temp_store = MEMORY");
|
query_db.exec("PRAGMA temp_store = MEMORY");
|
||||||
|
|
||||||
// Sample query which checks for existence of tables.
|
// Sample query which checks for existence of tables.
|
||||||
query_db.exec("SELECT value FROM Information WHERE key = 'schema_version'");
|
query_db.exec("SELECT inf_value FROM Information WHERE inf_key = 'schema_version'");
|
||||||
|
|
||||||
if (query_db.lastError().isValid()) {
|
if (query_db.lastError().isValid()) {
|
||||||
qWarning("Error occurred. File-based database is not initialized. Initializing now.");
|
qWarning("Error occurred. File-based SQLite database is not initialized. Initializing now.");
|
||||||
|
|
||||||
QFile file_init(APP_MISC_PATH + QDir::separator() + APP_DB_INIT_SQLITE);
|
QFile file_init(APP_MISC_PATH + QDir::separator() + APP_DB_INIT_SQLITE);
|
||||||
|
|
||||||
if (!file_init.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
if (!file_init.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||||
// Database initialization file not opened. HUGE problem.
|
// Database initialization file not opened. HUGE problem.
|
||||||
qFatal("Database initialization file '%s' from directory '%s' was not found. File-based database is uninitialized.",
|
qFatal("SQLite database initialization file '%s' from directory '%s' was not found. File-based database is uninitialized.",
|
||||||
APP_DB_INIT_SQLITE,
|
APP_DB_INIT_SQLITE,
|
||||||
qPrintable(APP_MISC_PATH));
|
qPrintable(APP_MISC_PATH));
|
||||||
}
|
}
|
||||||
@ -195,21 +195,21 @@ QSqlDatabase DatabaseFactory::sqliteInitializeFileBasedDatabase(const QString &c
|
|||||||
query_db.exec(statement);
|
query_db.exec(statement);
|
||||||
|
|
||||||
if (query_db.lastError().isValid()) {
|
if (query_db.lastError().isValid()) {
|
||||||
qFatal("File-based database initialization failed. Initialization script '%s' is not correct.",
|
qFatal("File-based SQLite database initialization failed. Initialization script '%s' is not correct.",
|
||||||
APP_DB_INIT_SQLITE);
|
APP_DB_INIT_SQLITE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
database.commit();
|
database.commit();
|
||||||
qDebug("File-based database backend should be ready now.");
|
qDebug("File-based SQLite database backend should be ready now.");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
query_db.next();
|
query_db.next();
|
||||||
|
|
||||||
qDebug("File-based database connection '%s' to file '%s' seems to be established.",
|
qDebug("File-based SQLite database connection '%s' to file '%s' seems to be established.",
|
||||||
qPrintable(connection_name),
|
qPrintable(connection_name),
|
||||||
qPrintable(QDir::toNativeSeparators(database.databaseName())));
|
qPrintable(QDir::toNativeSeparators(database.databaseName())));
|
||||||
qDebug("File-based database has version '%s'.", qPrintable(query_db.value(0).toString()));
|
qDebug("File-based SQLite database has version '%s'.", qPrintable(query_db.value(0).toString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
query_db.finish();
|
query_db.finish();
|
||||||
@ -224,71 +224,14 @@ QSqlDatabase DatabaseFactory::sqliteInitializeFileBasedDatabase(const QString &c
|
|||||||
|
|
||||||
QSqlDatabase DatabaseFactory::connection(const QString &connection_name,
|
QSqlDatabase DatabaseFactory::connection(const QString &connection_name,
|
||||||
DesiredType desired_type) {
|
DesiredType desired_type) {
|
||||||
if (desired_type == DatabaseFactory::StrictlyInMemory ||
|
switch (m_activeDatabaseDriver) {
|
||||||
(desired_type == DatabaseFactory::FromSettings && m_activeDatabaseDriver == SQLITE_MEMORY)) {
|
case MYSQL:
|
||||||
// We request in-memory database (either user don't care
|
return QSqlDatabase();
|
||||||
// about the type or user overrided it in the settings).
|
|
||||||
if (!m_sqliteInMemoryDatabaseInitialized) {
|
|
||||||
// It is not initialized yet.
|
|
||||||
return sqliteInitializeInMemoryDatabase();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
QSqlDatabase database = QSqlDatabase::database();
|
|
||||||
|
|
||||||
database.setDatabaseName(":memory:");
|
case SQLITE:
|
||||||
|
case SQLITE_MEMORY:
|
||||||
if (!database.isOpen() && !database.open()) {
|
default:
|
||||||
qFatal("In-memory database was NOT opened. Delivered error message: '%s'.",
|
return sqliteConnection(connection_name, desired_type);
|
||||||
qPrintable(database.lastError().text()));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
qDebug("In-memory database connection seems to be established.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return database;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// We request file-based database.
|
|
||||||
if (!m_sqliteFileBasedDatabaseinitialized) {
|
|
||||||
// File-based database is not yet initialised.
|
|
||||||
return sqliteInitializeFileBasedDatabase(connection_name);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
QSqlDatabase database;
|
|
||||||
|
|
||||||
if (QSqlDatabase::contains(connection_name)) {
|
|
||||||
qDebug("Connection '%s' is already active.",
|
|
||||||
qPrintable(connection_name));
|
|
||||||
|
|
||||||
// This database connection was added previously, no need to
|
|
||||||
// setup its properties.
|
|
||||||
database = QSqlDatabase::database(connection_name);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// Database connection with this name does not exist
|
|
||||||
// yet, add it and set it up.
|
|
||||||
database = QSqlDatabase::addDatabase(APP_DB_DRIVER_SQLITE, connection_name);
|
|
||||||
|
|
||||||
QDir db_path(m_sqliteDatabaseFilePath);
|
|
||||||
QFile db_file(db_path.absoluteFilePath(APP_DB_FILE));
|
|
||||||
|
|
||||||
// Setup database file path.
|
|
||||||
database.setDatabaseName(db_file.fileName());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!database.isOpen() && !database.open()) {
|
|
||||||
qFatal("File-based database was NOT opened. Delivered error message: '%s'.",
|
|
||||||
qPrintable(database.lastError().text()));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
qDebug("File-based database connection '%s' to file '%s' seems to be established.",
|
|
||||||
qPrintable(connection_name),
|
|
||||||
qPrintable(QDir::toNativeSeparators(database.databaseName())));
|
|
||||||
}
|
|
||||||
|
|
||||||
return database;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -323,7 +266,7 @@ void DatabaseFactory::sqliteSaveMemoryDatabase() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DatabaseFactory::determineDriver() {
|
void DatabaseFactory::determineDriver() {
|
||||||
QString db_driver = Settings::instance()->value(APP_CFG_GEN, "database_driver", APP_DB_DRIVER_SQLITE).toString();
|
QString db_driver = Settings::instance()->value(APP_CFG_DB, "database_driver", APP_DB_DRIVER_SQLITE).toString();
|
||||||
|
|
||||||
if (db_driver == APP_DB_DRIVER_MYSQL && QSqlDatabase::isDriverAvailable(APP_DB_DRIVER_MYSQL)) {
|
if (db_driver == APP_DB_DRIVER_MYSQL && QSqlDatabase::isDriverAvailable(APP_DB_DRIVER_MYSQL)) {
|
||||||
// User wants to use MySQL and MySQL is actually available. Use it.
|
// User wants to use MySQL and MySQL is actually available. Use it.
|
||||||
@ -335,7 +278,7 @@ void DatabaseFactory::determineDriver() {
|
|||||||
else {
|
else {
|
||||||
// User wants to use SQLite, which is always available. Check if file-based
|
// User wants to use SQLite, which is always available. Check if file-based
|
||||||
// or in-memory database will be used.
|
// or in-memory database will be used.
|
||||||
if (Settings::instance()->value(APP_CFG_GEN, "use_in_memory_db", false).toBool()) {
|
if (Settings::instance()->value(APP_CFG_DB, "use_in_memory_db", false).toBool()) {
|
||||||
// Use in-memory SQLite database.
|
// Use in-memory SQLite database.
|
||||||
m_activeDatabaseDriver = SQLITE_MEMORY;
|
m_activeDatabaseDriver = SQLITE_MEMORY;
|
||||||
|
|
||||||
@ -352,6 +295,76 @@ void DatabaseFactory::determineDriver() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QSqlDatabase DatabaseFactory::sqliteConnection(const QString &connection_name,
|
||||||
|
DatabaseFactory::DesiredType desired_type) {
|
||||||
|
if (desired_type == DatabaseFactory::StrictlyInMemory ||
|
||||||
|
(desired_type == DatabaseFactory::FromSettings && m_activeDatabaseDriver == SQLITE_MEMORY)) {
|
||||||
|
// We request in-memory database (either user explicitly
|
||||||
|
// needs in-memory database or it was enabled in the settings).
|
||||||
|
if (!m_sqliteInMemoryDatabaseInitialized) {
|
||||||
|
// It is not initialized yet.
|
||||||
|
return sqliteInitializeInMemoryDatabase();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
QSqlDatabase database = QSqlDatabase::database();
|
||||||
|
|
||||||
|
database.setDatabaseName(":memory:");
|
||||||
|
|
||||||
|
if (!database.isOpen() && !database.open()) {
|
||||||
|
qFatal("In-memory SQLite database was NOT opened. Delivered error message: '%s'.",
|
||||||
|
qPrintable(database.lastError().text()));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
qDebug("In-memory SQLite database connection seems to be established.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return database;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// We request file-based database.
|
||||||
|
if (!m_sqliteFileBasedDatabaseinitialized) {
|
||||||
|
// File-based database is not yet initialised.
|
||||||
|
return sqliteInitializeFileBasedDatabase(connection_name);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
QSqlDatabase database;
|
||||||
|
|
||||||
|
if (QSqlDatabase::contains(connection_name)) {
|
||||||
|
qDebug("SQLite connection '%s' is already active.",
|
||||||
|
qPrintable(connection_name));
|
||||||
|
|
||||||
|
// This database connection was added previously, no need to
|
||||||
|
// setup its properties.
|
||||||
|
database = QSqlDatabase::database(connection_name);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Database connection with this name does not exist
|
||||||
|
// yet, add it and set it up.
|
||||||
|
database = QSqlDatabase::addDatabase(APP_DB_DRIVER_SQLITE, connection_name);
|
||||||
|
|
||||||
|
QDir db_path(m_sqliteDatabaseFilePath);
|
||||||
|
QFile db_file(db_path.absoluteFilePath(APP_DB_FILE));
|
||||||
|
|
||||||
|
// Setup database file path.
|
||||||
|
database.setDatabaseName(db_file.fileName());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!database.isOpen() && !database.open()) {
|
||||||
|
qFatal("File-based SQLite database was NOT opened. Delivered error message: '%s'.",
|
||||||
|
qPrintable(database.lastError().text()));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
qDebug("File-based SQLite database connection '%s' to file '%s' seems to be established.",
|
||||||
|
qPrintable(connection_name),
|
||||||
|
qPrintable(QDir::toNativeSeparators(database.databaseName())));
|
||||||
|
}
|
||||||
|
|
||||||
|
return database;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void DatabaseFactory::saveDatabase() {
|
void DatabaseFactory::saveDatabase() {
|
||||||
switch (m_activeDatabaseDriver) {
|
switch (m_activeDatabaseDriver) {
|
||||||
case SQLITE_MEMORY:
|
case SQLITE_MEMORY:
|
||||||
|
@ -83,6 +83,9 @@ class DatabaseFactory : public QObject {
|
|||||||
// SQLITE stuff.
|
// SQLITE stuff.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
QSqlDatabase sqliteConnection(const QString &connection_name,
|
||||||
|
DesiredType desired_type);
|
||||||
|
|
||||||
// Performs saving of items from in-memory database
|
// Performs saving of items from in-memory database
|
||||||
// to file-based database.
|
// to file-based database.
|
||||||
void sqliteSaveMemoryDatabase();
|
void sqliteSaveMemoryDatabase();
|
||||||
|
@ -40,7 +40,7 @@
|
|||||||
#define INTERNAL_URL_NEWSPAPER "@APP_LOW_NAME@:newspaper"
|
#define INTERNAL_URL_NEWSPAPER "@APP_LOW_NAME@:newspaper"
|
||||||
#define DEFAULT_AUTO_UPDATE_INTERVAL 15
|
#define DEFAULT_AUTO_UPDATE_INTERVAL 15
|
||||||
#define AUTO_UPDATE_INTERVAL 60000
|
#define AUTO_UPDATE_INTERVAL 60000
|
||||||
#define STARTUP_UPDATE_DELAY 500
|
#define STARTUP_UPDATE_DELAY 1500
|
||||||
|
|
||||||
#define APP_DB_DRIVER_SQLITE "QSQLITE"
|
#define APP_DB_DRIVER_SQLITE "QSQLITE"
|
||||||
#define APP_DB_DRIVER_MYSQL "QMYSQL"
|
#define APP_DB_DRIVER_MYSQL "QMYSQL"
|
||||||
@ -56,6 +56,7 @@
|
|||||||
#define APP_CFG_GUI "gui"
|
#define APP_CFG_GUI "gui"
|
||||||
#define APP_CFG_GEN "main"
|
#define APP_CFG_GEN "main"
|
||||||
#define APP_CFG_PROXY "proxy"
|
#define APP_CFG_PROXY "proxy"
|
||||||
|
#define APP_CFG_DB "database"
|
||||||
#define APP_CFG_CUTS "keyboard"
|
#define APP_CFG_CUTS "keyboard"
|
||||||
#define APP_CFG_BROWSER "browser"
|
#define APP_CFG_BROWSER "browser"
|
||||||
#define APP_CFG_MESSAGES "messages"
|
#define APP_CFG_MESSAGES "messages"
|
||||||
|
@ -439,7 +439,7 @@ QList<Message> FeedsModel::messagesForFeeds(const QList<FeedsModelFeed*> &feeds)
|
|||||||
query_read_msg.setForwardOnly(true);
|
query_read_msg.setForwardOnly(true);
|
||||||
query_read_msg.prepare("SELECT title, url, author, date_created, contents "
|
query_read_msg.prepare("SELECT title, url, author, date_created, contents "
|
||||||
"FROM Messages "
|
"FROM Messages "
|
||||||
"WHERE deleted = 0 AND feed = :feed;");
|
"WHERE is_deleted = 0 AND feed = :feed;");
|
||||||
|
|
||||||
foreach (FeedsModelFeed *feed, feeds) {
|
foreach (FeedsModelFeed *feed, feeds) {
|
||||||
query_read_msg.bindValue(":feed", feed->id());
|
query_read_msg.bindValue(":feed", feed->id());
|
||||||
@ -695,8 +695,8 @@ bool FeedsModel::markFeedsRead(const QList<FeedsModelFeed*> &feeds,
|
|||||||
QSqlQuery query_read_msg(db_handle);
|
QSqlQuery query_read_msg(db_handle);
|
||||||
query_read_msg.setForwardOnly(true);
|
query_read_msg.setForwardOnly(true);
|
||||||
|
|
||||||
if (!query_read_msg.prepare(QString("UPDATE Messages SET read = :read "
|
if (!query_read_msg.prepare(QString("UPDATE Messages SET is_read = :read "
|
||||||
"WHERE feed IN (%1) AND deleted = 0;").arg(textualFeedIds(feeds).join(", ")))) {
|
"WHERE feed IN (%1) AND is_deleted = 0;").arg(textualFeedIds(feeds).join(", ")))) {
|
||||||
qWarning("Query preparation failed for feeds read change.");
|
qWarning("Query preparation failed for feeds read change.");
|
||||||
|
|
||||||
db_handle.rollback();
|
db_handle.rollback();
|
||||||
@ -734,8 +734,8 @@ bool FeedsModel::markFeedsDeleted(const QList<FeedsModelFeed*> &feeds,
|
|||||||
query_delete_msg.setForwardOnly(true);
|
query_delete_msg.setForwardOnly(true);
|
||||||
|
|
||||||
if (read_only) {
|
if (read_only) {
|
||||||
if (!query_delete_msg.prepare(QString("UPDATE Messages SET deleted = :deleted "
|
if (!query_delete_msg.prepare(QString("UPDATE Messages SET is_deleted = :deleted "
|
||||||
"WHERE feed IN (%1) AND deleted = 0 AND read = 1;").arg(textualFeedIds(feeds).join(", ")))) {
|
"WHERE feed IN (%1) AND is_deleted = 0 AND is_read = 1;").arg(textualFeedIds(feeds).join(", ")))) {
|
||||||
qWarning("Query preparation failed for feeds clearing.");
|
qWarning("Query preparation failed for feeds clearing.");
|
||||||
|
|
||||||
db_handle.rollback();
|
db_handle.rollback();
|
||||||
@ -743,8 +743,8 @@ bool FeedsModel::markFeedsDeleted(const QList<FeedsModelFeed*> &feeds,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (!query_delete_msg.prepare(QString("UPDATE Messages SET deleted = :deleted "
|
if (!query_delete_msg.prepare(QString("UPDATE Messages SET is_deleted = :deleted "
|
||||||
"WHERE feed IN (%1) AND deleted = 0;").arg(textualFeedIds(feeds).join(", ")))) {
|
"WHERE feed IN (%1) AND is_deleted = 0;").arg(textualFeedIds(feeds).join(", ")))) {
|
||||||
qWarning("Query preparation failed for feeds clearing.");
|
qWarning("Query preparation failed for feeds clearing.");
|
||||||
|
|
||||||
db_handle.rollback();
|
db_handle.rollback();
|
||||||
|
@ -53,16 +53,16 @@ void FeedsModelFeed::updateCounts(bool including_total_count) {
|
|||||||
query_all.setForwardOnly(true);
|
query_all.setForwardOnly(true);
|
||||||
|
|
||||||
if (including_total_count) {
|
if (including_total_count) {
|
||||||
if (query_all.exec(QString("SELECT count() FROM messages "
|
if (query_all.exec(QString("SELECT count() FROM Messages "
|
||||||
"WHERE feed = %1 AND deleted = 0;").arg(id())) &&
|
"WHERE feed = %1 AND is_deleted = 0;").arg(id())) &&
|
||||||
query_all.next()) {
|
query_all.next()) {
|
||||||
m_totalCount = query_all.value(0).toInt();
|
m_totalCount = query_all.value(0).toInt();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtain count of unread messages.
|
// Obtain count of unread messages.
|
||||||
if (query_all.exec(QString("SELECT count() FROM messages "
|
if (query_all.exec(QString("SELECT count() FROM Messages "
|
||||||
"WHERE feed = %1 AND deleted = 0 AND read = 0;").arg(id())) &&
|
"WHERE feed = %1 AND is_deleted = 0 AND is_read = 0;").arg(id())) &&
|
||||||
query_all.next()) {
|
query_all.next()) {
|
||||||
m_unreadCount = query_all.value(0).toInt();
|
m_unreadCount = query_all.value(0).toInt();
|
||||||
}
|
}
|
||||||
|
@ -244,7 +244,7 @@ void FeedsModelStandardFeed::updateMessages(const QList<Message> &messages) {
|
|||||||
query_update.prepare("UPDATE Messages "
|
query_update.prepare("UPDATE Messages "
|
||||||
"SET title = :title, url = :url, author = :author, "
|
"SET title = :title, url = :url, author = :author, "
|
||||||
"date_created = :date_created, contents = :contents, "
|
"date_created = :date_created, contents = :contents, "
|
||||||
"read = 0, important = 0, deleted = 0 "
|
"is_read = 0, is_important = 0, is_deleted = 0 "
|
||||||
"WHERE id = :id");
|
"WHERE id = :id");
|
||||||
|
|
||||||
if (!database.transaction()) {
|
if (!database.transaction()) {
|
||||||
|
@ -58,7 +58,7 @@ void MessagesModel::loadMessages(const QList<int> feed_ids) {
|
|||||||
|
|
||||||
QString assembled_ids = textualFeeds().join(", ");
|
QString assembled_ids = textualFeeds().join(", ");
|
||||||
|
|
||||||
setFilter(QString("feed IN (%1) AND deleted = 0").arg(assembled_ids));
|
setFilter(QString("feed IN (%1) AND is_deleted = 0").arg(assembled_ids));
|
||||||
select();
|
select();
|
||||||
fetchAll();
|
fetchAll();
|
||||||
|
|
||||||
@ -201,7 +201,7 @@ bool MessagesModel::setMessageRead(int row_index, int read) {
|
|||||||
QSqlQuery query_read_msg(db_handle);
|
QSqlQuery query_read_msg(db_handle);
|
||||||
query_read_msg.setForwardOnly(true);
|
query_read_msg.setForwardOnly(true);
|
||||||
|
|
||||||
if (!query_read_msg.prepare("UPDATE messages SET read = :read "
|
if (!query_read_msg.prepare("UPDATE messages SET is_read = :read "
|
||||||
"WHERE id = :id")) {
|
"WHERE id = :id")) {
|
||||||
qWarning("Query preparation failed for message read change.");
|
qWarning("Query preparation failed for message read change.");
|
||||||
|
|
||||||
@ -257,7 +257,7 @@ bool MessagesModel::switchMessageImportance(int row_index) {
|
|||||||
QSqlQuery query_importance_msg(db_handle);
|
QSqlQuery query_importance_msg(db_handle);
|
||||||
query_importance_msg.setForwardOnly(true);
|
query_importance_msg.setForwardOnly(true);
|
||||||
|
|
||||||
if (!query_importance_msg.prepare("UPDATE messages SET important = :important "
|
if (!query_importance_msg.prepare("UPDATE messages SET is_important = :important "
|
||||||
"WHERE id = :id")) {
|
"WHERE id = :id")) {
|
||||||
qWarning("Query preparation failed for message importance switch.");
|
qWarning("Query preparation failed for message importance switch.");
|
||||||
|
|
||||||
@ -296,7 +296,7 @@ bool MessagesModel::switchBatchMessageImportance(const QModelIndexList &messages
|
|||||||
QSqlQuery query_importance_msg(db_handle);
|
QSqlQuery query_importance_msg(db_handle);
|
||||||
query_importance_msg.setForwardOnly(true);
|
query_importance_msg.setForwardOnly(true);
|
||||||
|
|
||||||
if (!query_importance_msg.prepare("UPDATE messages SET important = :important "
|
if (!query_importance_msg.prepare("UPDATE messages SET is_important = :important "
|
||||||
"WHERE id = :id")) {
|
"WHERE id = :id")) {
|
||||||
qWarning("Query preparation failed for message importance switch.");
|
qWarning("Query preparation failed for message importance switch.");
|
||||||
|
|
||||||
@ -338,7 +338,7 @@ bool MessagesModel::setBatchMessagesDeleted(const QModelIndexList &messages, int
|
|||||||
QSqlQuery query_delete_msg(db_handle);
|
QSqlQuery query_delete_msg(db_handle);
|
||||||
query_delete_msg.setForwardOnly(true);
|
query_delete_msg.setForwardOnly(true);
|
||||||
|
|
||||||
if (!query_delete_msg.prepare("UPDATE messages SET deleted = :deleted "
|
if (!query_delete_msg.prepare("UPDATE messages SET is_deleted = :deleted "
|
||||||
"WHERE id = :id")) {
|
"WHERE id = :id")) {
|
||||||
qWarning("Query preparation failed for message deletion.");
|
qWarning("Query preparation failed for message deletion.");
|
||||||
|
|
||||||
@ -379,7 +379,7 @@ bool MessagesModel::setBatchMessagesRead(const QModelIndexList &messages, int re
|
|||||||
QSqlQuery query_read_msg(db_handle);
|
QSqlQuery query_read_msg(db_handle);
|
||||||
query_read_msg.setForwardOnly(true);
|
query_read_msg.setForwardOnly(true);
|
||||||
|
|
||||||
if (!query_read_msg.prepare("UPDATE messages SET read = :read "
|
if (!query_read_msg.prepare("UPDATE messages SET is_read = :read "
|
||||||
"WHERE id = :id")) {
|
"WHERE id = :id")) {
|
||||||
qWarning("Query preparation failed for message read change.");
|
qWarning("Query preparation failed for message read change.");
|
||||||
|
|
||||||
|
@ -442,7 +442,7 @@ void FormSettings::loadGeneral() {
|
|||||||
m_ui->m_cmbDatabaseDriver->addItem("SQLite", APP_DB_DRIVER_SQLITE);
|
m_ui->m_cmbDatabaseDriver->addItem("SQLite", APP_DB_DRIVER_SQLITE);
|
||||||
|
|
||||||
// Load in-memory database status.
|
// Load in-memory database status.
|
||||||
m_ui->m_cmbSqliteUseInMemoryDatabase->setChecked(Settings::instance()->value(APP_CFG_GEN, "use_in_memory_db", false).toBool());
|
m_ui->m_checkSqliteUseInMemoryDatabase->setChecked(Settings::instance()->value(APP_CFG_DB, "use_in_memory_db", false).toBool());
|
||||||
|
|
||||||
if (QSqlDatabase::isDriverAvailable(APP_DB_DRIVER_MYSQL)) {
|
if (QSqlDatabase::isDriverAvailable(APP_DB_DRIVER_MYSQL)) {
|
||||||
// Load MySQL.
|
// Load MySQL.
|
||||||
@ -452,7 +452,7 @@ void FormSettings::loadGeneral() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: nacist podle nastaveni
|
// TODO: nacist podle nastaveni
|
||||||
m_ui->m_cmbDatabaseDriver->setCurrentIndex(m_ui->m_cmbDatabaseDriver->findData(Settings::instance()->value(APP_CFG_GEN,
|
m_ui->m_cmbDatabaseDriver->setCurrentIndex(m_ui->m_cmbDatabaseDriver->findData(Settings::instance()->value(APP_CFG_DB,
|
||||||
"database_driver",
|
"database_driver",
|
||||||
APP_DB_DRIVER_SQLITE).toString()));
|
APP_DB_DRIVER_SQLITE).toString()));
|
||||||
}
|
}
|
||||||
@ -468,26 +468,26 @@ void FormSettings::saveGeneral() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Setup in-memory database status.
|
// Setup in-memory database status.
|
||||||
bool original_inmemory = Settings::instance()->value(APP_CFG_GEN, "use_in_memory_db", false).toBool();
|
bool original_inmemory = Settings::instance()->value(APP_CFG_DB, "use_in_memory_db", false).toBool();
|
||||||
bool new_inmemory = m_ui->m_cmbSqliteUseInMemoryDatabase->isChecked();
|
bool new_inmemory = m_ui->m_checkSqliteUseInMemoryDatabase->isChecked();
|
||||||
|
|
||||||
if (original_inmemory != new_inmemory) {
|
if (original_inmemory != new_inmemory) {
|
||||||
m_changedDataTexts.append(tr("in-memory database switched"));
|
m_changedDataTexts.append(tr("in-memory database switched"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save data storage settings.
|
// Save data storage settings.
|
||||||
QString original_db_driver = Settings::instance()->value(APP_CFG_GEN, "database_driver", APP_DB_DRIVER_SQLITE).toString();
|
QString original_db_driver = Settings::instance()->value(APP_CFG_DB, "database_driver", APP_DB_DRIVER_SQLITE).toString();
|
||||||
QString selected_db_driver = m_ui->m_cmbDatabaseDriver->itemData(m_ui->m_cmbDatabaseDriver->currentIndex()).toString();
|
QString selected_db_driver = m_ui->m_cmbDatabaseDriver->itemData(m_ui->m_cmbDatabaseDriver->currentIndex()).toString();
|
||||||
|
|
||||||
// Save SQLite.
|
// Save SQLite.
|
||||||
Settings::instance()->setValue(APP_CFG_GEN, "use_in_memory_db", new_inmemory);
|
Settings::instance()->setValue(APP_CFG_DB, "use_in_memory_db", new_inmemory);
|
||||||
|
|
||||||
if (QSqlDatabase::isDriverAvailable(APP_DB_DRIVER_MYSQL)) {
|
if (QSqlDatabase::isDriverAvailable(APP_DB_DRIVER_MYSQL)) {
|
||||||
// Save MySQL.
|
// Save MySQL.
|
||||||
// TODO: ulozit username, password atp.
|
// TODO: ulozit username, password atp.
|
||||||
}
|
}
|
||||||
|
|
||||||
Settings::instance()->setValue(APP_CFG_GEN, "database_driver", selected_db_driver);
|
Settings::instance()->setValue(APP_CFG_DB, "database_driver", selected_db_driver);
|
||||||
|
|
||||||
if (original_db_driver != selected_db_driver) {
|
if (original_db_driver != selected_db_driver) {
|
||||||
m_changedDataTexts.append(tr("data storage backend changed"));
|
m_changedDataTexts.append(tr("data storage backend changed"));
|
||||||
|
@ -48,6 +48,11 @@
|
|||||||
<string>General</string>
|
<string>General</string>
|
||||||
</property>
|
</property>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>Data storage</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Keyboard shortcuts</string>
|
<string>Keyboard shortcuts</string>
|
||||||
@ -78,10 +83,10 @@
|
|||||||
<item row="0" column="1">
|
<item row="0" column="1">
|
||||||
<widget class="QStackedWidget" name="m_stackedSettings">
|
<widget class="QStackedWidget" name="m_stackedSettings">
|
||||||
<property name="currentIndex">
|
<property name="currentIndex">
|
||||||
<number>0</number>
|
<number>1</number>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QWidget" name="m_pageGeneral">
|
<widget class="QWidget" name="m_pageGeneral">
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
<layout class="QFormLayout" name="formLayout_5">
|
||||||
<property name="leftMargin">
|
<property name="leftMargin">
|
||||||
<number>0</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
@ -94,28 +99,42 @@
|
|||||||
<property name="bottomMargin">
|
<property name="bottomMargin">
|
||||||
<number>0</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
<item>
|
<item row="0" column="0">
|
||||||
<widget class="QCheckBox" name="m_checkAutostart">
|
<widget class="QCheckBox" name="m_checkAutostart">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Launch RSS Guard on operating system startup</string>
|
<string>Launch RSS Guard on operating system startup</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
</layout>
|
||||||
<widget class="QGroupBox" name="m_gbDataStorage">
|
</widget>
|
||||||
<property name="sizePolicy">
|
<widget class="QWidget" name="m_pageDataStorage">
|
||||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
|
||||||
<horstretch>0</horstretch>
|
|
||||||
<verstretch>0</verstretch>
|
|
||||||
</sizepolicy>
|
|
||||||
</property>
|
|
||||||
<property name="title">
|
|
||||||
<string>Data storage</string>
|
|
||||||
</property>
|
|
||||||
<layout class="QFormLayout" name="formLayout_14">
|
<layout class="QFormLayout" name="formLayout_14">
|
||||||
<property name="fieldGrowthPolicy">
|
<property name="leftMargin">
|
||||||
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="topMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="rightMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="bottomMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<item row="0" column="0" colspan="2">
|
||||||
|
<widget class="QLabel" name="m_lblDataStorageWarning">
|
||||||
|
<property name="text">
|
||||||
|
<string>WARNING: Note that switching to another data storage type will NOT preserve your data from currently active data storage.</string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignCenter</set>
|
||||||
|
</property>
|
||||||
|
<property name="wordWrap">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item row="1" column="0">
|
<item row="1" column="0">
|
||||||
<widget class="QLabel" name="m_lblDatabaseDriver">
|
<widget class="QLabel" name="m_lblDatabaseDriver">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -126,7 +145,7 @@
|
|||||||
<item row="1" column="1">
|
<item row="1" column="1">
|
||||||
<widget class="QComboBox" name="m_cmbDatabaseDriver"/>
|
<widget class="QComboBox" name="m_cmbDatabaseDriver"/>
|
||||||
</item>
|
</item>
|
||||||
<item row="3" column="0" colspan="2">
|
<item row="2" column="0" colspan="2">
|
||||||
<widget class="QStackedWidget" name="m_stackedDatabaseDriver">
|
<widget class="QStackedWidget" name="m_stackedDatabaseDriver">
|
||||||
<property name="currentIndex">
|
<property name="currentIndex">
|
||||||
<number>0</number>
|
<number>0</number>
|
||||||
@ -136,8 +155,20 @@
|
|||||||
<property name="fieldGrowthPolicy">
|
<property name="fieldGrowthPolicy">
|
||||||
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
|
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="leftMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="topMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="rightMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="bottomMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
<item row="0" column="0" colspan="2">
|
<item row="0" column="0" colspan="2">
|
||||||
<widget class="QCheckBox" name="m_cmbSqliteUseInMemoryDatabase">
|
<widget class="QCheckBox" name="m_checkSqliteUseInMemoryDatabase">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Use in-memory database as the working database</string>
|
<string>Use in-memory database as the working database</string>
|
||||||
</property>
|
</property>
|
||||||
@ -173,6 +204,18 @@ Authors of this application are NOT responsible for lost data.</string>
|
|||||||
</widget>
|
</widget>
|
||||||
<widget class="QWidget" name="m_pageMysql">
|
<widget class="QWidget" name="m_pageMysql">
|
||||||
<layout class="QFormLayout" name="formLayout_16">
|
<layout class="QFormLayout" name="formLayout_16">
|
||||||
|
<property name="leftMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="topMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="rightMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="bottomMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
<item row="0" column="0">
|
<item row="0" column="0">
|
||||||
<widget class="QLabel" name="label_2">
|
<widget class="QLabel" name="label_2">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -228,22 +271,6 @@ Authors of this application are NOT responsible for lost data.</string>
|
|||||||
</widget>
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="0" colspan="2">
|
|
||||||
<widget class="QLabel" name="m_lblDataStorageWarning">
|
|
||||||
<property name="text">
|
|
||||||
<string>WARNING: Note that switching to another data storage type will NOT preserve your data from currently active data storage.</string>
|
|
||||||
</property>
|
|
||||||
<property name="alignment">
|
|
||||||
<set>Qt::AlignCenter</set>
|
|
||||||
</property>
|
|
||||||
<property name="wordWrap">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QWidget" name="m_pageShortcuts">
|
<widget class="QWidget" name="m_pageShortcuts">
|
||||||
@ -351,8 +378,8 @@ Authors of this application are NOT responsible for lost data.</string>
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>558</width>
|
<width>167</width>
|
||||||
<height>337</height>
|
<height>219</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QFormLayout" name="formLayout">
|
<layout class="QFormLayout" name="formLayout">
|
||||||
@ -1126,11 +1153,11 @@ Authors of this application are NOT responsible for lost data.</string>
|
|||||||
<hints>
|
<hints>
|
||||||
<hint type="sourcelabel">
|
<hint type="sourcelabel">
|
||||||
<x>558</x>
|
<x>558</x>
|
||||||
<y>96</y>
|
<y>50</y>
|
||||||
</hint>
|
</hint>
|
||||||
<hint type="destinationlabel">
|
<hint type="destinationlabel">
|
||||||
<x>516</x>
|
<x>516</x>
|
||||||
<y>215</y>
|
<y>154</y>
|
||||||
</hint>
|
</hint>
|
||||||
</hints>
|
</hints>
|
||||||
</connection>
|
</connection>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user