From 7167f6abb1524d82bdc3337a80654ce5dfb5664d Mon Sep 17 00:00:00 2001 From: Jan Dalheimer Date: Fri, 15 Nov 2013 18:33:47 +0100 Subject: [PATCH] Add a unit test for insert() that uses bool and QDateTime instead of QString --- SqlInsert.h | 7 +++++-- tests/inserttest.cpp | 8 ++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/SqlInsert.h b/SqlInsert.h index ea9a8ab..07c5918 100644 --- a/SqlInsert.h +++ b/SqlInsert.h @@ -46,7 +46,7 @@ struct ColumnValue Sql::warning, UsageOfClientSideTime>::print(); } - template + template ::type> ColumnValue(const ColumnT&) : columnName(ColumnT::sqlName()), isDefault(true) { @@ -60,6 +60,9 @@ struct ColumnValue QString columnName; QVariant value; bool isDefault; + + /// @internal needed for InsertExpr's vector + ColumnValue() : isDefault(true) {} }; // TODO find out if it would be possible to have an operator= instead @@ -108,7 +111,7 @@ struct InsertExpr */ InsertExpr columns( const QList& cols ) { - values += cols; + values += cols.toVector(); return *this; } InsertExpr columns( const ColumnValue& col ) diff --git a/tests/inserttest.cpp b/tests/inserttest.cpp index bbb6be7..258b9dd 100644 --- a/tests/inserttest.cpp +++ b/tests/inserttest.cpp @@ -57,6 +57,14 @@ private Q_SLOTS: .queryBuilder() << "INSERT INTO tblPerson (PersonForename,PersonSurname) VALUES (:0,DEFAULT)" << (QVector() << QLatin1String( "Ford" )); + + QTest::newRow( "two col, bool and datetime" ) + << insert() + .into( Person ) + .columns( Person.HireRights << false & Person.Hired << QDateTime(QDate(2013, 1, 1)) ) + .queryBuilder() + << "INSERT INTO tblPerson (HireRights,Hired) VALUES (:0,:1)" + << (QVector() << false << QDateTime(QDate(2013, 1, 1))); } void testInsert()