diff --git a/src/bulkinserter.h b/src/bulkinserter.h index 04df4b2..9f450b4 100644 --- a/src/bulkinserter.h +++ b/src/bulkinserter.h @@ -5,6 +5,7 @@ #include #include "defines.h" #include "phrases/phraselist.h" +#include "phrases/fieldphrase.h" NUT_BEGIN_NAMESPACE @@ -30,6 +31,63 @@ public: int apply(); }; +//#define HEAD(x, ...) x +//#define TAIL(x, ...) __VA_ARGS__ +//#define ENCLOSE(...) ( __VA_ARGS__ ) +//#define REM_ENCLOSE_(...) __VA_ARGS__ +//#define REM_ENCLOSE(...) REM_ENCLOSE_ __VA_ARGS__ + +//#define IF_ENCLOSED_1(true, ...) true +//#define IF_ENCLOSED_0(true, ...) __VA_ARGS__ +//#define IF_ENCLOSED(...) CAT(IF_ENCLOSED_, IF_ENCLOSED(__VA_ARGS__)) +//// This function will optionally remove brackets around its arguments +//// if there are any. Otherwise it will return normally +//#define OPT_REM_ENCLOSE(...) \ +// IF_ENCLOSED (__VA_ARGS__) ( REM_ENCLOSE(__VA_ARGS__), __VA_ARGS__ ) + +//#define TEST_LAST EXISTS(1) +//#define IS_LIST_EMPTY(...) \ +// TRY_EXTRACT_EXISTS( \ +// DEFER(HEAD) (__VA_ARGS__ EXISTS(1))\ +// , 0) +//#define IS_LIST_NOT_EMPTY(...) NOT(IS_LIST_EMPTY(__VA_ARGS__)) + +//#define FOR_EACH(fVisitor, ...) \ +// fVisitor( OPT_REM_ENCLOSE(HEAD(__VA_ARGS__)) ) \ +// FOR_EACH(fVisitor, TAIL(__VA_ARGS__)) + +//#define NUT_FOREACH(F, ...) \ +// F(HEAD(__VA_ARGS__)); \ +// NUT_FOREACH(F, TAIL(__VA_ARGS__)) +//template +//class Bulk +//{ +//public: +// void f(int){} +// Bulk() +// { +// int a, b, c, d; +// NUT_FOREACH(f, a, c, d) + +// } +//}; + +//template +//class Bulk +//{ +//public: +// Bulk(FieldPhrase) +// {} +//}; + +//template +//class Bulk +//{ +//public: +// Bulk(FieldPhrase, FieldPhrase) +// {} +//}; + NUT_END_NAMESPACE #endif // BULKINSERTER_H diff --git a/src/query.h b/src/query.h index d5cc823..ef582a6 100644 --- a/src/query.h +++ b/src/query.h @@ -83,7 +83,7 @@ public: QVariant min(const FieldPhrase &f); QVariant average(const FieldPhrase &f); - QVariant insert(AssignmentPhraseList p); + QVariant insert(const AssignmentPhraseList &p); //data mailpulation int update(const AssignmentPhraseList &ph); @@ -91,6 +91,7 @@ public: int remove(); QSqlQueryModel *toModel(); + void toModel(QSqlQueryModel *model); //debug purpose QString sqlCommand() const; @@ -410,7 +411,7 @@ Q_OUTOFLINE_TEMPLATE QVariant Query::average(const FieldPhrase &f) } template -Q_OUTOFLINE_TEMPLATE QVariant Query::insert(AssignmentPhraseList p) +Q_OUTOFLINE_TEMPLATE QVariant Query::insert(const AssignmentPhraseList &p) { Q_D(Query); d->sql = d->database->sqlGenertor() @@ -541,6 +542,14 @@ Q_OUTOFLINE_TEMPLATE int Query::remove() template Q_OUTOFLINE_TEMPLATE QSqlQueryModel *Query::toModel() +{ + QSqlQueryModel *model = new QSqlQueryModel; + toModel(model); + return model; +} + +template +Q_OUTOFLINE_TEMPLATE void Query::toModel(QSqlQueryModel *model) { Q_D(Query); @@ -551,7 +560,6 @@ Q_OUTOFLINE_TEMPLATE QSqlQueryModel *Query::toModel() d->skip, d->take); DatabaseModel dbModel = d->database->model(); - QSqlQueryModel *model = new QSqlQueryModel; model->setQuery(d->sql, d->database->database()); int fieldIndex = 0; @@ -573,8 +581,6 @@ Q_OUTOFLINE_TEMPLATE QSqlQueryModel *Query::toModel() f->displayName); } } - - return model; } template