dbconfigsqlite.h 1.96 KB
Newer Older
1
/*
2
3
4
    SPDX-FileCopyrightText: 2010 Tobias Koenig <tokoe@kde.org>

    SPDX-License-Identifier: LGPL-2.0-or-later
5
6
7
8
9
10
11
*/

#ifndef DBCONFIGSQLITE_H
#define DBCONFIGSQLITE_H

#include "dbconfig.h"

Laurent Montel's avatar
Laurent Montel committed
12
13
14
15
namespace Akonadi
{
namespace Server
{
16

17
18
class DbConfigSqlite : public DbConfig
{
19
public:
20
    enum Version {
21
22
        Default, /** Uses the Qt sqlite driver */
        Custom   /** Uses the custom qsqlite driver from akonadi/qsqlite */
23
24
    };

25
public:
Daniel Vrátil's avatar
Daniel Vrátil committed
26
    explicit DbConfigSqlite(Version driver);
27
28
29
30

    /**
     * Returns the name of the used driver.
     */
31
    QString driverName() const override;
32
33
34
35

    /**
     * Returns the database name.
     */
36
    QString databaseName() const override;
37
38
39
40
41
42

    /**
     * This method is called whenever the Akonadi server is started
     * and before the initial database connection is set up.
     *
     * At this point the default settings should be determined, merged
43
     * with the given @p settings and written back if @p storeSettings is true.
44
     */
45
    bool init(QSettings &settings, bool storeSettings = true) override;
46
47
48
49
50

    /**
     * This method checks if the requirements for this database connection are met
     * in the system (QSQLITE/QSQLITE3 driver is available, object can be initialized, etc.).
     */
51
    bool isAvailable(QSettings &settings) override;
52
53
54
55
56

    /**
     * This method applies the configured settings to the QtSql @p database
     * instance.
     */
57
    void apply(QSqlDatabase &database) override;
58
59
60
61

    /**
     * Returns whether an internal server needs to be used.
     */
62
    bool useInternalServer() const override;
63

64
65
66
    /**
     * Sets sqlite journal mode to WAL and synchronous mode to NORMAL
     */
67
    void setup() override;
68
private:
69
70
    bool setPragma(QSqlDatabase &db, QSqlQuery &query, const QString &pragma);

71
    Version mDriverVersion;
72
73
74
75
76
77
78
    QString mDatabaseName;
    QString mHostName;
    QString mUserName;
    QString mPassword;
    QString mConnectionOptions;
};

79
80
81
} // namespace Server
} // namespace Akonadi

82
#endif