db.h 2.07 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/***
Pix  Copyright (C) 2018  Camilo Higuita
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.

 This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
***/

21 22 23 24
#ifndef DB_H
#define DB_H

#include <QObject>
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
#include <QString>
#include <QStringList>
#include <QList>
#include <QSqlDatabase>
#include <QDebug>
#include <QSqlQuery>
#include <QSqlError>
#include <QSqlRecord>
#include <QSqlDriver>
#include <QFileInfo>
#include <QDir>
#include <QVariantMap>

#include "../utils/pic.h"

40 41 42 43

class DB : public QObject
{
        Q_OBJECT
44 45 46
    private:
        QString name;
         QSqlDatabase m_db;
47 48
    public:
        explicit DB(QObject *parent = nullptr);
49 50 51 52 53 54 55
        ~ DB();

        void openDB(const QString &name);

        /*basic public actions*/
        void prepareCollectionDB() const;

Camilo Higuita's avatar
Camilo Higuita committed
56
        /* utils*/
57
        Q_INVOKABLE bool checkExistance(const QString &tableName, const QString &searchId, const QString &search);
Camilo Higuita's avatar
Camilo Higuita committed
58 59


60
    protected:
Camilo Higuita's avatar
Camilo Higuita committed
61 62
        QSqlQuery getQuery(const QString &queryTxt);

63 64 65
        bool insert(const QString &tableName, const QVariantMap &insertData);
        bool update(const QString &tableName, const PIX::DB &updateData, const QVariantMap &where);
        bool update(const QString &table, const QString &column, const QVariant &newValue, const QVariant &op, const QString &id);
66
        bool remove(const QString &tableName, const PIX::DB &removeData);
67 68 69 70 71 72

    signals:

    public slots:
};

73
#endif // DB_H