Ignore:
Timestamp:
09/04/12 23:57:13 (10 years ago)
Author:
Philipp Spitzer <philipp@…>
Branches:
master, qt5
Children:
1f12b6b
Parents:
8d6798d
Message:

Restructured the SqlEngine?. Not yet finished (see "TODO" in the code).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sql/sqlengine.h

    r8d6798d r61346c9  
    2323#include <QObject>
    2424#include <QHash>
     25#include <QSqlDatabase>
    2526
    26 class QSqlDatabase;
    2727
    28 class SqlEngine : public QObject
    29 {
     28class SqlEngine : public QObject {
    3029    Q_OBJECT
    3130    public:
     31        QString dbFilename; ///< database filename including path
     32        QSqlDatabase db; ///< this may be private one day...
     33
    3234        SqlEngine(QObject *aParent = NULL);
    3335        ~SqlEngine();
    34         static void initialize();
    35         // if a conferenceId != 0 is given, the confernece is updated instead of inserted.
    36         static void addConferenceToDB(QHash<QString,QString> &aConference, int conferenceId);
    37         static void addEventToDB(QHash<QString,QString> &aEvent);
    38         static void addPersonToDB(QHash<QString,QString> &aPerson);
    39         static void addLinkToDB(QHash<QString,QString> &aLink);
    40         static void addRoomToDB(QHash<QString,QString> &aRoom);
    41         static void deleteConference(int id);
    4236
    43         static bool beginTransaction();
    44         static bool commitTransaction();
     37        // Open/Close
     38        void open(); ///< emits a database error if failed.
     39        bool isOpen() const {return db.isOpen();}
     40        void close() {db.close();}
    4541
    46         // search Events for ....
    47         static int searchEvent(int conferenceId, const QHash<QString,QString> &columns, const QString &keyword);
     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
     56        // if a conferneceId != 0 is given, the confernce is updated instead of inserted.
     57        void addConferenceToDB(QHash<QString,QString> &aConference, int conferenceId);
     58        void addEventToDB(QHash<QString,QString> &aEvent);
     59        void addPersonToDB(QHash<QString,QString> &aPerson);
     60        void addLinkToDB(QHash<QString,QString> &aLink);
     61        void addRoomToDB(QHash<QString,QString> &aRoom);
     62        bool deleteConference(int id);
     63
     64        bool beginTransaction();
     65        bool commitTransaction();
     66
     67        /// search Events for .... returns true if success
     68        bool searchEvent(int conferenceId, const QHash<QString,QString> &columns, const QString &keyword);
    4869    private:
    4970        static QString login(const QString &aDatabaseType, const QString &aDatabaseName);
    50         static bool execQuery(QSqlDatabase &aDatabase, const QString &aQuery);
    51         static bool execQueryWithParameter(QSqlDatabase &aDatabase, const QString &aQuery, const QHash<QString, QVariant>& params);
     71        /// emits a possible error message as signal. Does nothing if there was not last error
     72        void emitSqlQueryError(const QSqlQuery& query);
     73
     74    signals:
     75        /// emitted when a database errors occur
     76        void dbError(const QString& message);
    5277};
    5378
Note: See TracChangeset for help on using the changeset viewer.