Skip to content

Commit

Permalink
Add the <> (not equal) operator + unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
02JanDal committed Oct 29, 2013
1 parent c9cdc47 commit 0bf4e0d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
24 changes: 24 additions & 0 deletions SqlSelect.h
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,30 @@ operator==( const ColumnT1& , const placeholder &p )
return c;
}

template <typename ColumnT>
typename boost::enable_if<typename ColumnT::is_column, ConditionValueLeaf<ColumnT, SqlCondition::NotEquals, typename ColumnT::type> >::type
operator!=( const ColumnT &, const typename ColumnT::type& value )
{
ConditionValueLeaf<ColumnT, SqlCondition::NotEquals, typename ColumnT::type> newCond;
newCond.value = QVariant::fromValue( value );
return newCond;
}
template <typename ColumnT1, typename ColumnT2>
typename boost::enable_if<boost::mpl::and_<typename ColumnT1::is_column, typename ColumnT2::is_column>, ConditionColumnLeaf<ColumnT1, SqlCondition::NotEquals, ColumnT2> >::type
operator!=( const ColumnT1&, const ColumnT2& )
{
BOOST_MPL_ASSERT(( boost::is_same<typename ColumnT1::type, typename ColumnT2::type> )); // only compare columns of the same type
return ConditionColumnLeaf<ColumnT1, SqlCondition::NotEquals, ColumnT2>();
}
template <typename ColumnT1>
typename boost::enable_if<typename ColumnT1::is_column, ConditionPlaceholderLeaf<ColumnT1, SqlCondition::NotEquals> >::type
operator!=( const ColumnT1& , const placeholder &p )
{
ConditionPlaceholderLeaf<ColumnT1, SqlCondition::NotEquals> c;
c.placeholder = p.m_name;
return c;
}

template <typename ColumnT>
typename boost::enable_if<typename ColumnT::is_column, ConditionValueLeaf<ColumnT, SqlCondition::Less, typename ColumnT::type> >::type
operator<( const ColumnT &, const typename ColumnT::type& value )
Expand Down
5 changes: 5 additions & 0 deletions tests/selecttest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ private Q_SLOTS:
<< "SELECT tblPerson.id FROM tblPerson WHERE tblPerson.HireRights = :0"
<< (QVector<QVariant>() << true);

QTest::newRow( "single condition, not equal" )
<< select( Person.id ).from( Person ).where( Person.HireRights != true ).queryBuilder()
<< "SELECT tblPerson.id FROM tblPerson WHERE tblPerson.HireRights <> :0"
<< (QVector<QVariant>() << true);

QTest::newRow( "single condition, less than" )
<< select( Person.id ).from( Person ).where( Person.Hired < QDateTime( QDate( 2013, 10, 28 ) )).queryBuilder()
<< "SELECT tblPerson.id FROM tblPerson WHERE tblPerson.Hired < :0"
Expand Down

0 comments on commit 0bf4e0d

Please sign in to comment.