File indexing completed on 2024-05-12 04:45:55
0001 /*** 0002 Pix Copyright (C) 2018 Camilo Higuita 0003 This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 0004 This is free software, and you are welcome to redistribute it 0005 under certain conditions; type `show c' for details. 0006 0007 This program is free software: you can redistribute it and/or modify 0008 it under the terms of the GNU General Public License as published by 0009 the Free Software Foundation, either version 3 of the License, or 0010 (at your option) any later version. 0011 0012 This program is distributed in the hope that it will be useful, 0013 but WITHOUT ANY WARRANTY; without even the implied warranty of 0014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0015 GNU General Public License for more details. 0016 0017 You should have received a copy of the GNU General Public License 0018 along with this program. If not, see <http://www.gnu.org/licenses/>. 0019 ***/ 0020 0021 #pragma once 0022 0023 #include <QDebug> 0024 #include <QDir> 0025 #include <QFileInfo> 0026 #include <QList> 0027 #include <QObject> 0028 #include <QSqlDatabase> 0029 #include <QSqlDriver> 0030 #include <QSqlError> 0031 #include <QSqlQuery> 0032 #include <QSqlRecord> 0033 #include <QString> 0034 #include <QStringList> 0035 #include <QVariantMap> 0036 0037 #include "../utils/owl.h" 0038 0039 #include <MauiKit3/Core/fmh.h> 0040 0041 class DB : public QObject 0042 { 0043 Q_OBJECT 0044 0045 private: 0046 DB(); 0047 ~DB(); 0048 0049 DB(const DB &) = delete; 0050 DB &operator=(const DB &) = delete; 0051 DB(DB &&) = delete; 0052 DB &operator=(DB &&) = delete; 0053 0054 QString name; 0055 QSqlDatabase m_db; 0056 0057 public: 0058 static DB *getInstance() 0059 { 0060 static DB db; 0061 return &db; 0062 } 0063 0064 /* utils*/ 0065 bool checkExistance(const QString &tableName, const QString &searchId, const QString &search); 0066 const FMH::MODEL_LIST getDBData(const QString &queryTxt); 0067 QSqlQuery getQuery(const QString &queryTxt); 0068 0069 bool insert(const QString &tableName, const QVariantMap &insertData); 0070 bool update(const QString &tableName, const QVariantMap &updateData, const QVariantMap &where); 0071 bool update(const QString &table, const QString &column, const QVariant &newValue, const QVariant &op, const QString &id); 0072 bool remove(const QString &tableName, const QVariantMap &removeData); 0073 0074 protected: 0075 void openDB(const QString &name); 0076 void prepareCollectionDB() const; 0077 };