start QAD::SQL library
QAD::SQLQuery wrapper to minimize code of QSqlQuery usage
This commit is contained in:
63
libs/sql/sql_query.h
Normal file
63
libs/sql/sql_query.h
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
QAD - Qt ADvanced
|
||||
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef sql_query_H
|
||||
#define sql_query_H
|
||||
|
||||
#include "qad_sql_export.h"
|
||||
|
||||
#include <QMap>
|
||||
#include <QSqlError>
|
||||
#include <QSqlQuery>
|
||||
#include <QVariant>
|
||||
|
||||
|
||||
namespace QAD {
|
||||
|
||||
class QAD_SQL_EXPORT SQLQuery {
|
||||
public:
|
||||
SQLQuery(QString query_ = QString(), QVariantMap params = QVariantMap(), QSqlDatabase db = QSqlDatabase());
|
||||
~SQLQuery();
|
||||
|
||||
struct Result {
|
||||
bool ok = false;
|
||||
QVariant insertId = -1;
|
||||
};
|
||||
|
||||
typedef std::function<void(QString, QVariantMap, QSqlError)> HandlerFail;
|
||||
|
||||
QSqlQuery & query() { return q; }
|
||||
|
||||
static Result exec(QString query_, QVariantMap params = QVariantMap(), QSqlDatabase db = QSqlDatabase());
|
||||
|
||||
static void setFailHandler(HandlerFail h);
|
||||
|
||||
protected:
|
||||
QSqlQuery q;
|
||||
|
||||
private:
|
||||
struct Singleton {
|
||||
static Singleton * instance();
|
||||
HandlerFail fail_handler;
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace QAD
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user