Skip to content

Commit

Permalink
Add a unit test for insert() that uses bool and QDateTime instead of …
Browse files Browse the repository at this point in the history
…QString
  • Loading branch information
02JanDal committed Nov 15, 2013
1 parent d5f41d1 commit 7167f6a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
7 changes: 5 additions & 2 deletions SqlInsert.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ struct ColumnValue
Sql::warning<boost::is_same<typename ColumnT::type, QDateTime>, UsageOfClientSideTime>::print();
}

template <typename ColumnT>
template <typename ColumnT, class = typename boost::enable_if<typename ColumnT::is_column>::type>
ColumnValue(const ColumnT&) :
columnName(ColumnT::sqlName()), isDefault(true)
{
Expand All @@ -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
Expand Down Expand Up @@ -108,7 +111,7 @@ struct InsertExpr
*/
InsertExpr<TableT> columns( const QList<ColumnValue>& cols )
{
values += cols;
values += cols.toVector();
return *this;
}
InsertExpr<TableT> columns( const ColumnValue& col )
Expand Down
8 changes: 8 additions & 0 deletions tests/inserttest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ private Q_SLOTS:
.queryBuilder()
<< "INSERT INTO tblPerson (PersonForename,PersonSurname) VALUES (:0,DEFAULT)"
<< (QVector<QVariant>() << 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<QVariant>() << false << QDateTime(QDate(2013, 1, 1)));
}

void testInsert()
Expand Down

0 comments on commit 7167f6a

Please sign in to comment.