File indexing completed on 2024-04-28 04:50:50

0001 /*
0002  * sqlhelper.h
0003  *
0004  * Copyright (C) 2009-2011 Christoph Pfister <christophpfister@gmail.com>
0005  *
0006  * This program is free software; you can redistribute it and/or modify
0007  * it under the terms of the GNU General Public License as published by
0008  * the Free Software Foundation; either version 2 of the License, or
0009  * (at your option) any later version.
0010  *
0011  * This program is distributed in the hope that it will be useful,
0012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0014  * GNU General Public License for more details.
0015  *
0016  * You should have received a copy of the GNU General Public License along
0017  * with this program; if not, write to the Free Software Foundation, Inc.,
0018  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
0019  */
0020 
0021 #ifndef SQLHELPER_H
0022 #define SQLHELPER_H
0023 
0024 #include <QSharedData>
0025 #include <QSqlDatabase>
0026 #include <QTimer>
0027 
0028 class SqlInterface;
0029 
0030 class SqlHelper : public QObject, public QSharedData
0031 {
0032     Q_OBJECT
0033 private:
0034     SqlHelper();
0035 public:
0036     ~SqlHelper();
0037 
0038     static bool createInstance();
0039     static SqlHelper *getInstance();
0040 
0041     QSqlQuery prepare(const QString &statement);
0042     QSqlQuery exec(const QString &statement);
0043     void exec(QSqlQuery &query);
0044 
0045     void requestSubmission(SqlInterface *object);
0046 
0047 public slots:
0048     void collectSubmissions();
0049 
0050 private:
0051     static SqlHelper *instance;
0052 
0053     QSqlDatabase database;
0054     QTimer timer;
0055     QList<SqlInterface *> objects;
0056 };
0057 
0058 #endif /* SQLHELPER_H */