fixed the backlog replay issue. DISTCLEAN IS MANDATORY
[quassel.git] / src / core / abstractsqlstorage.h
1 /***************************************************************************
2  *   Copyright (C) 2005-07 by the Quassel IRC Team                         *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) version 3.                                           *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19  ***************************************************************************/
20
21 #ifndef ABSTRACTSQLSTORAGE_H
22 #define ABSTRACTSQLSTORAGE_H
23
24 #include "storage.h"
25
26 #include <QSqlDatabase>
27
28 class QSqlQuery;
29
30 class AbstractSqlStorage : public Storage {
31   Q_OBJECT
32
33 public:
34   AbstractSqlStorage(QObject *parent = 0);
35   virtual ~AbstractSqlStorage();
36
37   //! Returns the name of the storage backend engine
38   /** \return A virtual equivalent of displayName() */
39   virtual QString engineName() { return ""; }
40   
41 protected:
42   bool init(const QVariantMap &settings = QVariantMap());
43   virtual void sync();
44   
45   QSqlDatabase logDb();
46   
47   QString queryString(const QString &queryName, int version);
48   QString queryString(const QString &queryName);
49
50   QSqlQuery *cachedQuery(const QString &queryName, int version);
51   QSqlQuery *cachedQuery(const QString &queryName);
52
53   QStringList setupQueries();
54   bool setup(const QVariantMap &settings = QVariantMap());
55
56   QStringList upgradeQueries(int ver);
57   bool upgradeDb();
58
59   bool watchQuery(QSqlQuery *query);
60   
61   int schemaVersion();
62   virtual int installedSchemaVersion() { return -1; };
63
64   virtual QString driverName() = 0;
65   inline virtual QString hostName() { return QString(); }
66   virtual QString databaseName() = 0;
67   inline virtual QString userName() { return QString(); }
68   inline virtual QString password() { return QString(); }
69
70 private:
71   bool openDb();
72
73   int _schemaVersion;
74
75   QHash<QPair<QString, int>, QSqlQuery *> _queryCache;
76
77 };
78
79
80 #endif