additional methods in SQLQuery

This commit is contained in:
2023-06-13 18:54:55 +03:00
parent b061949716
commit cecc90f8d8
2 changed files with 45 additions and 1 deletions

View File

@@ -35,9 +35,11 @@ public:
SQLQuery(QString query_ = QString(), QVariantMap params = QVariantMap(), QSqlDatabase db = QSqlDatabase());
~SQLQuery();
struct Result {
struct QAD_SQL_EXPORT Result {
bool ok = false;
int rows = 0;
QVariant insertId = -1;
operator bool() const { return ok; }
};
typedef std::function<void(QString, QVariantMap, QSqlError)> HandlerFail;
@@ -46,6 +48,15 @@ public:
static Result exec(QString query_, QVariantMap params = QVariantMap(), QSqlDatabase db = QSqlDatabase());
/// INSERT INTO <table> (<values.keys>) VALUES (<values.values>)
static Result insert(QString table, QVariantMap values = QVariantMap(), QSqlDatabase db = QSqlDatabase());
/// DELETE FROM <table> [WHERE <filter>]
static Result remove(QString table, QString filter = QString(), QSqlDatabase db = QSqlDatabase());
/// DROP TABLE <table>
static bool drop(QString table, QSqlDatabase db = QSqlDatabase());
static void setFailHandler(HandlerFail h);
protected: