2014-03-18 15:28:17 +08:00
|
|
|
/*
|
2016-05-23 20:16:27 +08:00
|
|
|
* Copyright (c) 2013-2016, Roland Bock, Aaron Bishop
|
2014-03-18 15:28:17 +08:00
|
|
|
* All rights reserved.
|
2015-08-05 20:43:21 +08:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without modification,
|
2014-03-18 15:28:17 +08:00
|
|
|
* are permitted provided that the following conditions are met:
|
2015-08-05 20:43:21 +08:00
|
|
|
*
|
|
|
|
* * Redistributions of source code must retain the above copyright notice,
|
2014-03-18 15:28:17 +08:00
|
|
|
* this list of conditions and the following disclaimer.
|
2015-08-05 20:43:21 +08:00
|
|
|
* * Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
2014-03-18 15:28:17 +08:00
|
|
|
* and/or other materials provided with the distribution.
|
2015-08-05 20:43:21 +08:00
|
|
|
*
|
|
|
|
* 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
|
2014-03-18 15:28:17 +08:00
|
|
|
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "MockDb.h"
|
2016-09-07 04:34:59 +08:00
|
|
|
#include "Sample.h"
|
2014-03-18 15:28:17 +08:00
|
|
|
#include "is_regular.h"
|
2016-09-07 04:34:59 +08:00
|
|
|
#include <iostream>
|
2014-03-18 15:28:17 +08:00
|
|
|
#include <sqlpp11/alias_provider.h>
|
|
|
|
#include <sqlpp11/connection.h>
|
2016-09-07 04:34:59 +08:00
|
|
|
#include <sqlpp11/functions.h>
|
|
|
|
#include <sqlpp11/select.h>
|
2016-03-17 01:17:28 +08:00
|
|
|
#include <sqlpp11/without_table_check.h>
|
2014-03-18 15:28:17 +08:00
|
|
|
|
|
|
|
namespace alias
|
|
|
|
{
|
2015-09-14 03:33:19 +08:00
|
|
|
SQLPP_ALIAS_PROVIDER(a)
|
|
|
|
SQLPP_ALIAS_PROVIDER(b)
|
|
|
|
SQLPP_ALIAS_PROVIDER(left)
|
|
|
|
SQLPP_ALIAS_PROVIDER(right)
|
2019-08-21 00:32:16 +08:00
|
|
|
} // namespace alias
|
2014-03-18 15:28:17 +08:00
|
|
|
|
2019-08-21 00:32:16 +08:00
|
|
|
int SelectType(int, char*[])
|
2014-03-18 15:28:17 +08:00
|
|
|
{
|
2015-09-14 03:33:19 +08:00
|
|
|
MockDb db = {};
|
2015-12-28 05:25:05 +08:00
|
|
|
MockDb::_serializer_context_t printer = {};
|
2015-09-14 03:33:19 +08:00
|
|
|
|
2015-12-28 17:58:30 +08:00
|
|
|
auto f = test::TabFoo{};
|
|
|
|
auto t = test::TabBar{};
|
2015-09-14 03:33:19 +08:00
|
|
|
|
|
|
|
// Test a table
|
|
|
|
{
|
2015-12-28 05:25:05 +08:00
|
|
|
using T = typename std::decay<decltype(t)>::type;
|
2015-09-14 03:33:19 +08:00
|
|
|
static_assert(not sqlpp::is_numeric_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::is_integral_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::is_floating_point_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::is_expression_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::is_selectable_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::require_insert_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::must_not_insert_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::must_not_update_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::is_boolean_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::is_text_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::is_alias_t<T>::value, "type requirement");
|
|
|
|
static_assert(sqlpp::is_table_t<T>::value, "type requirement");
|
|
|
|
static_assert(sqlpp::is_regular<T>::value, "type requirement");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test an alias of table
|
|
|
|
{
|
|
|
|
using T = decltype(t.as(alias::a));
|
|
|
|
static_assert(not sqlpp::is_numeric_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::is_integral_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::is_floating_point_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::is_expression_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::is_selectable_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::require_insert_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::must_not_insert_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::must_not_update_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::is_boolean_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::is_text_t<T>::value, "type requirement");
|
|
|
|
static_assert(sqlpp::is_alias_t<T>::value, "type requirement");
|
|
|
|
static_assert(sqlpp::is_table_t<T>::value, "type requirement");
|
|
|
|
static_assert(sqlpp::is_regular<T>::value, "type requirement");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test an integral column of an alias of table
|
|
|
|
{
|
|
|
|
using T = decltype(t.as(alias::a).alpha);
|
|
|
|
static_assert(sqlpp::is_numeric_t<T>::value, "type requirement");
|
|
|
|
static_assert(sqlpp::is_integral_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::is_floating_point_t<T>::value, "type requirement");
|
|
|
|
static_assert(sqlpp::is_expression_t<T>::value, "type requirement");
|
|
|
|
static_assert(sqlpp::is_selectable_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::require_insert_t<T>::value, "type requirement");
|
|
|
|
static_assert(sqlpp::must_not_insert_t<T>::value, "type requirement");
|
|
|
|
static_assert(sqlpp::must_not_update_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::is_boolean_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::is_text_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::is_alias_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::is_table_t<T>::value, "type requirement");
|
|
|
|
static_assert(sqlpp::is_regular<T>::value, "type requirement");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test an integral table column
|
|
|
|
{
|
|
|
|
using T = decltype(t.alpha);
|
|
|
|
static_assert(sqlpp::is_numeric_t<T>::value, "type requirement");
|
|
|
|
static_assert(sqlpp::is_integral_t<T>::value, "type requirement");
|
2016-05-20 19:09:48 +08:00
|
|
|
static_assert(not sqlpp::is_unsigned_integral_t<T>::value, "type requirement");
|
2015-09-14 03:33:19 +08:00
|
|
|
static_assert(not sqlpp::is_floating_point_t<T>::value, "type requirement");
|
|
|
|
static_assert(sqlpp::is_expression_t<T>::value, "type requirement");
|
|
|
|
static_assert(sqlpp::is_selectable_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::require_insert_t<T>::value, "type requirement");
|
|
|
|
static_assert(sqlpp::must_not_insert_t<T>::value, "type requirement");
|
|
|
|
static_assert(sqlpp::must_not_update_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::is_boolean_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::is_text_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::is_alias_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::is_table_t<T>::value, "type requirement");
|
|
|
|
static_assert(sqlpp::is_regular<T>::value, "type requirement");
|
|
|
|
}
|
|
|
|
|
2016-05-20 19:09:48 +08:00
|
|
|
// Test an unsigned integral table column
|
|
|
|
{
|
|
|
|
using T = decltype(f.psi);
|
|
|
|
static_assert(sqlpp::is_numeric_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::is_integral_t<T>::value, "type requirement");
|
|
|
|
static_assert(sqlpp::is_unsigned_integral_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::is_floating_point_t<T>::value, "type requirement");
|
|
|
|
static_assert(sqlpp::is_expression_t<T>::value, "type requirement");
|
|
|
|
static_assert(sqlpp::is_selectable_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::require_insert_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::is_boolean_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::is_text_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::is_alias_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::is_table_t<T>::value, "type requirement");
|
|
|
|
static_assert(sqlpp::is_regular<T>::value, "type requirement");
|
2016-09-07 04:34:59 +08:00
|
|
|
// subtraction on unsigned makes it signed
|
|
|
|
static_assert(sqlpp::is_integral_t<sqlpp::return_type_minus_t<T, T>>::value, "type requirement");
|
|
|
|
static_assert(sqlpp::is_integral_t<sqlpp::return_type_unary_minus_t<T, T>>::value, "type requirement");
|
|
|
|
// any operation on float makes it float
|
|
|
|
static_assert(sqlpp::is_floating_point_t<sqlpp::return_type_minus_t<T, sqlpp::floating_point>>::value,
|
|
|
|
"type requirement");
|
|
|
|
static_assert(sqlpp::is_floating_point_t<sqlpp::return_type_plus_t<T, sqlpp::floating_point>>::value,
|
|
|
|
"type requirement");
|
|
|
|
static_assert(sqlpp::is_floating_point_t<sqlpp::return_type_multiplies_t<T, sqlpp::floating_point>>::value,
|
|
|
|
"type requirement");
|
|
|
|
static_assert(sqlpp::is_floating_point_t<sqlpp::return_type_divides_t<T, sqlpp::floating_point>>::value,
|
|
|
|
"type requirement");
|
|
|
|
static_assert(sqlpp::is_floating_point_t<sqlpp::return_type_minus_t<sqlpp::floating_point, T>>::value,
|
|
|
|
"type requirement");
|
|
|
|
static_assert(sqlpp::is_floating_point_t<sqlpp::return_type_plus_t<sqlpp::floating_point, T>>::value,
|
|
|
|
"type requirement");
|
|
|
|
static_assert(sqlpp::is_floating_point_t<sqlpp::return_type_multiplies_t<sqlpp::floating_point, T>>::value,
|
|
|
|
"type requirement");
|
|
|
|
static_assert(sqlpp::is_floating_point_t<sqlpp::return_type_divides_t<sqlpp::floating_point, T>>::value,
|
|
|
|
"type requirement");
|
|
|
|
static_assert(sqlpp::is_floating_point_t<sqlpp::return_type_modulus_t<sqlpp::floating_point, T>>::value,
|
|
|
|
"type requirement");
|
|
|
|
// signed operation on unsigned makes it signed
|
|
|
|
static_assert(sqlpp::is_integral_t<sqlpp::return_type_minus_t<T, sqlpp::integral>>::value, "type requirement");
|
|
|
|
static_assert(sqlpp::is_integral_t<sqlpp::return_type_plus_t<T, sqlpp::integral>>::value, "type requirement");
|
|
|
|
static_assert(sqlpp::is_integral_t<sqlpp::return_type_multiplies_t<T, sqlpp::integral>>::value, "type requirement");
|
2019-08-21 00:32:16 +08:00
|
|
|
static_assert(sqlpp::is_floating_point_t<sqlpp::return_type_divides_t<T, sqlpp::integral>>::value,
|
|
|
|
"type requirement");
|
2016-09-07 04:34:59 +08:00
|
|
|
static_assert(sqlpp::is_integral_t<sqlpp::return_type_minus_t<sqlpp::integral, T>>::value, "type requirement");
|
|
|
|
static_assert(sqlpp::is_integral_t<sqlpp::return_type_plus_t<sqlpp::integral, T>>::value, "type requirement");
|
|
|
|
static_assert(sqlpp::is_integral_t<sqlpp::return_type_multiplies_t<sqlpp::integral, T>>::value, "type requirement");
|
2016-11-12 17:35:03 +08:00
|
|
|
static_assert(sqlpp::is_floating_point_t<sqlpp::return_type_divides_t<sqlpp::integral, T>>::value,
|
|
|
|
"type requirement");
|
2016-09-07 04:34:59 +08:00
|
|
|
static_assert(sqlpp::is_integral_t<sqlpp::return_type_modulus_t<sqlpp::integral, T>>::value, "type requirement");
|
2016-05-20 19:09:48 +08:00
|
|
|
}
|
|
|
|
|
2015-09-14 03:33:19 +08:00
|
|
|
// Test a floating point table column
|
|
|
|
{
|
|
|
|
using T = decltype(f.omega);
|
|
|
|
static_assert(sqlpp::is_numeric_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::is_integral_t<T>::value, "type requirement");
|
|
|
|
static_assert(sqlpp::is_floating_point_t<T>::value, "type requirement");
|
|
|
|
static_assert(sqlpp::is_expression_t<T>::value, "type requirement");
|
|
|
|
static_assert(sqlpp::is_selectable_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::require_insert_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::must_not_insert_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::must_not_update_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::is_boolean_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::is_text_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::is_alias_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::is_table_t<T>::value, "type requirement");
|
|
|
|
static_assert(sqlpp::is_regular<T>::value, "type requirement");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test a an alias of a numeric table column
|
|
|
|
{
|
|
|
|
using T = decltype(t.alpha.as(alias::a));
|
|
|
|
static_assert(sqlpp::is_numeric_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::is_expression_t<T>::value, "type requirement");
|
|
|
|
static_assert(sqlpp::is_selectable_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::require_insert_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::must_not_insert_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::must_not_update_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::is_boolean_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::is_text_t<T>::value, "type requirement");
|
|
|
|
static_assert(sqlpp::is_alias_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::is_table_t<T>::value, "type requirement");
|
|
|
|
static_assert(sqlpp::is_regular<T>::value, "type requirement");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test a select of a single column without a from
|
|
|
|
{
|
|
|
|
using T = decltype(select(t.alpha));
|
|
|
|
static_assert(sqlpp::is_numeric_t<T>::value, "type requirement");
|
|
|
|
static_assert(sqlpp::is_expression_t<T>::value, "type requirement");
|
|
|
|
static_assert(sqlpp::is_selectable_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::require_insert_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::must_not_insert_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::must_not_update_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::is_boolean_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::is_text_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::is_alias_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::is_table_t<T>::value, "type requirement");
|
|
|
|
static_assert(sqlpp::is_regular<T>::value, "type requirement");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test a select of a single numeric table column
|
|
|
|
{
|
|
|
|
using T = decltype(select(t.alpha).from(t));
|
|
|
|
// static_assert(sqlpp::is_select_column_list_t<decltype(T::_column_list)>::value, "Must not be noop");
|
|
|
|
// static_assert(sqlpp::is_from_t<decltype(T::_from)>::value, "Must not be noop");
|
|
|
|
static_assert(sqlpp::is_numeric_t<T>::value, "type requirement");
|
|
|
|
static_assert(sqlpp::is_expression_t<T>::value, "type requirement");
|
|
|
|
static_assert(sqlpp::is_selectable_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::require_insert_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::must_not_insert_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::must_not_update_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::is_boolean_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::is_text_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::is_alias_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::is_table_t<T>::value, "type requirement");
|
|
|
|
static_assert(sqlpp::is_regular<T>::value, "type requirement");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test a select of an alias of a single numeric table column
|
|
|
|
{
|
|
|
|
using T = decltype(select(t.alpha.as(alias::a)).from(t));
|
|
|
|
static_assert(sqlpp::is_numeric_t<T>::value, "type requirement");
|
|
|
|
static_assert(sqlpp::is_expression_t<T>::value, "type requirement");
|
|
|
|
static_assert(sqlpp::is_selectable_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::require_insert_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::must_not_insert_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::must_not_update_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::is_boolean_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::is_text_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::is_alias_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::is_table_t<T>::value, "type requirement");
|
|
|
|
static_assert(sqlpp::is_regular<T>::value, "type requirement");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test an alias of a select of a single numeric table column
|
|
|
|
{
|
|
|
|
using T = decltype(select(t.alpha).from(t).as(alias::b));
|
|
|
|
static_assert(not sqlpp::is_numeric_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::is_expression_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::is_selectable_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::require_insert_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::must_not_insert_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::must_not_update_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::is_boolean_t<T>::value, "red to not be boolean");
|
|
|
|
static_assert(not sqlpp::is_text_t<T>::value, "type requirement");
|
|
|
|
static_assert(sqlpp::is_alias_t<T>::value, "type requirement");
|
|
|
|
static_assert(sqlpp::is_table_t<T>::value, "type requirement");
|
|
|
|
static_assert(sqlpp::is_regular<T>::value, "type requirement");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test the column of an alias of a select of an alias of a single numeric table column
|
|
|
|
{
|
|
|
|
using T = decltype(select(t.alpha.as(alias::a)).from(t).as(alias::b));
|
|
|
|
static_assert(not sqlpp::is_numeric_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::is_expression_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::is_selectable_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::require_insert_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::must_not_insert_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::must_not_update_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::is_boolean_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::is_text_t<T>::value, "type requirement");
|
|
|
|
static_assert(sqlpp::is_alias_t<T>::value, "type requirement");
|
|
|
|
static_assert(sqlpp::is_table_t<T>::value, "type requirement");
|
|
|
|
static_assert(sqlpp::is_regular<T>::value, "type requirement");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test the column of an alias of a select of a single numeric table column
|
|
|
|
{
|
|
|
|
using T = decltype(select(t.alpha).from(t).as(alias::b).alpha);
|
|
|
|
static_assert(sqlpp::is_numeric_t<T>::value, "type requirement");
|
|
|
|
static_assert(sqlpp::is_expression_t<T>::value, "type requirement");
|
|
|
|
static_assert(sqlpp::is_selectable_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::require_insert_t<T>::value, "type requirement");
|
|
|
|
static_assert(sqlpp::must_not_insert_t<T>::value, "type requirement");
|
|
|
|
static_assert(sqlpp::must_not_update_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::is_boolean_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::is_text_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::is_alias_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::is_table_t<T>::value, "type requirement");
|
|
|
|
static_assert(sqlpp::is_regular<T>::value, "type requirement");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test an alias of a select of an alias of a single numeric table column
|
|
|
|
{
|
|
|
|
using T = decltype(select(t.alpha.as(alias::a)).from(t).as(alias::b).a);
|
|
|
|
static_assert(sqlpp::is_numeric_t<T>::value, "type requirement");
|
|
|
|
static_assert(sqlpp::is_expression_t<T>::value, "type requirement");
|
|
|
|
static_assert(sqlpp::is_selectable_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::require_insert_t<T>::value, "type requirement");
|
|
|
|
static_assert(sqlpp::must_not_insert_t<T>::value, "type requirement");
|
|
|
|
static_assert(sqlpp::must_not_update_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::is_boolean_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::is_text_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::is_alias_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::is_table_t<T>::value, "type requirement");
|
|
|
|
static_assert(sqlpp::is_regular<T>::value, "type requirement");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test that all_of(tab) is expanded in select
|
|
|
|
{
|
|
|
|
auto a = select(all_of(t));
|
|
|
|
auto b = select(t.alpha, t.beta, t.gamma, t.delta);
|
|
|
|
// auto c = select(t);
|
|
|
|
static_assert(std::is_same<decltype(a), decltype(b)>::value, "all_of(t) has to be expanded by select()");
|
|
|
|
// static_assert(std::is_same<decltype(b), decltype(c)>::value, "t has to be expanded by select()");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test that result sets with identical name/value combinations have identical types
|
|
|
|
{
|
|
|
|
auto a = select(t.alpha);
|
|
|
|
auto b = select(f.epsilon.as(t.alpha));
|
|
|
|
using A = typename decltype(a)::_result_row_t<MockDb>;
|
|
|
|
using B = typename decltype(b)::_result_row_t<MockDb>;
|
|
|
|
static_assert(
|
|
|
|
std::is_same<sqlpp::value_type_of<decltype(t.alpha)>, sqlpp::value_type_of<decltype(f.epsilon)>>::value,
|
|
|
|
"Two bigint columns must have identical base_value_type");
|
|
|
|
static_assert(std::is_same<A, B>::value,
|
|
|
|
"select with identical columns(name/value_type) need to have identical result_types");
|
|
|
|
}
|
|
|
|
|
2016-02-25 14:57:28 +08:00
|
|
|
for (const auto& row : db(select(all_of(t)).from(t).unconditionally()))
|
2015-09-14 03:33:19 +08:00
|
|
|
{
|
|
|
|
int64_t a = row.alpha;
|
|
|
|
std::cout << a << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2016-02-25 14:57:28 +08:00
|
|
|
auto s = dynamic_select(db, all_of(t)).dynamic_from(t).dynamic_where().dynamic_limit().dynamic_offset();
|
|
|
|
s.from.add(dynamic_join(f).on(f.omega > t.alpha));
|
2016-03-17 01:17:28 +08:00
|
|
|
s.where.add(without_table_check(f.omega > 7 and t.alpha == any(select(t.alpha).from(t).where(t.alpha < 3))));
|
2016-09-07 04:34:59 +08:00
|
|
|
s.limit.set(30u);
|
|
|
|
s.limit.set(3u);
|
2015-09-14 03:33:19 +08:00
|
|
|
std::cerr << "------------------------\n";
|
|
|
|
serialize(s, printer).str();
|
|
|
|
std::cerr << "------------------------\n";
|
|
|
|
using T = decltype(s);
|
|
|
|
static_assert(sqlpp::is_regular<T>::value, "type requirement");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test that select can be called with zero columns if it is used with dynamic columns.
|
|
|
|
{
|
2016-03-18 00:28:59 +08:00
|
|
|
auto s = dynamic_select(db).dynamic_columns();
|
|
|
|
s.selected_columns.add(without_table_check(t.alpha));
|
2015-09-14 03:33:19 +08:00
|
|
|
serialize(s, printer).str();
|
|
|
|
}
|
|
|
|
|
2017-10-17 02:43:07 +08:00
|
|
|
{
|
|
|
|
auto find_query = sqlpp::dynamic_select(db).dynamic_columns(t.alpha.as(alias::a)).dynamic_from(t).unconditionally();
|
|
|
|
find_query.from.add(sqlpp::dynamic_join(f).on(t.alpha == f.omega));
|
|
|
|
find_query.selected_columns.add(sqlpp::without_table_check(f.omega.as(alias::b)));
|
|
|
|
}
|
|
|
|
|
2015-09-14 03:33:19 +08:00
|
|
|
// Test that verbatim_table compiles
|
|
|
|
{
|
|
|
|
auto s = select(t.alpha).from(sqlpp::verbatim_table("my_unknown_table"));
|
|
|
|
serialize(s, printer).str();
|
|
|
|
}
|
|
|
|
|
|
|
|
static_assert(sqlpp::is_select_flag_t<decltype(sqlpp::all)>::value, "sqlpp::all has to be a select_flag");
|
2014-06-14 16:15:42 +08:00
|
|
|
using T = sqlpp::wrap_operand<int>::type;
|
2015-09-14 03:33:19 +08:00
|
|
|
static_assert(sqlpp::is_regular<T>::value, "type requirement");
|
|
|
|
static_assert(sqlpp::is_expression_t<T>::value, "T has to be an expression");
|
|
|
|
static_assert(sqlpp::is_numeric_t<T>::value, "T has to be numeric");
|
|
|
|
static_assert(sqlpp::is_numeric_t<decltype(t.alpha)>::value, "TabBar.alpha has to be a numeric");
|
|
|
|
((t.alpha + 7) + 4).asc();
|
2016-04-06 16:16:35 +08:00
|
|
|
static_assert(sqlpp::is_boolean_t<decltype(t.gamma != not(t.gamma))>::value,
|
|
|
|
"Comparison expression have to be boolean");
|
2015-09-14 03:33:19 +08:00
|
|
|
!t.gamma;
|
|
|
|
serialize(t.beta < "kaesekuchen", printer).str();
|
|
|
|
serialize(t.beta + "hallenhalma", printer).str();
|
|
|
|
static_assert(sqlpp::must_not_insert_t<decltype(t.alpha)>::value, "alpha must not be inserted");
|
|
|
|
serialize(t.alpha, printer).str();
|
|
|
|
std::cerr << "\n" << sizeof(test::TabBar) << std::endl;
|
|
|
|
static_assert(sqlpp::is_selectable_t<decltype(t.alpha)>::value, "alpha should be a named expression");
|
|
|
|
static_assert(sqlpp::is_selectable_t<decltype(t.alpha.as(alias::a))>::value,
|
|
|
|
"an alias of alpha should be a named expression");
|
|
|
|
static_assert(sqlpp::is_alias_t<decltype(t.alpha.as(alias::a))>::value, "an alias of alpha should be an alias");
|
|
|
|
|
|
|
|
auto l = t.as(alias::left);
|
|
|
|
auto r = select(t.gamma.as(alias::a)).from(t).where(t.gamma == true).as(alias::right);
|
|
|
|
static_assert(sqlpp::is_boolean_t<decltype(select(t.gamma).from(t))>::value, "select(bool) has to be a bool");
|
|
|
|
static_assert(sqlpp::is_boolean_t<decltype(select(r.a).from(r))>::value, "select(bool) has to be a bool");
|
|
|
|
auto s1 = sqlpp::select()
|
|
|
|
.flags(sqlpp::distinct, sqlpp::straight_join)
|
2015-10-03 23:00:53 +08:00
|
|
|
.columns(l.gamma, r.a)
|
2016-03-06 17:36:42 +08:00
|
|
|
.from(r.cross_join(t).cross_join(l))
|
2015-09-14 03:33:19 +08:00
|
|
|
.where(t.beta == "hello world" and select(t.gamma).from(t)) // .as(alias::right))
|
|
|
|
.group_by(l.gamma, r.a)
|
|
|
|
.having(r.a != true)
|
|
|
|
.order_by(l.beta.asc())
|
2016-09-07 04:34:59 +08:00
|
|
|
.limit(17u)
|
|
|
|
.offset(3u)
|
2015-09-14 03:33:19 +08:00
|
|
|
.as(alias::a);
|
|
|
|
|
|
|
|
return 0;
|
2014-03-18 15:28:17 +08:00
|
|
|
}
|