source: src/sql/sqlengine.h @ 7b3cd0e

qt5
Last change on this file since 7b3cd0e was 4a87a3b, checked in by gregor herrmann <gregoa@…>, 8 years ago

Bump copyright year.

In anticipation of a release in 2015.

  • Property mode set to 100644
File size: 3.1 KB
Line 
1/*
2 * Copyright (C) 2010 Ixonos Plc.
3 * Copyright (C) 2011-2015 Philipp Spitzer, gregor herrmann, Stefan Stahl
4 *
5 * This file is part of ConfClerk.
6 *
7 * ConfClerk is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the Free
9 * Software Foundation, either version 2 of the License, or (at your option)
10 * any later version.
11 *
12 * ConfClerk is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
15 * more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * ConfClerk.  If not, see <http://www.gnu.org/licenses/>.
19 */
20#ifndef SQLENGINE_H
21#define SQLENGINE_H
22
23#include <QObject>
24#include <QHash>
25#include <QSqlDatabase>
26
27
28class SqlEngine : public QObject {
29    Q_OBJECT
30    public:
31        QString dbFilename; ///< database filename including path
32        QSqlDatabase db; ///< this may be private one day...
33
34        SqlEngine(QObject *aParent = NULL);
35        ~SqlEngine();
36
37        // Open/Close
38        void open(); ///< emits a database error if failed.
39        bool isOpen() const {return db.isOpen();}
40        void close() {db.close();}
41
42        // Schema version
43        /// returns the "user_version" of the database schema
44        /// we return -1 for an empty database
45        /// the database has to be open
46        /// returns -2 if an error occurs and emits the error message
47        int dbSchemaVersion();
48        /// called by createOrUpdateDbSchema. Do not use directly. true for success.
49        bool updateDbSchemaVersion000To001();
50        /// called by createOrUpdateDbSchma. Do not use directly. true for success.
51        bool createCurrentDbSchema();
52        /// creates the current database schema if an empty database is found,
53        /// otherwise updates the schema if an old one is found. true for success.
54        bool createOrUpdateDbSchema();
55        /// Applies an SQL file
56        bool applySqlFile(const QString sqlFile);
57
58        // if a conferneceId != 0 is given, the confernce is updated instead of inserted.
59        void addConferenceToDB(QHash<QString,QString> &aConference, int conferenceId);
60        void addEventToDB(QHash<QString,QString> &aEvent);
61        void addPersonToDB(QHash<QString,QString> &aPerson);
62        void addLinkToDB(QHash<QString,QString> &aLink);
63        void addRoomToDB(QHash<QString,QString> &aRoom);
64        bool deleteConference(int id);
65
66        bool beginTransaction();
67        bool commitTransaction();
68
69        /// search Events for .... returns true if success
70        bool searchEvent(int conferenceId, const QHash<QString,QString> &columns, const QString &keyword);
71    private:
72        static QString login(const QString &aDatabaseType, const QString &aDatabaseName);
73        /// emits a possible error message as signal. Does nothing if there was not last error
74        void emitSqlQueryError(const QSqlQuery& query);
75
76    signals:
77        /// emitted when a database errors occur
78        void dbError(const QString& message);
79};
80
81#endif /* SQLENGINE_H */
82
Note: See TracBrowser for help on using the repository browser.