Commit 37ca710e authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Use directly new dbaccess class

parent 9d956118
Pipeline #200025 passed with stage
in 1 minute
......@@ -49,7 +49,7 @@ set(KDEPIM_LIB_SOVERSION "5")
set(AKONADI_CONTACT_VERSION "5.20.40")
set(CALENDARSUPPORT_LIB_VERSION "5.20.40")
set(AKONADI_VERSION "5.20.40")
set(AKONADI_VERSION "5.20.43")
set(AKONADI_SEARCH_VERSION "5.20.40")
set(QT_REQUIRED_VERSION "5.15.2")
......
......@@ -21,7 +21,6 @@ set(libakonadiconsole_SRCS
collectioninternalspage.cpp
collectionaclpage.cpp
connectionpage.cpp
dbaccess.cpp
dbbrowser.cpp
dbconsole.cpp
debugfiltermodel.cpp
......@@ -74,7 +73,6 @@ set(libakonadiconsole_SRCS
jobtrackerfilterproxymodel.h
loggingmodel.h
agentwidget.h
dbaccess.h
debugmodel.h
instanceselector.h
${libakonadiconsole_tracker_SRCS}
......
......@@ -11,8 +11,8 @@
#include "collectionattributespage.h"
#include "collectioninternalspage.h"
#include "config-akonadiconsole.h"
#include "dbaccess.h"
#include "tagpropertiesdialog.h"
#include <Akonadi/DbAccess>
#include <Akonadi/AttributeFactory>
#include <Akonadi/ChangeRecorder>
......
/*
SPDX-FileCopyrightText: 2009 Volker Krause <vkrause@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "dbaccess.h"
#include <Akonadi/ServerManager>
#include <QSettings>
#include <QSqlDatabase>
#include <QSqlError>
#include <QSqlQuery>
#include <KMessageBox>
using namespace Akonadi;
class DbAccessPrivate
{
public:
DbAccessPrivate()
{
init();
}
void init()
{
const QString serverConfigFile = ServerManager::serverConfigFilePath(ServerManager::ReadWrite);
QSettings settings(serverConfigFile, QSettings::IniFormat);
const QString driver = settings.value(QStringLiteral("General/Driver"), QStringLiteral("QMYSQL")).toString();
database = QSqlDatabase::addDatabase(driver);
settings.beginGroup(driver);
database.setHostName(settings.value(QStringLiteral("Host"), QString()).toString());
database.setDatabaseName(settings.value(QStringLiteral("Name"), QStringLiteral("akonadi")).toString());
database.setUserName(settings.value(QStringLiteral("User"), QString()).toString());
database.setPassword(settings.value(QStringLiteral("Password"), QString()).toString());
database.setConnectOptions(settings.value(QStringLiteral("Options"), QString()).toString());
if (!database.open()) {
KMessageBox::error(nullptr, QStringLiteral("Failed to connect to database: %1").arg(database.lastError().text()));
}
}
QSqlDatabase database;
};
Q_GLOBAL_STATIC(DbAccessPrivate, sInstance)
QSqlDatabase DbAccess::database()
{
// hack to detect database gone away error
QSqlQuery query(sInstance->database);
// prepare or exec of "SELECT 1" will only fail when we are not connected to database
if (!query.prepare(QStringLiteral("SELECT 1")) || !query.exec()) {
sInstance->database.close();
QSqlDatabase::removeDatabase(sInstance->database.connectionName());
sInstance->init();
}
return sInstance->database;
}
/*
SPDX-FileCopyrightText: 2009 Volker Krause <vkrause@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#pragma once
class QSqlDatabase;
namespace DbAccess
{
QSqlDatabase database();
}
......@@ -5,7 +5,7 @@
*/
#include "dbbrowser.h"
#include "dbaccess.h"
#include <Akonadi/DbAccess>
#include <QSqlTableModel>
......
......@@ -5,7 +5,7 @@
*/
#include "dbconsole.h"
#include "dbaccess.h"
#include <Akonadi/DbAccess>
#include <QAction>
......
......@@ -6,7 +6,7 @@
*/
#include "tagpropertiesdialog.h"
#include "dbaccess.h"
#include <Akonadi/DbAccess>
#include <Akonadi/AttributeFactory>
#include <QDialogButtonBox>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment