2013-11-07 20:36:54 +08:00
/*
2014-03-27 23:43:36 +08:00
* Copyright ( c ) 2013 - 2014 , Roland Bock
2013-11-07 20:36:54 +08:00
* All rights reserved .
*
* Redistribution and use in source and binary forms , with or without modification ,
* are permitted provided that the following conditions are met :
*
* * Redistributions of source code must retain the above copyright notice ,
* this list of conditions and the following disclaimer .
* * Redistributions in binary form must reproduce the above copyright notice ,
* this list of conditions and the following disclaimer in the documentation
* and / or other materials provided with the distribution .
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS " AS IS " AND
* ANY EXPRESS OR IMPLIED WARRANTIES , INCLUDING , BUT NOT LIMITED TO , THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED .
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT ,
* INDIRECT , INCIDENTAL , SPECIAL , EXEMPLARY , OR CONSEQUENTIAL DAMAGES ( INCLUDING ,
* BUT NOT LIMITED TO , PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES ; LOSS OF USE ,
* DATA , OR PROFITS ; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY , WHETHER IN CONTRACT , STRICT LIABILITY , OR TORT ( INCLUDING NEGLIGENCE
* OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE , EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE .
*/
2014-01-29 03:53:22 +08:00
# include "Sample.h"
2013-11-07 20:36:54 +08:00
# include "MockDb.h"
2014-01-19 03:58:51 +08:00
# include <sqlpp11/alias_provider.h>
2014-05-16 15:18:08 +08:00
# include <sqlpp11/select.h>
2013-11-07 20:36:54 +08:00
# include <sqlpp11/functions.h>
# include <sqlpp11/connection.h>
# include <iostream>
2014-02-21 14:24:07 +08:00
MockDb db = { } ;
2014-01-19 03:58:51 +08:00
SQLPP_ALIAS_PROVIDER ( kaesekuchen ) ;
2013-11-07 20:36:54 +08:00
int main ( )
{
2014-01-29 03:53:22 +08:00
test : : TabFoo f ;
test : : TabBar t ;
2013-11-07 20:36:54 +08:00
2014-03-24 03:54:44 +08:00
//f.omega + 4 *= "";
2013-11-07 20:36:54 +08:00
// MEMBER FUNCTIONS
// ----------------
// Test in
{
using TI = decltype ( t . alpha . in ( 1 , 2 , 3 ) ) ;
using TF = decltype ( f . omega . in ( 1.0 , 2.0 , 3.0 ) ) ;
using TT = decltype ( t . beta . in ( " a " , " b " , " c " ) ) ;
2013-11-07 22:06:13 +08:00
static_assert ( sqlpp : : is_named_expression_t < TI > : : value , " type requirement " ) ;
2013-11-07 20:36:54 +08:00
static_assert ( sqlpp : : is_boolean_t < TI > : : value , " type requirement " ) ;
static_assert ( not sqlpp : : is_numeric_t < TI > : : value , " type requirement " ) ;
static_assert ( not sqlpp : : is_text_t < TI > : : value , " type requirement " ) ;
2013-11-07 22:06:13 +08:00
static_assert ( sqlpp : : is_named_expression_t < TF > : : value , " type requirement " ) ;
2013-11-07 20:36:54 +08:00
static_assert ( sqlpp : : is_boolean_t < TF > : : value , " type requirement " ) ;
static_assert ( not sqlpp : : is_numeric_t < TF > : : value , " type requirement " ) ;
static_assert ( not sqlpp : : is_text_t < TF > : : value , " type requirement " ) ;
2013-11-07 22:06:13 +08:00
static_assert ( sqlpp : : is_named_expression_t < TF > : : value , " type requirement " ) ;
2013-11-07 20:36:54 +08:00
static_assert ( sqlpp : : is_boolean_t < TT > : : value , " type requirement " ) ;
static_assert ( not sqlpp : : is_numeric_t < TT > : : value , " type requirement " ) ;
static_assert ( not sqlpp : : is_text_t < TT > : : value , " type requirement " ) ;
}
2013-11-08 16:09:52 +08:00
// Test in with value list
{
using TI = decltype ( t . alpha . in ( sqlpp : : value_list ( std : : vector < int > ( { 1 , 2 , 3 } ) ) ) ) ;
using TF = decltype ( f . omega . in ( sqlpp : : value_list ( std : : vector < float > ( { 1.0 , 2.0 , 3.0 } ) ) ) ) ;
using TT = decltype ( t . beta . in ( sqlpp : : value_list ( std : : vector < std : : string > ( { " a " , " b " , " c " } ) ) ) ) ;
static_assert ( sqlpp : : is_named_expression_t < TI > : : value , " type requirement " ) ;
static_assert ( sqlpp : : is_boolean_t < TI > : : value , " type requirement " ) ;
static_assert ( not sqlpp : : is_numeric_t < TI > : : value , " type requirement " ) ;
static_assert ( not sqlpp : : is_text_t < TI > : : value , " type requirement " ) ;
static_assert ( sqlpp : : is_named_expression_t < TF > : : value , " type requirement " ) ;
static_assert ( sqlpp : : is_boolean_t < TF > : : value , " type requirement " ) ;
static_assert ( not sqlpp : : is_numeric_t < TF > : : value , " type requirement " ) ;
static_assert ( not sqlpp : : is_text_t < TF > : : value , " type requirement " ) ;
static_assert ( sqlpp : : is_named_expression_t < TF > : : value , " type requirement " ) ;
static_assert ( sqlpp : : is_boolean_t < TT > : : value , " type requirement " ) ;
static_assert ( not sqlpp : : is_numeric_t < TT > : : value , " type requirement " ) ;
static_assert ( not sqlpp : : is_text_t < TT > : : value , " type requirement " ) ;
}
2013-11-07 20:36:54 +08:00
// Test not_in
{
using TI = decltype ( t . alpha . not_in ( 1 , 2 , 3 ) ) ;
using TF = decltype ( f . omega . not_in ( 1.0 , 2.0 , 3.0 ) ) ;
using TT = decltype ( t . beta . not_in ( " a " , " b " , " c " ) ) ;
2013-11-07 22:06:13 +08:00
static_assert ( sqlpp : : is_named_expression_t < TI > : : value , " type requirement " ) ;
2013-11-07 20:36:54 +08:00
static_assert ( sqlpp : : is_boolean_t < TI > : : value , " type requirement " ) ;
static_assert ( not sqlpp : : is_numeric_t < TI > : : value , " type requirement " ) ;
static_assert ( not sqlpp : : is_text_t < TI > : : value , " type requirement " ) ;
2013-11-07 22:06:13 +08:00
static_assert ( sqlpp : : is_named_expression_t < TF > : : value , " type requirement " ) ;
2013-11-07 20:36:54 +08:00
static_assert ( sqlpp : : is_boolean_t < TF > : : value , " type requirement " ) ;
static_assert ( not sqlpp : : is_numeric_t < TF > : : value , " type requirement " ) ;
static_assert ( not sqlpp : : is_text_t < TF > : : value , " type requirement " ) ;
2013-11-07 22:06:13 +08:00
static_assert ( sqlpp : : is_named_expression_t < TT > : : value , " type requirement " ) ;
2013-11-07 20:36:54 +08:00
static_assert ( sqlpp : : is_boolean_t < TT > : : value , " type requirement " ) ;
static_assert ( not sqlpp : : is_numeric_t < TT > : : value , " type requirement " ) ;
static_assert ( not sqlpp : : is_text_t < TT > : : value , " type requirement " ) ;
}
2013-11-08 16:09:52 +08:00
// Test not in with value list
{
using TI = decltype ( t . alpha . not_in ( sqlpp : : value_list ( std : : vector < int > ( { 1 , 2 , 3 } ) ) ) ) ;
using TF = decltype ( f . omega . not_in ( sqlpp : : value_list ( std : : vector < float > ( { 1.0 , 2.0 , 3.0 } ) ) ) ) ;
using TT = decltype ( t . beta . not_in ( sqlpp : : value_list ( std : : vector < std : : string > ( { " a " , " b " , " c " } ) ) ) ) ;
static_assert ( sqlpp : : is_named_expression_t < TI > : : value , " type requirement " ) ;
static_assert ( sqlpp : : is_boolean_t < TI > : : value , " type requirement " ) ;
static_assert ( not sqlpp : : is_numeric_t < TI > : : value , " type requirement " ) ;
static_assert ( not sqlpp : : is_text_t < TI > : : value , " type requirement " ) ;
static_assert ( sqlpp : : is_named_expression_t < TF > : : value , " type requirement " ) ;
static_assert ( sqlpp : : is_boolean_t < TF > : : value , " type requirement " ) ;
static_assert ( not sqlpp : : is_numeric_t < TF > : : value , " type requirement " ) ;
static_assert ( not sqlpp : : is_text_t < TF > : : value , " type requirement " ) ;
static_assert ( sqlpp : : is_named_expression_t < TF > : : value , " type requirement " ) ;
static_assert ( sqlpp : : is_boolean_t < TT > : : value , " type requirement " ) ;
static_assert ( not sqlpp : : is_numeric_t < TT > : : value , " type requirement " ) ;
static_assert ( not sqlpp : : is_text_t < TT > : : value , " type requirement " ) ;
}
2013-11-07 20:36:54 +08:00
// Test like
{
using TT = decltype ( t . beta . like ( " %c% " ) ) ;
2013-11-07 22:06:13 +08:00
static_assert ( sqlpp : : is_named_expression_t < TT > : : value , " type requirement " ) ;
static_assert ( sqlpp : : is_boolean_t < TT > : : value , " type requirement " ) ;
static_assert ( not sqlpp : : is_numeric_t < TT > : : value , " type requirement " ) ;
static_assert ( not sqlpp : : is_text_t < TT > : : value , " type requirement " ) ;
}
// Test is_null
{
using TI = decltype ( t . alpha . is_null ( ) ) ;
using TF = decltype ( f . omega . is_null ( ) ) ;
using TT = decltype ( t . beta . is_null ( ) ) ;
static_assert ( sqlpp : : is_named_expression_t < TI > : : value , " type requirement " ) ;
static_assert ( sqlpp : : is_boolean_t < TI > : : value , " type requirement " ) ;
static_assert ( not sqlpp : : is_numeric_t < TI > : : value , " type requirement " ) ;
static_assert ( not sqlpp : : is_text_t < TI > : : value , " type requirement " ) ;
static_assert ( sqlpp : : is_named_expression_t < TF > : : value , " type requirement " ) ;
static_assert ( sqlpp : : is_boolean_t < TF > : : value , " type requirement " ) ;
static_assert ( not sqlpp : : is_numeric_t < TF > : : value , " type requirement " ) ;
static_assert ( not sqlpp : : is_text_t < TF > : : value , " type requirement " ) ;
static_assert ( sqlpp : : is_named_expression_t < TT > : : value , " type requirement " ) ;
static_assert ( sqlpp : : is_boolean_t < TT > : : value , " type requirement " ) ;
static_assert ( not sqlpp : : is_numeric_t < TT > : : value , " type requirement " ) ;
static_assert ( not sqlpp : : is_text_t < TT > : : value , " type requirement " ) ;
}
// Test is_not_null
{
using TI = decltype ( t . alpha . is_not_null ( ) ) ;
using TF = decltype ( f . omega . is_not_null ( ) ) ;
using TT = decltype ( t . beta . is_not_null ( ) ) ;
static_assert ( sqlpp : : is_named_expression_t < TI > : : value , " type requirement " ) ;
static_assert ( sqlpp : : is_boolean_t < TI > : : value , " type requirement " ) ;
static_assert ( not sqlpp : : is_numeric_t < TI > : : value , " type requirement " ) ;
static_assert ( not sqlpp : : is_text_t < TI > : : value , " type requirement " ) ;
static_assert ( sqlpp : : is_named_expression_t < TF > : : value , " type requirement " ) ;
static_assert ( sqlpp : : is_boolean_t < TF > : : value , " type requirement " ) ;
static_assert ( not sqlpp : : is_numeric_t < TF > : : value , " type requirement " ) ;
static_assert ( not sqlpp : : is_text_t < TF > : : value , " type requirement " ) ;
static_assert ( sqlpp : : is_named_expression_t < TT > : : value , " type requirement " ) ;
2013-11-07 20:36:54 +08:00
static_assert ( sqlpp : : is_boolean_t < TT > : : value , " type requirement " ) ;
static_assert ( not sqlpp : : is_numeric_t < TT > : : value , " type requirement " ) ;
static_assert ( not sqlpp : : is_text_t < TT > : : value , " type requirement " ) ;
}
// SUB_SELECT_FUNCTIONS
// --------------------
// Test exists
{
using TI = decltype ( exists ( select ( t . alpha ) . from ( t ) ) ) ;
using TT = decltype ( exists ( select ( t . beta ) . from ( t ) ) ) ;
2013-11-07 22:06:13 +08:00
static_assert ( sqlpp : : is_named_expression_t < TI > : : value , " type requirement " ) ;
2013-11-07 20:36:54 +08:00
static_assert ( sqlpp : : is_boolean_t < TI > : : value , " type requirement " ) ;
static_assert ( not sqlpp : : is_numeric_t < TI > : : value , " type requirement " ) ;
static_assert ( not sqlpp : : is_text_t < TI > : : value , " type requirement " ) ;
2013-11-07 22:06:13 +08:00
static_assert ( sqlpp : : is_named_expression_t < TT > : : value , " type requirement " ) ;
2013-11-07 20:36:54 +08:00
static_assert ( sqlpp : : is_boolean_t < TT > : : value , " type requirement " ) ;
static_assert ( not sqlpp : : is_numeric_t < TT > : : value , " type requirement " ) ;
static_assert ( not sqlpp : : is_text_t < TT > : : value , " type requirement " ) ;
}
2014-04-19 01:59:35 +08:00
2013-11-07 20:36:54 +08:00
// Test any
{
2014-05-16 15:18:08 +08:00
using S = decltype ( select ( t . alpha ) . from ( t ) ) ;
static_assert ( sqlpp : : is_numeric_t < S > : : value , " type requirement " ) ;
2014-04-19 01:59:35 +08:00
2013-11-07 20:36:54 +08:00
using TI = decltype ( any ( select ( t . alpha ) . from ( t ) ) ) ;
using TT = decltype ( any ( select ( t . beta ) . from ( t ) ) ) ;
2014-04-19 01:59:35 +08:00
using TF = decltype ( any ( select ( f . omega ) . from ( f ) ) ) ;
2013-11-07 22:06:13 +08:00
static_assert ( not sqlpp : : is_named_expression_t < TI > : : value , " type requirement " ) ;
2013-11-08 16:09:52 +08:00
static_assert ( sqlpp : : is_multi_expression_t < TI > : : value , " type requirement " ) ;
2013-11-07 20:36:54 +08:00
static_assert ( sqlpp : : is_numeric_t < TI > : : value , " type requirement " ) ;
static_assert ( sqlpp : : is_integral_t < TI > : : value , " type requirement " ) ;
static_assert ( not sqlpp : : is_text_t < TI > : : value , " type requirement " ) ;
2013-11-07 22:06:13 +08:00
static_assert ( not sqlpp : : is_named_expression_t < TF > : : value , " type requirement " ) ;
2013-11-08 16:09:52 +08:00
static_assert ( sqlpp : : is_multi_expression_t < TF > : : value , " type requirement " ) ;
2013-11-07 22:06:13 +08:00
static_assert ( sqlpp : : is_numeric_t < TF > : : value , " tFpe requirement " ) ;
2013-11-07 20:36:54 +08:00
static_assert ( sqlpp : : is_floating_point_t < TF > : : value , " type requirement " ) ;
static_assert ( not sqlpp : : is_text_t < TF > : : value , " type requirement " ) ;
2013-11-07 22:06:13 +08:00
static_assert ( not sqlpp : : is_named_expression_t < TT > : : value , " type requirement " ) ;
2013-11-08 16:09:52 +08:00
static_assert ( sqlpp : : is_multi_expression_t < TT > : : value , " type requirement " ) ;
2013-11-07 20:36:54 +08:00
static_assert ( not sqlpp : : is_numeric_t < TT > : : value , " type requirement " ) ;
static_assert ( not sqlpp : : is_integral_t < TT > : : value , " type requirement " ) ;
static_assert ( not sqlpp : : is_floating_point_t < TT > : : value , " type requirement " ) ;
static_assert ( sqlpp : : is_text_t < TT > : : value , " type requirement " ) ;
}
// Test some
{
using TI = decltype ( some ( select ( t . alpha ) . from ( t ) ) ) ;
using TT = decltype ( some ( select ( t . beta ) . from ( t ) ) ) ;
2014-04-19 01:59:35 +08:00
using TF = decltype ( some ( select ( f . omega ) . from ( f ) ) ) ;
2013-11-07 22:06:13 +08:00
static_assert ( not sqlpp : : is_named_expression_t < TI > : : value , " type requirement " ) ;
2013-11-08 16:09:52 +08:00
static_assert ( sqlpp : : is_multi_expression_t < TI > : : value , " type requirement " ) ;
2013-11-07 20:36:54 +08:00
static_assert ( sqlpp : : is_numeric_t < TI > : : value , " type requirement " ) ;
static_assert ( sqlpp : : is_integral_t < TI > : : value , " type requirement " ) ;
static_assert ( not sqlpp : : is_text_t < TI > : : value , " type requirement " ) ;
static_assert ( sqlpp : : is_numeric_t < TF > : : value , " type requirement " ) ;
2013-11-07 22:06:13 +08:00
static_assert ( not sqlpp : : is_named_expression_t < TF > : : value , " type requirement " ) ;
2013-11-08 16:09:52 +08:00
static_assert ( sqlpp : : is_multi_expression_t < TF > : : value , " type requirement " ) ;
2013-11-07 20:36:54 +08:00
static_assert ( sqlpp : : is_floating_point_t < TF > : : value , " type requirement " ) ;
static_assert ( not sqlpp : : is_text_t < TF > : : value , " type requirement " ) ;
static_assert ( not sqlpp : : is_numeric_t < TT > : : value , " type requirement " ) ;
2013-11-07 22:06:13 +08:00
static_assert ( not sqlpp : : is_named_expression_t < TT > : : value , " type requirement " ) ;
2013-11-08 16:09:52 +08:00
static_assert ( sqlpp : : is_multi_expression_t < TT > : : value , " type requirement " ) ;
2013-11-07 20:36:54 +08:00
static_assert ( not sqlpp : : is_integral_t < TT > : : value , " type requirement " ) ;
static_assert ( not sqlpp : : is_floating_point_t < TT > : : value , " type requirement " ) ;
static_assert ( sqlpp : : is_text_t < TT > : : value , " type requirement " ) ;
}
// NUMERIC FUNCTIONS
// -----------------
// Test avg
{
using TI = decltype ( avg ( t . alpha ) ) ;
using TF = decltype ( avg ( f . omega ) ) ;
2013-11-07 22:06:13 +08:00
static_assert ( sqlpp : : is_named_expression_t < TI > : : value , " type requirement " ) ;
2013-11-07 20:36:54 +08:00
static_assert ( sqlpp : : is_numeric_t < TI > : : value , " type requirement " ) ;
static_assert ( not sqlpp : : is_integral_t < TI > : : value , " type requirement " ) ;
static_assert ( sqlpp : : is_floating_point_t < TI > : : value , " type requirement " ) ;
2013-11-07 22:06:13 +08:00
static_assert ( sqlpp : : is_named_expression_t < TF > : : value , " type requirement " ) ;
2013-11-07 20:36:54 +08:00
static_assert ( sqlpp : : is_numeric_t < TF > : : value , " type requirement " ) ;
static_assert ( not sqlpp : : is_integral_t < TF > : : value , " type requirement " ) ;
static_assert ( sqlpp : : is_floating_point_t < TF > : : value , " type requirement " ) ;
}
// Test count
{
using TI = decltype ( count ( t . alpha ) ) ;
using TT = decltype ( count ( t . beta ) ) ;
using TF = decltype ( count ( f . omega ) ) ;
2013-11-07 22:06:13 +08:00
static_assert ( sqlpp : : is_named_expression_t < TI > : : value , " type requirement " ) ;
2013-11-07 20:36:54 +08:00
static_assert ( sqlpp : : is_numeric_t < TI > : : value , " type requirement " ) ;
static_assert ( sqlpp : : is_integral_t < TI > : : value , " type requirement " ) ;
static_assert ( not sqlpp : : is_floating_point_t < TI > : : value , " type requirement " ) ;
2013-11-07 22:06:13 +08:00
static_assert ( sqlpp : : is_named_expression_t < TF > : : value , " type requirement " ) ;
2013-11-07 20:36:54 +08:00
static_assert ( sqlpp : : is_numeric_t < TF > : : value , " type requirement " ) ;
static_assert ( sqlpp : : is_integral_t < TF > : : value , " type requirement " ) ;
static_assert ( not sqlpp : : is_floating_point_t < TF > : : value , " type requirement " ) ;
2013-11-07 22:06:13 +08:00
static_assert ( sqlpp : : is_named_expression_t < TT > : : value , " type requirement " ) ;
static_assert ( sqlpp : : is_numeric_t < TT > : : value , " type requirement " ) ;
static_assert ( sqlpp : : is_integral_t < TT > : : value , " type requirement " ) ;
static_assert ( not sqlpp : : is_floating_point_t < TT > : : value , " type requirement " ) ;
2013-11-07 20:36:54 +08:00
}
// Test max
{
using TI = decltype ( max ( t . alpha ) ) ;
using TF = decltype ( max ( f . omega ) ) ;
2013-11-07 22:06:13 +08:00
using TT = decltype ( max ( t . beta ) ) ;
static_assert ( sqlpp : : is_named_expression_t < TI > : : value , " type requirement " ) ;
2013-11-07 20:36:54 +08:00
static_assert ( sqlpp : : is_numeric_t < TI > : : value , " type requirement " ) ;
static_assert ( sqlpp : : is_integral_t < TI > : : value , " type requirement " ) ;
static_assert ( not sqlpp : : is_floating_point_t < TI > : : value , " type requirement " ) ;
2013-11-07 22:06:13 +08:00
static_assert ( sqlpp : : is_named_expression_t < TF > : : value , " type requirement " ) ;
2013-11-07 20:36:54 +08:00
static_assert ( sqlpp : : is_numeric_t < TF > : : value , " type requirement " ) ;
static_assert ( not sqlpp : : is_integral_t < TF > : : value , " type requirement " ) ;
static_assert ( sqlpp : : is_floating_point_t < TF > : : value , " type requirement " ) ;
2013-11-07 22:06:13 +08:00
static_assert ( sqlpp : : is_named_expression_t < TT > : : value , " type requirement " ) ;
static_assert ( not sqlpp : : is_numeric_t < TT > : : value , " type requirement " ) ;
static_assert ( sqlpp : : is_text_t < TT > : : value , " type requirement " ) ;
2013-11-07 20:36:54 +08:00
}
// Test min
{
using TI = decltype ( min ( t . alpha ) ) ;
using TF = decltype ( min ( f . omega ) ) ;
2013-11-07 22:06:13 +08:00
using TT = decltype ( min ( t . beta ) ) ;
static_assert ( sqlpp : : is_named_expression_t < TI > : : value , " type requirement " ) ;
2013-11-07 20:36:54 +08:00
static_assert ( sqlpp : : is_numeric_t < TI > : : value , " type requirement " ) ;
static_assert ( sqlpp : : is_integral_t < TI > : : value , " type requirement " ) ;
static_assert ( not sqlpp : : is_floating_point_t < TI > : : value , " type requirement " ) ;
2013-11-07 22:06:13 +08:00
static_assert ( sqlpp : : is_named_expression_t < TF > : : value , " type requirement " ) ;
2013-11-07 20:36:54 +08:00
static_assert ( sqlpp : : is_numeric_t < TF > : : value , " type requirement " ) ;
static_assert ( not sqlpp : : is_integral_t < TF > : : value , " type requirement " ) ;
static_assert ( sqlpp : : is_floating_point_t < TF > : : value , " type requirement " ) ;
2013-11-07 22:06:13 +08:00
static_assert ( sqlpp : : is_named_expression_t < TT > : : value , " type requirement " ) ;
static_assert ( not sqlpp : : is_numeric_t < TT > : : value , " type requirement " ) ;
static_assert ( sqlpp : : is_text_t < TT > : : value , " type requirement " ) ;
2013-11-07 20:36:54 +08:00
}
// Test sum
{
using TI = decltype ( sum ( t . alpha ) ) ;
using TF = decltype ( sum ( f . omega ) ) ;
2013-11-07 22:06:13 +08:00
static_assert ( sqlpp : : is_named_expression_t < TF > : : value , " type requirement " ) ;
2013-11-07 20:36:54 +08:00
static_assert ( sqlpp : : is_numeric_t < TI > : : value , " type requirement " ) ;
static_assert ( sqlpp : : is_integral_t < TI > : : value , " type requirement " ) ;
static_assert ( not sqlpp : : is_floating_point_t < TI > : : value , " type requirement " ) ;
2013-11-07 22:06:13 +08:00
static_assert ( sqlpp : : is_named_expression_t < TF > : : value , " type requirement " ) ;
2013-11-07 20:36:54 +08:00
static_assert ( sqlpp : : is_numeric_t < TF > : : value , " type requirement " ) ;
static_assert ( not sqlpp : : is_integral_t < TF > : : value , " type requirement " ) ;
static_assert ( sqlpp : : is_floating_point_t < TF > : : value , " type requirement " ) ;
}
2013-11-07 22:06:13 +08:00
// MISC FUNCTIONS
// --------------
// test value
{
using TB = decltype ( sqlpp : : value ( true ) ) ;
using TI = decltype ( sqlpp : : value ( 7 ) ) ;
using TF = decltype ( sqlpp : : value ( 1.5 ) ) ;
using TT = decltype ( sqlpp : : value ( " cheesecake " ) ) ;
static_assert ( not sqlpp : : is_named_expression_t < TB > : : value , " type requirement " ) ;
static_assert ( sqlpp : : is_boolean_t < TB > : : value , " type requirement " ) ;
static_assert ( not sqlpp : : is_named_expression_t < TB > : : value , " type requirement " ) ;
static_assert ( sqlpp : : is_integral_t < TI > : : value , " type requirement " ) ;
static_assert ( not sqlpp : : is_named_expression_t < TI > : : value , " type requirement " ) ;
static_assert ( sqlpp : : is_floating_point_t < TF > : : value , " type requirement " ) ;
static_assert ( not sqlpp : : is_named_expression_t < TT > : : value , " type requirement " ) ;
static_assert ( sqlpp : : is_text_t < TT > : : value , " type requirement " ) ;
}
// test flatten
{
using TB = decltype ( flatten ( t . gamma , db ) ) ;
using TI = decltype ( flatten ( t . alpha , db ) ) ;
using TF = decltype ( flatten ( f . omega , db ) ) ;
using TT = decltype ( flatten ( t . beta , db ) ) ;
static_assert ( not sqlpp : : is_named_expression_t < TB > : : value , " type requirement " ) ;
static_assert ( sqlpp : : is_boolean_t < TB > : : value , " type requirement " ) ;
static_assert ( not sqlpp : : is_named_expression_t < TB > : : value , " type requirement " ) ;
static_assert ( sqlpp : : is_integral_t < TI > : : value , " type requirement " ) ;
static_assert ( not sqlpp : : is_named_expression_t < TI > : : value , " type requirement " ) ;
static_assert ( sqlpp : : is_floating_point_t < TF > : : value , " type requirement " ) ;
static_assert ( not sqlpp : : is_named_expression_t < TT > : : value , " type requirement " ) ;
static_assert ( sqlpp : : is_text_t < TT > : : value , " type requirement " ) ;
}
// test verbatim
{
using TB = decltype ( sqlpp : : verbatim < sqlpp : : boolean > ( " 1 " ) ) ;
using TI = decltype ( sqlpp : : verbatim < sqlpp : : bigint > ( " 42 " ) ) ;
using TF = decltype ( sqlpp : : verbatim < sqlpp : : floating_point > ( " 1.5 " ) ) ;
using TT = decltype ( sqlpp : : verbatim < sqlpp : : text > ( " cheesecake " ) ) ;
static_assert ( not sqlpp : : is_named_expression_t < TB > : : value , " type requirement " ) ;
static_assert ( sqlpp : : is_boolean_t < TB > : : value , " type requirement " ) ;
static_assert ( not sqlpp : : is_named_expression_t < TB > : : value , " type requirement " ) ;
static_assert ( sqlpp : : is_integral_t < TI > : : value , " type requirement " ) ;
static_assert ( not sqlpp : : is_named_expression_t < TI > : : value , " type requirement " ) ;
static_assert ( sqlpp : : is_floating_point_t < TF > : : value , " type requirement " ) ;
static_assert ( not sqlpp : : is_named_expression_t < TT > : : value , " type requirement " ) ;
static_assert ( sqlpp : : is_text_t < TT > : : value , " type requirement " ) ;
}
2013-11-17 06:19:37 +08:00
// test verbatim_table
{
using T = decltype ( sqlpp : : verbatim_table ( " cheesecake " ) ) ;
static_assert ( not sqlpp : : is_named_expression_t < T > : : value , " type requirement " ) ;
static_assert ( not sqlpp : : is_expression_t < T > : : value , " type requirement " ) ;
static_assert ( sqlpp : : is_table_t < T > : : value , " type requirement " ) ;
}
// test verbatim_table alias
{
using T = decltype ( sqlpp : : verbatim_table ( " cheesecake " ) . as ( kaesekuchen ) ) ;
static_assert ( not sqlpp : : is_named_expression_t < T > : : value , " type requirement " ) ;
static_assert ( not sqlpp : : is_expression_t < T > : : value , " type requirement " ) ;
static_assert ( sqlpp : : is_table_t < T > : : value , " type requirement " ) ;
static_assert ( sqlpp : : is_alias_t < T > : : value , " type requirement " ) ;
}
2014-07-30 00:18:57 +08:00
// test tvin
{
static_assert ( std : : is_same < decltype ( sqlpp : : tvin ( 1 ) ) , sqlpp : : tvin_arg_t < sqlpp : : integral_operand > > : : value , " integral values are accepted and wrapped " ) ;
static_assert ( std : : is_same < decltype ( sqlpp : : tvin ( false ) ) , sqlpp : : tvin_arg_t < sqlpp : : boolean_operand > > : : value , " bool values are accepted and wrapped " ) ;
static_assert ( std : : is_same < decltype ( sqlpp : : tvin ( 0.17 ) ) , sqlpp : : tvin_arg_t < sqlpp : : floating_point_operand > > : : value , " float values are accepted and wrapped " ) ;
static_assert ( std : : is_same < decltype ( sqlpp : : tvin ( " test " ) ) , sqlpp : : tvin_arg_t < sqlpp : : text_operand > > : : value , " text values are accepted and wrapped " ) ;
for ( const auto & row : db ( select ( all_of ( t ) ) . from ( t ) . where ( true ) ) )
{
static_assert ( std : : is_same < decltype ( sqlpp : : tvin ( row . alpha ) ) , sqlpp : : tvin_arg_t < decltype ( row . alpha ) > > : : value , " result fields are accepted and not wrapped " ) ;
static_assert ( std : : is_same < decltype ( sqlpp : : tvin ( row . beta ) ) , sqlpp : : tvin_arg_t < decltype ( row . beta ) > > : : value , " result fields are accepted and not wrapped " ) ;
static_assert ( std : : is_same < decltype ( sqlpp : : tvin ( row . gamma ) ) , sqlpp : : tvin_arg_t < decltype ( row . gamma ) > > : : value , " result fields are accepted and not wrapped " ) ;
}
}
2013-11-07 20:36:54 +08:00
return 0 ;
}