2013-08-14 04:43:10 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2013, Roland Bock
|
|
|
|
* 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-02-10 06:30:30 +08:00
|
|
|
#include <iostream>
|
2014-01-29 03:53:22 +08:00
|
|
|
#include "Sample.h"
|
2013-11-11 01:03:39 +08:00
|
|
|
#include "MockDb.h"
|
|
|
|
#include "is_regular.h"
|
2014-01-19 03:58:51 +08:00
|
|
|
#include <sqlpp11/alias_provider.h>
|
2013-08-14 04:43:10 +08:00
|
|
|
#include <sqlpp11/select.h>
|
2013-11-01 19:23:50 +08:00
|
|
|
#include <sqlpp11/functions.h>
|
2013-10-09 16:36:38 +08:00
|
|
|
#include <sqlpp11/connection.h>
|
2013-08-14 04:43:10 +08:00
|
|
|
|
|
|
|
|
2013-11-11 01:03:39 +08:00
|
|
|
DbMock db = {};
|
2014-01-19 03:58:51 +08:00
|
|
|
DbMock::_context_t printer(std::cerr);
|
|
|
|
|
|
|
|
namespace alias
|
|
|
|
{
|
|
|
|
SQLPP_ALIAS_PROVIDER(a);
|
|
|
|
SQLPP_ALIAS_PROVIDER(b);
|
|
|
|
SQLPP_ALIAS_PROVIDER(left);
|
|
|
|
SQLPP_ALIAS_PROVIDER(right);
|
|
|
|
}
|
2013-08-14 04:43:10 +08:00
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
2014-01-29 03:53:22 +08:00
|
|
|
test::TabFoo f;
|
|
|
|
test::TabBar t;
|
2013-08-14 04:43:10 +08:00
|
|
|
|
|
|
|
// Test a table
|
|
|
|
{
|
|
|
|
using T = decltype(t);
|
|
|
|
static_assert(not sqlpp::is_numeric_t<T>::value, "type requirement");
|
2013-11-07 19:23:49 +08:00
|
|
|
static_assert(not sqlpp::is_integral_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::is_floating_point_t<T>::value, "type requirement");
|
2013-08-14 04:43:10 +08:00
|
|
|
static_assert(not sqlpp::is_expression_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::is_named_expression_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");
|
2013-11-11 01:03:39 +08:00
|
|
|
static_assert(sqlpp::is_regular<T>::value, "type requirement");
|
2013-08-14 04:43:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test an alias of table
|
|
|
|
{
|
2014-01-19 03:58:51 +08:00
|
|
|
using T = decltype(t.as(alias::a));
|
2013-08-14 04:43:10 +08:00
|
|
|
static_assert(not sqlpp::is_numeric_t<T>::value, "type requirement");
|
2013-11-07 19:23:49 +08:00
|
|
|
static_assert(not sqlpp::is_integral_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::is_floating_point_t<T>::value, "type requirement");
|
2013-08-14 04:43:10 +08:00
|
|
|
static_assert(not sqlpp::is_expression_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::is_named_expression_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");
|
2013-11-11 01:03:39 +08:00
|
|
|
static_assert(sqlpp::is_regular<T>::value, "type requirement");
|
2013-08-14 04:43:10 +08:00
|
|
|
}
|
|
|
|
|
2013-11-07 19:23:49 +08:00
|
|
|
// Test an integral column of an alias of table
|
2013-08-14 04:43:10 +08:00
|
|
|
{
|
2014-01-19 03:58:51 +08:00
|
|
|
using T = decltype(t.as(alias::a).alpha);
|
2013-08-14 04:43:10 +08:00
|
|
|
static_assert(sqlpp::is_numeric_t<T>::value, "type requirement");
|
2013-11-07 19:23:49 +08:00
|
|
|
static_assert(sqlpp::is_integral_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::is_floating_point_t<T>::value, "type requirement");
|
2013-08-14 04:43:10 +08:00
|
|
|
static_assert(sqlpp::is_expression_t<T>::value, "type requirement");
|
|
|
|
static_assert(sqlpp::is_named_expression_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");
|
2013-11-11 01:03:39 +08:00
|
|
|
static_assert(sqlpp::is_regular<T>::value, "type requirement");
|
2013-08-14 04:43:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-07 19:23:49 +08:00
|
|
|
// Test an integral table column
|
2013-08-14 04:43:10 +08:00
|
|
|
{
|
|
|
|
using T = decltype(t.alpha);
|
|
|
|
static_assert(sqlpp::is_numeric_t<T>::value, "type requirement");
|
2013-11-07 19:23:49 +08:00
|
|
|
static_assert(sqlpp::is_integral_t<T>::value, "type requirement");
|
|
|
|
static_assert(not sqlpp::is_floating_point_t<T>::value, "type requirement");
|
2013-08-14 04:43:10 +08:00
|
|
|
static_assert(sqlpp::is_expression_t<T>::value, "type requirement");
|
|
|
|
static_assert(sqlpp::is_named_expression_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");
|
2013-11-11 01:03:39 +08:00
|
|
|
static_assert(sqlpp::is_regular<T>::value, "type requirement");
|
2013-08-14 04:43:10 +08:00
|
|
|
}
|
2013-11-07 19:23:49 +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_named_expression_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");
|
2013-11-11 01:03:39 +08:00
|
|
|
static_assert(sqlpp::is_regular<T>::value, "type requirement");
|
2013-11-07 19:23:49 +08:00
|
|
|
}
|
|
|
|
|
2013-08-14 04:43:10 +08:00
|
|
|
// Test a an alias of a numeric table column
|
|
|
|
{
|
2014-01-19 03:58:51 +08:00
|
|
|
using T = decltype(t.alpha.as(alias::a));
|
2013-08-14 04:43:10 +08:00
|
|
|
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_named_expression_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");
|
2013-11-11 01:03:39 +08:00
|
|
|
static_assert(sqlpp::is_regular<T>::value, "type requirement");
|
2013-08-14 04:43:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test a select of a single column without a from
|
|
|
|
{
|
|
|
|
using T = decltype(select(t.alpha)); // Hint: The current rule is pretty crude (a from is required), but certainly better than nothing
|
|
|
|
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_named_expression_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");
|
2013-11-11 01:03:39 +08:00
|
|
|
static_assert(sqlpp::is_regular<T>::value, "type requirement");
|
2013-08-14 04:43:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test a select of a single numeric table column
|
|
|
|
{
|
|
|
|
using T = decltype(select(t.alpha).from(t));
|
2014-02-10 06:30:30 +08:00
|
|
|
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");
|
2013-08-14 04:43:10 +08:00
|
|
|
static_assert(sqlpp::is_numeric_t<T>::value, "type requirement");
|
|
|
|
static_assert(sqlpp::is_expression_t<T>::value, "type requirement");
|
|
|
|
static_assert(sqlpp::is_named_expression_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");
|
2013-11-11 01:03:39 +08:00
|
|
|
static_assert(sqlpp::is_regular<T>::value, "type requirement");
|
2013-08-14 04:43:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test a select of an alias of a single numeric table column
|
|
|
|
{
|
2014-01-19 03:58:51 +08:00
|
|
|
using T = decltype(select(t.alpha.as(alias::a)).from(t));
|
2013-08-14 04:43:10 +08:00
|
|
|
static_assert(sqlpp::is_numeric_t<T>::value, "type requirement");
|
|
|
|
static_assert(sqlpp::is_expression_t<T>::value, "type requirement");
|
|
|
|
static_assert(sqlpp::is_named_expression_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");
|
2013-11-11 01:03:39 +08:00
|
|
|
static_assert(sqlpp::is_regular<T>::value, "type requirement");
|
2013-08-14 04:43:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test an alias of a select of a single numeric table column
|
|
|
|
{
|
2014-01-19 03:58:51 +08:00
|
|
|
using T = decltype(select(t.alpha).from(t).as(alias::b));
|
2013-08-14 04:43:10 +08:00
|
|
|
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_named_expression_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");
|
2013-11-11 01:03:39 +08:00
|
|
|
static_assert(sqlpp::is_regular<T>::value, "type requirement");
|
2013-08-14 04:43:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test the column of an alias of a select of an alias of a single numeric table column
|
|
|
|
{
|
2014-01-19 03:58:51 +08:00
|
|
|
using T = decltype(select(t.alpha.as(alias::a)).from(t).as(alias::b));
|
2013-08-14 04:43:10 +08:00
|
|
|
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_named_expression_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");
|
2013-11-11 01:03:39 +08:00
|
|
|
static_assert(sqlpp::is_regular<T>::value, "type requirement");
|
2013-08-14 04:43:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test the column of an alias of a select of a single numeric table column
|
|
|
|
{
|
2014-01-19 03:58:51 +08:00
|
|
|
using T = decltype(select(t.alpha).from(t).as(alias::b).alpha);
|
2013-08-14 04:43:10 +08:00
|
|
|
static_assert(sqlpp::is_numeric_t<T>::value, "type requirement");
|
|
|
|
static_assert(sqlpp::is_expression_t<T>::value, "type requirement");
|
|
|
|
static_assert(sqlpp::is_named_expression_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");
|
2013-11-11 01:03:39 +08:00
|
|
|
static_assert(sqlpp::is_regular<T>::value, "type requirement");
|
2013-08-14 04:43:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test an alias of a select of an alias of a single numeric table column
|
|
|
|
{
|
2014-01-19 03:58:51 +08:00
|
|
|
using T = decltype(select(t.alpha.as(alias::a)).from(t).as(alias::b).a);
|
2013-08-14 04:43:10 +08:00
|
|
|
static_assert(sqlpp::is_numeric_t<T>::value, "type requirement");
|
|
|
|
static_assert(sqlpp::is_expression_t<T>::value, "type requirement");
|
|
|
|
static_assert(sqlpp::is_named_expression_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");
|
2013-11-11 01:03:39 +08:00
|
|
|
static_assert(sqlpp::is_regular<T>::value, "type requirement");
|
2013-08-14 04:43:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test that select(all_of(tab)) is expanded in select
|
|
|
|
{
|
|
|
|
auto a = select(all_of(t));
|
2014-02-13 15:44:09 +08:00
|
|
|
auto b = select(t.alpha, t.beta, t.gamma, t.delta);
|
2013-10-04 03:36:50 +08:00
|
|
|
//auto c = select(t);
|
2013-08-14 04:43:10 +08:00
|
|
|
static_assert(std::is_same<decltype(a), decltype(b)>::value, "all_of(t) has to be expanded by select()");
|
2013-10-04 03:36:50 +08:00
|
|
|
//static_assert(std::is_same<decltype(b), decltype(c)>::value, "t has to be expanded by select()");
|
2013-08-14 04:43:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test that select(all_of(tab)) is expanded in multi_column
|
|
|
|
{
|
2014-02-13 17:07:51 +08:00
|
|
|
auto a = multi_column(all_of(t)).as(alias::a);
|
|
|
|
auto b = multi_column(t.alpha, t.beta, t.gamma, t.delta).as(alias::a);
|
2013-08-14 04:43:10 +08:00
|
|
|
static_assert(std::is_same<decltype(a), decltype(b)>::value, "all_of(t) has to be expanded by multi_column");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test that a multicolumn is not a value
|
|
|
|
{
|
2014-02-13 17:07:51 +08:00
|
|
|
auto m = multi_column(t.alpha, t.beta).as(alias::a);
|
2014-01-19 03:58:51 +08:00
|
|
|
auto a = select(m).from(t).as(alias::b).a;
|
2013-08-14 04:43:10 +08:00
|
|
|
static_assert(not sqlpp::is_value_t<decltype(a)>::value, "a multi_column is not a value");
|
|
|
|
}
|
2013-09-13 13:24:41 +08:00
|
|
|
// Test that result sets with identical name/value combinations have identical types
|
|
|
|
{
|
|
|
|
auto a = select(t.alpha);
|
2013-11-07 19:23:49 +08:00
|
|
|
auto b = select(f.epsilon.as(t.alpha));
|
2013-09-13 13:24:41 +08:00
|
|
|
using A = typename decltype(a)::_result_row_t;
|
|
|
|
using B = typename decltype(b)::_result_row_t;
|
2013-09-13 15:18:15 +08:00
|
|
|
static_assert(std::is_same<
|
|
|
|
decltype(t.alpha)::_value_type::_base_value_type,
|
2013-11-07 19:23:49 +08:00
|
|
|
decltype(f.epsilon)::_value_type::_base_value_type>::value, "Two bigint columns must have identical base_value_type");
|
2013-09-13 13:24:41 +08:00
|
|
|
static_assert(std::is_same<A, B>::value, "select with identical columns(name/value_type) need to have identical result_types");
|
|
|
|
}
|
|
|
|
|
2013-09-22 18:16:28 +08:00
|
|
|
{
|
2013-10-04 03:36:50 +08:00
|
|
|
auto s = dynamic_select(db, all_of(t)).dynamic_from().dynamic_where().dynamic_limit().dynamic_offset();
|
2014-02-09 05:24:05 +08:00
|
|
|
s.add_from(t);
|
|
|
|
s.add_where(t.alpha > 7 and t.alpha == any(select(t.alpha).from(t).where(t.alpha < 3)));
|
|
|
|
s.set_limit(30);
|
|
|
|
s.set_limit(3);
|
2013-09-22 18:16:28 +08:00
|
|
|
std::cerr << "------------------------\n";
|
2014-01-19 03:58:51 +08:00
|
|
|
interpret(s, printer).flush();
|
2013-09-22 18:16:28 +08:00
|
|
|
std::cerr << "------------------------\n";
|
2013-11-11 01:03:39 +08:00
|
|
|
using T = decltype(s);
|
|
|
|
static_assert(sqlpp::is_regular<T>::value, "type requirement");
|
2013-09-22 18:16:28 +08:00
|
|
|
}
|
|
|
|
|
2013-10-09 16:36:38 +08:00
|
|
|
// Test that select can be called with zero columns if it is used with dynamic columns.
|
|
|
|
{
|
2014-02-09 05:24:05 +08:00
|
|
|
auto s = dynamic_select(db).dynamic_columns();
|
|
|
|
s.add_column(t.alpha);
|
2014-01-19 03:58:51 +08:00
|
|
|
interpret(s, printer).flush();
|
2013-11-17 06:19:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test that verbatim_table compiles
|
|
|
|
{
|
|
|
|
auto s = select(t.alpha).from(sqlpp::verbatim_table("my_unknown_table"));
|
2014-01-19 03:58:51 +08:00
|
|
|
interpret(s, printer).flush();
|
2013-10-09 16:36:38 +08:00
|
|
|
}
|
|
|
|
|
2013-08-14 04:43:10 +08:00
|
|
|
|
|
|
|
static_assert(sqlpp::is_select_flag_t<decltype(sqlpp::all)>::value, "sqlpp::all has to be a select_flag");
|
2014-01-19 03:58:51 +08:00
|
|
|
using T = sqlpp::vendor::wrap_operand<int>::type;
|
2013-11-11 01:03:39 +08:00
|
|
|
static_assert(sqlpp::is_regular<T>::value, "type requirement");
|
2013-08-14 04:43:10 +08:00
|
|
|
static_assert(T::_is_expression, "T has to be an expression");
|
2013-09-29 15:02:51 +08:00
|
|
|
static_assert(std::is_same<typename T::_value_type::_is_numeric, std::true_type>::value, "T has to be a numeric");
|
2013-08-14 04:43:10 +08:00
|
|
|
static_assert(sqlpp::is_numeric_t<T>::value, "T has to be a numeric");
|
2014-01-29 03:53:22 +08:00
|
|
|
static_assert(sqlpp::is_numeric_t<decltype(t.alpha)>::value, "TabBar.alpha has to be a numeric");
|
2013-08-14 04:43:10 +08:00
|
|
|
((t.alpha + 7) + 4).asc();
|
|
|
|
static_assert(sqlpp::is_boolean_t<decltype(t.gamma == t.gamma)>::value, "Comparison expression have to be boolean");
|
|
|
|
auto x = (t.gamma == true) and (t.alpha == 7);
|
|
|
|
auto y = t.gamma and true and t.gamma;
|
|
|
|
!t.gamma;
|
|
|
|
t.beta < "kaesekuchen";
|
2014-01-19 03:58:51 +08:00
|
|
|
interpret(t.beta + "hallenhalma", printer).flush();
|
2013-08-14 04:43:10 +08:00
|
|
|
static_assert(sqlpp::must_not_insert_t<decltype(t.alpha)>::value, "alpha must not be inserted");
|
2014-01-19 03:58:51 +08:00
|
|
|
interpret(t.alpha, printer).flush();
|
2014-01-29 03:53:22 +08:00
|
|
|
std::cerr << "\n" << sizeof(test::TabBar) << std::endl;
|
2013-09-29 15:02:51 +08:00
|
|
|
static_assert(std::is_same<typename decltype(t.alpha)::_value_type::_is_named_expression, std::true_type>::value, "alpha should be a named expression");
|
2013-08-14 04:43:10 +08:00
|
|
|
static_assert(sqlpp::is_named_expression_t<decltype(t.alpha)>::value, "alpha should be a named expression");
|
2014-01-19 03:58:51 +08:00
|
|
|
static_assert(sqlpp::is_named_expression_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");
|
2014-02-09 06:48:35 +08:00
|
|
|
auto z = select(t.alpha).from(t) == 7;
|
2014-01-19 03:58:51 +08:00
|
|
|
auto l = t.as(alias::left);
|
|
|
|
auto r = select(t.gamma.as(alias::a)).from(t).where(t.gamma == true).as(alias::right);
|
2013-08-14 04:43:10 +08:00
|
|
|
static_assert(sqlpp::is_boolean_t<decltype(select(t.gamma).from(t))>::value, "select(bool) has to be a bool");
|
2014-02-09 05:50:26 +08:00
|
|
|
interpret(sqlpp::select().flags(sqlpp::distinct, sqlpp::straight_join).columns(l.alpha, l.beta, select(r.a).from(r))
|
2013-08-14 04:43:10 +08:00
|
|
|
.from(l, r)
|
2014-01-19 03:58:51 +08:00
|
|
|
.where(t.beta == "hello world" and select(t.gamma).from(t))// .as(alias::right))
|
2013-08-14 04:43:10 +08:00
|
|
|
.group_by(l.gamma, r.a)
|
|
|
|
.having(r.a != true)
|
|
|
|
.order_by(l.beta.asc())
|
|
|
|
.limit(17)
|
|
|
|
.offset(3)
|
2014-01-19 03:58:51 +08:00
|
|
|
.as(alias::a)
|
|
|
|
, printer).flush();
|
2013-08-14 04:43:10 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|