| 1 | // For license of this file, see <project-root-folder>/LICENSE.md.cxx . . $ `<file>/src/librssguard/database/databasefactory.cpp`/ |
| 2 | |
| 3 | #include "database/databasefactory.h"cxx . . $ `<file>/src/librssguard/database/databasefactory.h`/ |
| 4 | |
| 5 | #include "3rd-party/boolinq/boolinq.h"cxx . . $ `<file>/src/librssguard/3rd-party/boolinq/boolinq.h`/ |
| 6 | #include "database/mariadbdriver.h"cxx . . $ `<file>/src/librssguard/database/mariadbdriver.h`/ |
| 7 | #include "database/sqlitedriver.h"cxx . . $ `<file>/src/librssguard/database/sqlitedriver.h`/ |
| 8 | #include "exceptions/applicationexception.h"cxx . . $ `<file>/src/librssguard/exceptions/applicationexception.h`/ |
| 9 | #include "gui/messagebox.h"cxx . . $ `<file>/src/librssguard/gui/messagebox.h`/ |
| 10 | #include "miscellaneous/application.h"cxx . . $ `<file>/src/librssguard/miscellaneous/application.h`/ |
| 11 | #include "miscellaneous/iofactory.h"cxx . . $ `<file>/src/librssguard/miscellaneous/iofactory.h`/ |
| 12 | #include "miscellaneous/settings.h"cxx . . $ `<file>/src/librssguard/miscellaneous/settings.h`/ |
| 13 | #include "miscellaneous/textfactory.h"cxx . . $ `<file>/src/librssguard/miscellaneous/textfactory.h`/ |
| 14 | |
| 15 | #include <QDir> |
| 16 | #include <QSqlDriver> |
| 17 | #include <QSqlQuery> |
| 18 | #include <QSqlResult> |
| 19 | #include <QVariant> |
| 20 | |
| 21 | DatabaseFactorycxx . . $ DatabaseFactory#::DatabaseFactorycxx . . $ DatabaseFactory#DatabaseFactory(749de1b6ae65bddd).(QObjectcxx . . $ QObject#* parent) : QObjectcxx . . $ QObject#QObject(749de1b6ae65bddd).(parent), m_dbDrivercxx . . $ DatabaseFactory#m_dbDriver.(nullptr) { |
| 22 | determineDrivercxx . . $ DatabaseFactory#determineDriver(49f6e7a06ebc5aa8).(); |
| 23 | } |
| 24 | |
| 25 | void DatabaseFactorycxx . . $ DatabaseFactory#::removeConnectioncxx . . $ DatabaseFactory#removeConnection(3520e46b33348bf6).(const QStringcxx . . $ QString#& connection_name) { |
| 26 | qDebugNNcxx . . $ `src/librssguard/definitions/definitions.h:413:9`! <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). LOGSEC_DBcxx . . $ `src/librssguard/definitions/definitions.h:180:9`! <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "Removing database connection '" <<cxx . . $ QDebug#`operator<<`(4cf17434affdd8). connection_name <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "'."; |
| 27 | QSqlDatabasecxx . . $ QSqlDatabase#::removeDatabasecxx . . $ QSqlDatabase#removeDatabase(3520e46b33348bf6).(connection_name); |
| 28 | } |
| 29 | |
| 30 | void DatabaseFactorycxx . . $ DatabaseFactory#::determineDrivercxx . . $ DatabaseFactory#determineDriver(49f6e7a06ebc5aa8).() { |
| 31 | m_allDbDriverscxx . . $ DatabaseFactory#m_allDbDrivers. =cxx . . $ QList#`operator=`(f67483249d2fd4fc). { |
| 32 | new SqliteDrivercxx . . $ SqliteDriver#(qAppcxx . . $ `src/librssguard/miscellaneous/application.h:30:9`!->settingscxx . . $ Application#settings(951936487a2d9252).()->valuecxx . . $ Settings#value(8f1f29a69568d71a).(GROUPcxx . . $ `src/librssguard/miscellaneous/settings.h:32:9`!(Database), SETTINGcxx . . $ `src/librssguard/miscellaneous/settings.h:30:9`!(Database::UseInMemory)).toBoolcxx . . $ QVariant#toBool(50ce9a9e25b4a850).(), this)}; |
| 33 | |
| 34 | if (QSqlDatabasecxx . . $ QSqlDatabase#::isDriverAvailablecxx . . $ QSqlDatabase#isDriverAvailable(e1defb592416720d).(QSLcxx . . $ `src/librssguard/definitions/definitions.h:442:9`!(APP_DB_MYSQL_DRIVERcxx . . $ `src/librssguard/definitions/definitions.h:222:9`!))) { |
| 35 | m_allDbDriverscxx . . $ DatabaseFactory#m_allDbDrivers..appendcxx . . $ QList#append(200d2dc08238a4ed).(new MariaDbDrivercxx . . $ MariaDbDriver#(this)); |
| 36 | } |
| 37 | |
| 38 | const QStringcxx . . $ QString# db_driver = qAppcxx . . $ `src/librssguard/miscellaneous/application.h:30:9`!->settingscxx . . $ Application#settings(951936487a2d9252).()->valuecxx . . $ Settings#value(8f1f29a69568d71a).(GROUPcxx . . $ `src/librssguard/miscellaneous/settings.h:32:9`!(Database), SETTINGcxx . . $ `src/librssguard/miscellaneous/settings.h:30:9`!(Database::ActiveDriver)).toStringcxx . . $ QVariant#toString(6ef7b6c27b00b43d).(); |
| 39 | |
| 40 | m_dbDrivercxx . . $ DatabaseFactory#m_dbDriver. = boolinqcxx . . $ boolinq/::fromcxx . . $ boolinq/from(1a44d082b2747720).(m_allDbDriverscxx . . $ DatabaseFactory#m_allDbDrivers.).firstOrDefaultcxx . . $ boolinq/Linq#firstOrDefault(72be2761f3eff290).([cxx . . $ std/function#function(bdc3712e480e4d04).db_drivercxx . . $ QString#QString(132dd6869045752b).](DatabaseDrivercxx . . $ DatabaseDriver#* driv) { |
| 41 | return QStringcxx . . $ QString#::comparecxx . . $ QString#compare(1f3f562f55dad5ec).(driv->qtDriverCodecxx . . $ DatabaseDriver#qtDriverCode(6ef7b6c27b00b43d).(), db_driver, Qtcxx . . $ Qt/::CaseSensitivitycxx . . $ Qt/CaseSensitivity#::CaseInsensitivecxx . . $ Qt/CaseInsensitive.) == 0; |
| 42 | }); |
| 43 | |
| 44 | if (m_dbDrivercxx . . $ DatabaseFactory#m_dbDriver. == nullptr) { |
| 45 | qFatalcxx . . $ `<external>/7280663963939302026/qlogging.h:172:9`!("DB driver for '%s' was not found.", qPrintablecxx . . $ `<external>/13954984326995544643/qstring.h:1647:11`!(db_driver)); |
| 46 | } |
| 47 | |
| 48 | // Try to setup connection and fallback to SQLite. |
| 49 | try { |
| 50 | m_dbDrivercxx . . $ DatabaseFactory#m_dbDriver.->connectioncxx . . $ DatabaseDriver#connection(32d6d64cc6e35a97).(QSLcxx . . $ `src/librssguard/definitions/definitions.h:442:9`!("DatabaseFactory")); |
| 51 | } |
| 52 | catch (const ApplicationExceptioncxx . . $ ApplicationException#& ex) { |
| 53 | qCriticalNNcxx . . $ `src/librssguard/definitions/definitions.h:421:9`! <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). LOGSEC_DBcxx . . $ `src/librssguard/definitions/definitions.h:180:9`! <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "Failed to reach connection to DB source:" <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). QUOTE_W_SPACE_DOTcxx . . $ `src/librssguard/definitions/definitions.h:430:9`!(ex.message()); |
| 54 | |
| 55 | if (m_dbDrivercxx . . $ DatabaseFactory#m_dbDriver.->driverTypecxx . . $ DatabaseDriver#driverType(2f4784d5e94eaa66).() != DatabaseDrivercxx . . $ DatabaseDriver#::DriverTypecxx . . $ DatabaseDriver#DriverType#::SQLitecxx . . $ DatabaseDriver#DriverType#SQLite.) { |
| 56 | MsgBoxcxx . . $ MsgBox#::showcxx . . $ MsgBox#show(699e792c6fa2d501).(nullptr, |
| 57 | QMessageBoxcxx . . $ QMessageBox#::Iconcxx . . $ QMessageBox#Icon#::Criticalcxx . . $ QMessageBox#Critical., |
| 58 | trcxx . . $ DatabaseFactory#tr(75d9f1c324b4579d).("Cannot connect to database"), |
| 59 | trcxx . . $ DatabaseFactory#tr(75d9f1c324b4579d).("Connection to your database was not established with error: '%1'. " |
| 60 | "Falling back to SQLite.") |
| 61 | .argcxx . . $ QString#arg(ad0bca07273edcc2).(ex.messagecxx . . $ ApplicationException#message(6ef7b6c27b00b43d).())); |
| 62 | |
| 63 | m_dbDrivercxx . . $ DatabaseFactory#m_dbDriver. = boolinqcxx . . $ boolinq/::fromcxx . . $ boolinq/from(1a44d082b2747720).(m_allDbDriverscxx . . $ DatabaseFactory#m_allDbDrivers.).firstcxx . . $ boolinq/Linq#first(b3b4635b5093b302).([cxx . . $ std/function#function(bdc3712e480e4d04).](DatabaseDrivercxx . . $ DatabaseDriver#* driv) { |
| 64 | return driv->driverTypecxx . . $ DatabaseDriver#driverType(2f4784d5e94eaa66).() == DatabaseDrivercxx . . $ DatabaseDriver#::DriverTypecxx . . $ DatabaseDriver#DriverType#::SQLitecxx . . $ DatabaseDriver#DriverType#SQLite.; |
| 65 | }); |
| 66 | } |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | DatabaseDrivercxx . . $ DatabaseDriver#* DatabaseFactorycxx . . $ DatabaseFactory#::drivercxx . . $ DatabaseFactory#driver(5299be7c9afd522d).() const { |
| 71 | return m_dbDrivercxx . . $ DatabaseFactory#m_dbDriver.; |
| 72 | } |
| 73 | |
| 74 | DatabaseDrivercxx . . $ DatabaseDriver#* DatabaseFactorycxx . . $ DatabaseFactory#::driverForTypecxx . . $ DatabaseFactory#driverForType(b7e3e82fd170d343).(DatabaseDrivercxx . . $ DatabaseDriver#::DriverTypecxx . . $ DatabaseDriver#DriverType# d) const { |
| 75 | return boolinqcxx . . $ boolinq/::fromcxx . . $ boolinq/from(1a44d082b2747720).(m_allDbDriverscxx . . $ DatabaseFactory#m_allDbDrivers.).firstOrDefaultcxx . . $ boolinq/Linq#firstOrDefault(72be2761f3eff290).([cxx . . $ std/function#function(bdc3712e480e4d04).d](DatabaseDrivercxx . . $ DatabaseDriver#* driv) { |
| 76 | return driv->driverTypecxx . . $ DatabaseDriver#driverType(2f4784d5e94eaa66).() == d; |
| 77 | }); |
| 78 | } |
| 79 | |
| 80 | QStringcxx . . $ QString# DatabaseFactorycxx . . $ DatabaseFactory#::lastExecutedQuerycxx . . $ DatabaseFactory#lastExecutedQuery(410cae5ad8128b9d).(const QSqlQuerycxx . . $ QSqlQuery#& query) { |
| 81 | QStringcxx . . $ QString# str = query.lastQuerycxx . . $ QSqlQuery#lastQuery(6ef7b6c27b00b43d).(); |
| 82 | |
| 83 | #if QT_VERSION_MAJORcxx . . $ `<external>/9758848313111604122/qconfig.h:67:9`! == 5 |
| 84 | QMapIterator<QString, QVariant> it(query.boundValues()); |
| 85 | |
| 86 | while (it.hasNext()) { |
| 87 | it.next(); |
| 88 | |
| 89 | if (it.value().type() == QVariant::Type::Char || it.value().type() == QVariant::Type::String) { |
| 90 | str.replace(it.key(), QSL("'%1'").arg(it.value().toString())); |
| 91 | } |
| 92 | else { |
| 93 | str.replace(it.key(), it.value().toString()); |
| 94 | } |
| 95 | } |
| 96 | #endif |
| 97 | |
| 98 | return strcxx . . $ QString#QString(28715ad661ad3cec).; |
| 99 | } |
| 100 | |
| 101 | QStringcxx . . $ QString# DatabaseFactorycxx . . $ DatabaseFactory#::escapeQuerycxx . . $ DatabaseFactory#escapeQuery(fd988a2ab94d906b).(const QStringcxx . . $ QString#& query) { |
| 102 | return QStringcxx . . $ QString#QString(132dd6869045752b).(query).replacecxx . . $ QString#replace(192e628656427d1c).(QSLcxx . . $ `src/librssguard/definitions/definitions.h:442:9`!("'"), QSLcxx . . $ `src/librssguard/definitions/definitions.h:442:9`!("''")); |
| 103 | |
| 104 | //.replace(QSL("\""), QSL("\\\"")); |
| 105 | } |
| 106 | |
| 107 | DatabaseDrivercxx . . $ DatabaseDriver#::DriverTypecxx . . $ DatabaseDriver#DriverType# DatabaseFactorycxx . . $ DatabaseFactory#::activeDatabaseDrivercxx . . $ DatabaseFactory#activeDatabaseDriver(2f4784d5e94eaa66).() const { |
| 108 | return m_dbDrivercxx . . $ DatabaseFactory#m_dbDriver.->driverTypecxx . . $ DatabaseDriver#driverType(2f4784d5e94eaa66).(); |
| 109 | } |