mirror of
https://github.com/rbock/sqlpp11.git
synced 2026-01-05 12:40:40 -06:00
Merge branch 'release/0.43'
This commit is contained in:
@@ -88,6 +88,11 @@ namespace sqlpp
|
||||
static_assert(required_tables_of<dynamic_pre_join_t>::size::value == 0,
|
||||
"joined tables must not depend on other tables");
|
||||
|
||||
auto unconditionally() const -> dynamic_join_t<dynamic_pre_join_t, on_t<unconditional_t>>
|
||||
{
|
||||
return {*this, {}};
|
||||
}
|
||||
|
||||
template <typename Expr>
|
||||
auto on(Expr expr) const -> typename std::conditional<check_dynamic_join_on_t<dynamic_pre_join_t, Expr>::value,
|
||||
dynamic_join_t<dynamic_pre_join_t, on_t<Expr>>,
|
||||
|
||||
@@ -29,11 +29,11 @@
|
||||
|
||||
#include <sqlpp11/alias.h>
|
||||
#include <sqlpp11/data_types/boolean.h>
|
||||
#include <sqlpp11/tvin.h>
|
||||
#include <sqlpp11/rhs_wrap.h>
|
||||
#include <sqlpp11/noop.h>
|
||||
#include <sqlpp11/expression_fwd.h>
|
||||
#include <sqlpp11/noop.h>
|
||||
#include <sqlpp11/rhs_wrap.h>
|
||||
#include <sqlpp11/serializer.h>
|
||||
#include <sqlpp11/tvin.h>
|
||||
#include <sqlpp11/wrap_operand.h>
|
||||
|
||||
namespace sqlpp
|
||||
@@ -126,7 +126,7 @@ namespace sqlpp
|
||||
}
|
||||
else
|
||||
{
|
||||
context << "!=";
|
||||
context << "<>";
|
||||
serialize_operand(t._rhs, context);
|
||||
}
|
||||
context << ")";
|
||||
|
||||
@@ -264,7 +264,7 @@ namespace sqlpp
|
||||
return _having_impl<_database_t>(Check{}, expression);
|
||||
}
|
||||
|
||||
auto dynamic_having() const -> _new_statement_t<check_where_dynamic_t<_database_t, boolean_operand>,
|
||||
auto dynamic_having() const -> _new_statement_t<check_having_dynamic_t<_database_t, boolean_operand>,
|
||||
having_t<_database_t, boolean_operand>>
|
||||
{
|
||||
return dynamic_having(::sqlpp::value(true));
|
||||
|
||||
@@ -153,7 +153,8 @@ namespace sqlpp
|
||||
{
|
||||
// FIXME: Make sure that Limit does not require external tables? Need to read up on SQL
|
||||
using arg_t = wrap_operand_t<Limit>;
|
||||
static_assert(is_integral_t<arg_t>::value, "limit requires an integral value or integral parameter");
|
||||
static_assert(is_unsigned_integral_t<arg_t>::value,
|
||||
"limit requires an unsigned integral value or unsigned integral parameter");
|
||||
_data._value = arg_t{value};
|
||||
_data._initialized = true;
|
||||
}
|
||||
@@ -194,11 +195,13 @@ namespace sqlpp
|
||||
};
|
||||
};
|
||||
|
||||
SQLPP_PORTABLE_STATIC_ASSERT(assert_limit_is_integral, "argument for limit() must be an integral expressions");
|
||||
SQLPP_PORTABLE_STATIC_ASSERT(assert_limit_is_unsigned_integral,
|
||||
"argument for limit() must be an unsigned integral expressions");
|
||||
template <typename T>
|
||||
struct check_limit
|
||||
{
|
||||
using type = static_combined_check_t<static_check_t<is_integral_t<T>::value, assert_limit_is_integral>>;
|
||||
using type =
|
||||
static_combined_check_t<static_check_t<is_unsigned_integral_t<T>::value, assert_limit_is_unsigned_integral>>;
|
||||
};
|
||||
template <typename T>
|
||||
using check_limit_t = typename check_limit<wrap_operand_t<T>>::type;
|
||||
|
||||
@@ -57,8 +57,6 @@ namespace sqlpp
|
||||
using _traits = make_traits<no_value_t, tag::is_offset>;
|
||||
using _nodes = detail::type_vector<Offset>;
|
||||
|
||||
static_assert(is_integral_t<Offset>::value, "offset requires an integral value or integral parameter");
|
||||
|
||||
// Data
|
||||
using _data_t = offset_data_t<Offset>;
|
||||
|
||||
@@ -155,7 +153,8 @@ namespace sqlpp
|
||||
{
|
||||
// FIXME: Make sure that Offset does not require external tables? Need to read up on SQL
|
||||
using arg_t = wrap_operand_t<Offset>;
|
||||
static_assert(is_integral_t<arg_t>::value, "offset requires an integral value or integral parameter");
|
||||
static_assert(is_unsigned_integral_t<arg_t>::value,
|
||||
"offset requires an unsigned integral value or unsigned integral parameter");
|
||||
_data._value = arg_t{value};
|
||||
_data._initialized = true;
|
||||
}
|
||||
@@ -208,11 +207,13 @@ namespace sqlpp
|
||||
interpretable_t<Database> _value;
|
||||
};
|
||||
|
||||
SQLPP_PORTABLE_STATIC_ASSERT(assert_offset_is_integral, "argument for offset() must be an integral expressions");
|
||||
SQLPP_PORTABLE_STATIC_ASSERT(assert_offset_is_unsigned_integral,
|
||||
"argument for offset() must be an integral expressions");
|
||||
template <typename T>
|
||||
struct check_offset
|
||||
{
|
||||
using type = static_combined_check_t<static_check_t<is_integral_t<T>::value, assert_offset_is_integral>>;
|
||||
using type =
|
||||
static_combined_check_t<static_check_t<is_unsigned_integral_t<T>::value, assert_offset_is_unsigned_integral>>;
|
||||
};
|
||||
template <typename T>
|
||||
using check_offset_t = typename check_offset<wrap_operand_t<T>>::type;
|
||||
|
||||
@@ -102,6 +102,11 @@ namespace sqlpp
|
||||
|
||||
static_assert(required_tables_of<pre_join_t>::size::value == 0, "joined tables must not depend on other tables");
|
||||
|
||||
auto unconditionally() -> join_t<pre_join_t, on_t<unconditional_t>>
|
||||
{
|
||||
return {*this, {}};
|
||||
}
|
||||
|
||||
template <typename Expr>
|
||||
auto on(Expr expr) const -> typename std::conditional<check_join_on_t<pre_join_t, Expr>::value,
|
||||
join_t<pre_join_t, on_t<Expr>>,
|
||||
|
||||
@@ -55,7 +55,10 @@ namespace sqlpp
|
||||
struct select_pseudo_table_t
|
||||
: public table_t<select_pseudo_table_t<Select, NamedExpr...>, select_column_spec_t<Select, NamedExpr>...>
|
||||
{
|
||||
using _traits = make_traits<no_value_t, tag::is_table, tag::is_pseudo_table>;
|
||||
using _traits = make_traits<no_value_t,
|
||||
tag::is_table,
|
||||
tag::is_pseudo_table,
|
||||
tag_if<tag::requires_braces, requires_braces_t<Select>::value>>;
|
||||
using _nodes = detail::type_vector<>;
|
||||
|
||||
select_pseudo_table_t(Select select) : _select(select)
|
||||
|
||||
@@ -27,12 +27,12 @@
|
||||
#ifndef SQLPP_TABLE_ALIAS_H
|
||||
#define SQLPP_TABLE_ALIAS_H
|
||||
|
||||
#include <sqlpp11/column_fwd.h>
|
||||
#include <sqlpp11/interpret.h>
|
||||
#include <sqlpp11/type_traits.h>
|
||||
#include <sqlpp11/join.h>
|
||||
#include <sqlpp11/alias.h>
|
||||
#include <sqlpp11/column_fwd.h>
|
||||
#include <sqlpp11/detail/type_set.h>
|
||||
#include <sqlpp11/interpret.h>
|
||||
#include <sqlpp11/join.h>
|
||||
#include <sqlpp11/type_traits.h>
|
||||
|
||||
namespace sqlpp
|
||||
{
|
||||
@@ -107,10 +107,10 @@ namespace sqlpp
|
||||
|
||||
static Context& _(const T& t, Context& context)
|
||||
{
|
||||
if (requires_braces_t<T>::value)
|
||||
if (requires_braces_t<Table>::value)
|
||||
context << "(";
|
||||
serialize(t._table, context);
|
||||
if (requires_braces_t<T>::value)
|
||||
if (requires_braces_t<Table>::value)
|
||||
context << ")";
|
||||
context << " AS " << name_of<T>::char_ptr();
|
||||
return context;
|
||||
|
||||
@@ -209,16 +209,17 @@ namespace sqlpp
|
||||
};
|
||||
};
|
||||
|
||||
SQLPP_PORTABLE_STATIC_ASSERT(assert_where_t, "calling where() or unconditionally() required");
|
||||
SQLPP_PORTABLE_STATIC_ASSERT(assert_where_or_unconditionally_called_t,
|
||||
"calling where() or unconditionally() required");
|
||||
|
||||
SQLPP_PORTABLE_STATIC_ASSERT(assert_where_not_cpp_bool_t,
|
||||
SQLPP_PORTABLE_STATIC_ASSERT(assert_where_arg_is_not_cpp_bool_t,
|
||||
"where() argument has to be an sqlpp boolean expression. Please use "
|
||||
".unconditionally() instead of .where(true), or sqlpp::value(bool)");
|
||||
SQLPP_PORTABLE_STATIC_ASSERT(assert_where_boolean_expression_t,
|
||||
SQLPP_PORTABLE_STATIC_ASSERT(assert_where_arg_is_boolean_expression_t,
|
||||
"where() argument has to be an sqlpp boolean expression.");
|
||||
SQLPP_PORTABLE_STATIC_ASSERT(assert_where_no_aggregate_functions_t,
|
||||
SQLPP_PORTABLE_STATIC_ASSERT(assert_where_arg_contains_no_aggregate_functions_t,
|
||||
"at least one aggregate function used in where()");
|
||||
SQLPP_PORTABLE_STATIC_ASSERT(assert_where_dynamic_statement_dynamic_t,
|
||||
SQLPP_PORTABLE_STATIC_ASSERT(assert_where_dynamic_used_with_dynamic_statement_t,
|
||||
"dynamic_where() must not be called in a static statement");
|
||||
|
||||
// workaround for msvc bugs https://connect.microsoft.com/VisualStudio/Feedback/Details/2086629 &
|
||||
@@ -226,20 +227,22 @@ namespace sqlpp
|
||||
// template <typename... Expressions>
|
||||
// using check_where_t = static_combined_check_t<
|
||||
// static_check_t<logic::all_t<is_not_cpp_bool_t<Expressions>::value...>::value,
|
||||
// assert_where_not_cpp_bool_t>,
|
||||
// assert_where_arg_is_not_cpp_bool_t>,
|
||||
// static_check_t<logic::all_t<is_expression_t<Expressions>::value...>::value,
|
||||
// assert_where_boolean_expressions_t>,
|
||||
// static_check_t<logic::all_t<is_boolean_t<Expressions>::value...>::value, assert_where_boolean_expression_t>,
|
||||
// static_check_t<logic::all_t<is_boolean_t<Expressions>::value...>::value,
|
||||
// assert_where_arg_is_boolean_expression_t>,
|
||||
// static_check_t<logic::all_t<(not contains_aggregate_function_t<Expressions>::value)...>::value,
|
||||
// assert_where_no_aggregate_functions_t>>;
|
||||
// assert_where_arg_contains_no_aggregate_functions_t>>;
|
||||
template <typename Expression>
|
||||
struct check_where
|
||||
{
|
||||
using type = static_combined_check_t<
|
||||
static_check_t<is_not_cpp_bool_t<Expression>::value, assert_where_not_cpp_bool_t>,
|
||||
static_check_t<is_expression_t<Expression>::value, assert_where_boolean_expression_t>,
|
||||
static_check_t<is_boolean_t<Expression>::value, assert_where_boolean_expression_t>,
|
||||
static_check_t<not contains_aggregate_function_t<Expression>::value, assert_where_no_aggregate_functions_t>>;
|
||||
static_check_t<is_not_cpp_bool_t<Expression>::value, assert_where_arg_is_not_cpp_bool_t>,
|
||||
static_check_t<is_expression_t<Expression>::value, assert_where_arg_is_boolean_expression_t>,
|
||||
static_check_t<is_boolean_t<Expression>::value, assert_where_arg_is_boolean_expression_t>,
|
||||
static_check_t<not contains_aggregate_function_t<Expression>::value,
|
||||
assert_where_arg_contains_no_aggregate_functions_t>>;
|
||||
};
|
||||
|
||||
template <typename Expression>
|
||||
@@ -250,7 +253,7 @@ namespace sqlpp
|
||||
|
||||
template <typename Database, typename Expression>
|
||||
using check_where_dynamic_t = static_combined_check_t<
|
||||
static_check_t<not std::is_same<Database, void>::value, assert_where_dynamic_statement_dynamic_t>,
|
||||
static_check_t<not std::is_same<Database, void>::value, assert_where_dynamic_used_with_dynamic_statement_t>,
|
||||
check_where_t<Expression>>;
|
||||
|
||||
// NO WHERE YET
|
||||
@@ -311,7 +314,7 @@ namespace sqlpp
|
||||
|
||||
using _consistency_check =
|
||||
typename std::conditional<WhereRequired and (Policies::_all_provided_tables::size::value > 0),
|
||||
assert_where_t,
|
||||
assert_where_or_unconditionally_called_t,
|
||||
consistent_t>::type;
|
||||
|
||||
auto unconditionally() const -> _new_statement_t<consistent_t, where_t<void, unconditional_t>>
|
||||
|
||||
@@ -28,6 +28,7 @@ set(test_serializer_names
|
||||
In
|
||||
Insert
|
||||
Where
|
||||
TableAlias
|
||||
)
|
||||
|
||||
create_test_sourcelist(test_serializer_sources test_serializer_main.cpp ${test_serializer_names})
|
||||
|
||||
@@ -46,7 +46,7 @@ int CustomQuery(int, char* [])
|
||||
compare(__LINE__,
|
||||
custom_query(sqlpp::select(), select_flags(sqlpp::distinct), select_columns(foo.omega),
|
||||
from(foo.join(bar).on(foo.omega == bar.alpha)), where(bar.alpha > 17), group_by(foo.omega),
|
||||
having(avg(bar.alpha) > 19), order_by(foo.omega.asc()), sqlpp::limit(10), sqlpp::offset(100)),
|
||||
having(avg(bar.alpha) > 19), order_by(foo.omega.asc()), sqlpp::limit(10u), sqlpp::offset(100u)),
|
||||
"SELECT DISTINCT tab_foo.omega FROM tab_foo INNER JOIN tab_bar ON (tab_foo.omega=tab_bar.alpha) WHERE "
|
||||
"(tab_bar.alpha>17) GROUP BY tab_foo.omega HAVING (AVG(tab_bar.alpha)>19) ORDER BY tab_foo.omega ASC "
|
||||
"LIMIT 10 OFFSET 100");
|
||||
|
||||
@@ -23,8 +23,8 @@
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "compare.h"
|
||||
#include "Sample.h"
|
||||
#include "compare.h"
|
||||
#include <sqlpp11/sqlpp11.h>
|
||||
|
||||
namespace
|
||||
@@ -61,6 +61,7 @@ int From(int, char* [])
|
||||
compare(
|
||||
__LINE__, from(aFoo.join(bFoo).on(aFoo.omega > bFoo.omega).join(cFoo).on(bFoo.omega > cFoo.omega)),
|
||||
" FROM tab_foo AS a INNER JOIN tab_foo AS b ON (a.omega>b.omega) INNER JOIN tab_foo AS c ON (b.omega>c.omega)");
|
||||
compare(__LINE__, from(foo.join(bar).unconditionally()), " FROM tab_foo INNER JOIN tab_bar");
|
||||
|
||||
// Static joins involving verbatim tables
|
||||
compare(__LINE__, from(aFoo.join(sqlpp::verbatim_table("unknown_table"))
|
||||
@@ -109,6 +110,11 @@ int From(int, char* [])
|
||||
dfa.from.add(dynamic_right_outer_join(bar).on(bar.alpha > foo.omega));
|
||||
compare(__LINE__, dfa, " FROM tab_foo RIGHT OUTER JOIN tab_bar ON (tab_bar.alpha>tab_foo.omega)");
|
||||
}
|
||||
{
|
||||
auto dfa = df;
|
||||
dfa.from.add(dynamic_join(bar).unconditionally());
|
||||
compare(__LINE__, dfa, " FROM tab_foo INNER JOIN tab_bar");
|
||||
}
|
||||
{
|
||||
auto dfa = df;
|
||||
dfa.from.add(dynamic_inner_join(bar).on(bar.alpha > foo.omega));
|
||||
|
||||
43
test_serializer/TableAlias.cpp
Normal file
43
test_serializer/TableAlias.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (c) 2016-2016, 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.
|
||||
*/
|
||||
|
||||
#include "Sample.h"
|
||||
#include "compare.h"
|
||||
#include <sqlpp11/sqlpp11.h>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
int TableAlias(int, char* [])
|
||||
{
|
||||
const auto foo = test::TabFoo{};
|
||||
const auto bar = test::TabBar{};
|
||||
|
||||
// Individual values
|
||||
compare(__LINE__, foo.as(bar), "tab_foo AS tab_bar");
|
||||
compare(__LINE__, select(foo.omega).from(foo).unconditionally().as(bar),
|
||||
"(SELECT tab_foo.omega FROM tab_foo) AS tab_bar");
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -138,7 +138,7 @@ namespace
|
||||
static_assert(ExpectedCheckResult::value, "Unexpected check result");
|
||||
|
||||
using ReturnType = decltype(select(all_of(t)).from(t).dynamic_having());
|
||||
using ExpectedReturnType = std::is_same<ReturnType, sqlpp::assert_where_dynamic_statement_dynamic_t>;
|
||||
using ExpectedReturnType = std::is_same<ReturnType, sqlpp::assert_having_dynamic_statement_dynamic_t>;
|
||||
print_type_on_error<ReturnType>(ExpectedReturnType{});
|
||||
static_assert(ExpectedReturnType::value, "Unexpected return type");
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ namespace
|
||||
void where()
|
||||
{
|
||||
where_check<sqlpp::consistent_t>(t.gamma);
|
||||
where_check<sqlpp::assert_where_not_cpp_bool_t>(true);
|
||||
where_check<sqlpp::assert_where_arg_is_not_cpp_bool_t>(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -79,26 +79,26 @@ namespace
|
||||
where_static_check<sqlpp::consistent_t>(t.gamma == true);
|
||||
|
||||
// Try assignment as condition
|
||||
where_static_check<sqlpp::assert_where_boolean_expression_t>(t.gamma = true);
|
||||
where_static_check<sqlpp::assert_where_arg_is_boolean_expression_t>(t.gamma = true);
|
||||
|
||||
// Try non-boolean expression
|
||||
where_static_check<sqlpp::assert_where_boolean_expression_t>(t.alpha);
|
||||
where_static_check<sqlpp::assert_where_arg_is_boolean_expression_t>(t.alpha);
|
||||
|
||||
// Try builtin bool
|
||||
where_static_check<sqlpp::assert_where_not_cpp_bool_t>(true);
|
||||
where_static_check<sqlpp::assert_where_not_cpp_bool_t>(17 > 3);
|
||||
where_static_check<sqlpp::assert_where_arg_is_not_cpp_bool_t>(true);
|
||||
where_static_check<sqlpp::assert_where_arg_is_not_cpp_bool_t>(17 > 3);
|
||||
|
||||
// Try some other types as expressions
|
||||
where_static_check<sqlpp::assert_where_boolean_expression_t>("true");
|
||||
where_static_check<sqlpp::assert_where_boolean_expression_t>(17);
|
||||
where_static_check<sqlpp::assert_where_boolean_expression_t>('c');
|
||||
where_static_check<sqlpp::assert_where_boolean_expression_t>(nullptr);
|
||||
where_static_check<sqlpp::assert_where_boolean_expression_t>(t.alpha.as(t.beta));
|
||||
where_static_check<sqlpp::assert_where_arg_is_boolean_expression_t>("true");
|
||||
where_static_check<sqlpp::assert_where_arg_is_boolean_expression_t>(17);
|
||||
where_static_check<sqlpp::assert_where_arg_is_boolean_expression_t>('c');
|
||||
where_static_check<sqlpp::assert_where_arg_is_boolean_expression_t>(nullptr);
|
||||
where_static_check<sqlpp::assert_where_arg_is_boolean_expression_t>(t.alpha.as(t.beta));
|
||||
|
||||
// Try using aggregate functions in where
|
||||
where_static_check<sqlpp::assert_where_no_aggregate_functions_t>(count(t.alpha) > 0);
|
||||
where_static_check<sqlpp::assert_where_no_aggregate_functions_t>(t.gamma and count(t.alpha) > 0);
|
||||
where_static_check<sqlpp::assert_where_no_aggregate_functions_t>(
|
||||
where_static_check<sqlpp::assert_where_arg_contains_no_aggregate_functions_t>(count(t.alpha) > 0);
|
||||
where_static_check<sqlpp::assert_where_arg_contains_no_aggregate_functions_t>(t.gamma and count(t.alpha) > 0);
|
||||
where_static_check<sqlpp::assert_where_arg_contains_no_aggregate_functions_t>(
|
||||
case_when(count(t.alpha) > 0).then(t.gamma).else_(not t.gamma));
|
||||
}
|
||||
|
||||
@@ -109,36 +109,36 @@ namespace
|
||||
where_dynamic_check<sqlpp::consistent_t>(t.gamma == true);
|
||||
|
||||
// Try assignment as condition
|
||||
where_dynamic_check<sqlpp::assert_where_boolean_expression_t>(t.gamma = true);
|
||||
where_dynamic_check<sqlpp::assert_where_arg_is_boolean_expression_t>(t.gamma = true);
|
||||
|
||||
// Try non-boolean expression
|
||||
where_dynamic_check<sqlpp::assert_where_boolean_expression_t>(t.alpha);
|
||||
where_dynamic_check<sqlpp::assert_where_arg_is_boolean_expression_t>(t.alpha);
|
||||
|
||||
// Try builtin bool
|
||||
where_dynamic_check<sqlpp::assert_where_not_cpp_bool_t>(true);
|
||||
where_dynamic_check<sqlpp::assert_where_not_cpp_bool_t>(17 > 3);
|
||||
where_dynamic_check<sqlpp::assert_where_arg_is_not_cpp_bool_t>(true);
|
||||
where_dynamic_check<sqlpp::assert_where_arg_is_not_cpp_bool_t>(17 > 3);
|
||||
|
||||
// Try some other types as expressions
|
||||
where_dynamic_check<sqlpp::assert_where_boolean_expression_t>("true");
|
||||
where_dynamic_check<sqlpp::assert_where_boolean_expression_t>(17);
|
||||
where_dynamic_check<sqlpp::assert_where_boolean_expression_t>('c');
|
||||
where_dynamic_check<sqlpp::assert_where_boolean_expression_t>(nullptr);
|
||||
where_dynamic_check<sqlpp::assert_where_boolean_expression_t>(t.alpha.as(t.beta));
|
||||
where_dynamic_check<sqlpp::assert_where_arg_is_boolean_expression_t>("true");
|
||||
where_dynamic_check<sqlpp::assert_where_arg_is_boolean_expression_t>(17);
|
||||
where_dynamic_check<sqlpp::assert_where_arg_is_boolean_expression_t>('c');
|
||||
where_dynamic_check<sqlpp::assert_where_arg_is_boolean_expression_t>(nullptr);
|
||||
where_dynamic_check<sqlpp::assert_where_arg_is_boolean_expression_t>(t.alpha.as(t.beta));
|
||||
|
||||
// Try using aggregate functions in where
|
||||
where_dynamic_check<sqlpp::assert_where_no_aggregate_functions_t>(count(t.alpha) > 0);
|
||||
where_dynamic_check<sqlpp::assert_where_no_aggregate_functions_t>(t.gamma and count(t.alpha) > 0);
|
||||
where_dynamic_check<sqlpp::assert_where_no_aggregate_functions_t>(
|
||||
where_dynamic_check<sqlpp::assert_where_arg_contains_no_aggregate_functions_t>(count(t.alpha) > 0);
|
||||
where_dynamic_check<sqlpp::assert_where_arg_contains_no_aggregate_functions_t>(t.gamma and count(t.alpha) > 0);
|
||||
where_dynamic_check<sqlpp::assert_where_arg_contains_no_aggregate_functions_t>(
|
||||
case_when(count(t.alpha) > 0).then(t.gamma).else_(not t.gamma));
|
||||
|
||||
// Try dynamic_where on a non-dynamic remove
|
||||
using CheckResult = sqlpp::check_where_dynamic_t<void, sqlpp::boolean_operand>;
|
||||
using ExpectedCheckResult = std::is_same<CheckResult, sqlpp::assert_where_dynamic_statement_dynamic_t>;
|
||||
using ExpectedCheckResult = std::is_same<CheckResult, sqlpp::assert_where_dynamic_used_with_dynamic_statement_t>;
|
||||
print_type_on_error<CheckResult>(ExpectedCheckResult{});
|
||||
static_assert(ExpectedCheckResult::value, "Unexpected check result");
|
||||
|
||||
using ReturnType = decltype(remove_from(t).dynamic_where());
|
||||
using ExpectedReturnType = std::is_same<ReturnType, sqlpp::assert_where_dynamic_statement_dynamic_t>;
|
||||
using ExpectedReturnType = std::is_same<ReturnType, sqlpp::assert_where_dynamic_used_with_dynamic_statement_t>;
|
||||
print_type_on_error<ReturnType>(ExpectedReturnType{});
|
||||
static_assert(ExpectedReturnType::value, "Unexpected return type");
|
||||
}
|
||||
|
||||
@@ -23,8 +23,8 @@
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "Sample.h"
|
||||
#include "MockDb.h"
|
||||
#include "Sample.h"
|
||||
#include <sqlpp11/sqlpp11.h>
|
||||
|
||||
#include <iostream>
|
||||
@@ -74,23 +74,26 @@ int Interpret(int, char* [])
|
||||
serialize(select(t.alpha, t.beta).from(t).where(t.alpha == 3), printer).str();
|
||||
serialize(select(t.alpha, t.beta).from(t).where(t.alpha == 3).group_by(t.gamma), printer).str();
|
||||
serialize(select(t.alpha, t.beta).from(t).where(t.alpha == 3).group_by(t.gamma).having(t.beta.like("%kuchen")),
|
||||
printer).str();
|
||||
printer)
|
||||
.str();
|
||||
serialize(select(t.alpha, t.beta)
|
||||
.from(t)
|
||||
.where(t.alpha == 3)
|
||||
.group_by(t.gamma)
|
||||
.having(t.beta.like("%kuchen"))
|
||||
.order_by(t.beta.asc()),
|
||||
printer).str();
|
||||
printer)
|
||||
.str();
|
||||
serialize(select(t.alpha, t.beta)
|
||||
.from(t)
|
||||
.where(t.alpha == 3)
|
||||
.group_by(t.gamma)
|
||||
.having(t.beta.like("%kuchen"))
|
||||
.order_by(t.beta.asc())
|
||||
.limit(17)
|
||||
.offset(3),
|
||||
printer).str();
|
||||
.limit(17u)
|
||||
.offset(3u),
|
||||
printer)
|
||||
.str();
|
||||
|
||||
serialize(parameter(sqlpp::bigint(), t.alpha), printer).str();
|
||||
serialize(parameter(t.alpha), printer).str();
|
||||
@@ -199,7 +202,9 @@ int Interpret(int, char* [])
|
||||
|
||||
printer.reset();
|
||||
std::cerr << serialize(select(all_of(t)).from(t).where(t.alpha.in(select(f.epsilon).from(f).unconditionally())),
|
||||
printer).str() << std::endl;
|
||||
printer)
|
||||
.str()
|
||||
<< std::endl;
|
||||
|
||||
printer.reset();
|
||||
std::cerr << serialize(select(all_of(t)).from(t).where(t.alpha.in()), printer).str() << std::endl;
|
||||
|
||||
@@ -122,8 +122,8 @@ int Select(int, char* [])
|
||||
.group_by(t.alpha)
|
||||
.order_by(t.gamma.asc())
|
||||
.having(t.gamma)
|
||||
.offset(19)
|
||||
.limit(7);
|
||||
.offset(19u)
|
||||
.limit(7u);
|
||||
printer.reset();
|
||||
std::cerr << serialize(stat, printer).str() << std::endl;
|
||||
|
||||
@@ -135,8 +135,8 @@ int Select(int, char* [])
|
||||
.group_by(t.alpha)
|
||||
.order_by(t.gamma.asc())
|
||||
.having(t.gamma)
|
||||
.limit(7)
|
||||
.offset(19);
|
||||
.limit(7u)
|
||||
.offset(19u);
|
||||
|
||||
printer.reset();
|
||||
std::cerr << serialize(s0, printer).str() << std::endl;
|
||||
@@ -156,8 +156,8 @@ int Select(int, char* [])
|
||||
s.from.add(dynamic_cross_join(f));
|
||||
s.where.add(t.alpha > 7);
|
||||
s.having.add(t.alpha > 7);
|
||||
s.limit.set(3);
|
||||
s.offset.set(3);
|
||||
s.limit.set(3u);
|
||||
s.offset.set(3u);
|
||||
s.group_by.add(t.beta);
|
||||
s.order_by.add(t.beta.asc());
|
||||
for (const auto& row : db(s))
|
||||
|
||||
@@ -23,14 +23,14 @@
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include "Sample.h"
|
||||
#include "MockDb.h"
|
||||
#include "Sample.h"
|
||||
#include "is_regular.h"
|
||||
#include <iostream>
|
||||
#include <sqlpp11/alias_provider.h>
|
||||
#include <sqlpp11/select.h>
|
||||
#include <sqlpp11/functions.h>
|
||||
#include <sqlpp11/connection.h>
|
||||
#include <sqlpp11/functions.h>
|
||||
#include <sqlpp11/select.h>
|
||||
#include <sqlpp11/without_table_check.h>
|
||||
|
||||
namespace alias
|
||||
@@ -137,29 +137,38 @@ int SelectType(int, char* [])
|
||||
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");
|
||||
//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");
|
||||
static_assert(sqlpp::is_integral_t<sqlpp::return_type_divides_t<T,sqlpp::integral>>::value, "type requirement");
|
||||
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");
|
||||
static_assert(sqlpp::is_integral_t<sqlpp::return_type_divides_t<sqlpp::integral,T>>::value, "type requirement");
|
||||
static_assert(sqlpp::is_integral_t<sqlpp::return_type_modulus_t<sqlpp::integral,T>>::value, "type requirement");
|
||||
// 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");
|
||||
static_assert(sqlpp::is_integral_t<sqlpp::return_type_divides_t<T, sqlpp::integral>>::value, "type requirement");
|
||||
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");
|
||||
static_assert(sqlpp::is_integral_t<sqlpp::return_type_divides_t<sqlpp::integral, T>>::value, "type requirement");
|
||||
static_assert(sqlpp::is_integral_t<sqlpp::return_type_modulus_t<sqlpp::integral, T>>::value, "type requirement");
|
||||
}
|
||||
|
||||
// Test a floating point table column
|
||||
@@ -370,8 +379,8 @@ int SelectType(int, char* [])
|
||||
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));
|
||||
s.where.add(without_table_check(f.omega > 7 and t.alpha == any(select(t.alpha).from(t).where(t.alpha < 3))));
|
||||
s.limit.set(30);
|
||||
s.limit.set(3);
|
||||
s.limit.set(30u);
|
||||
s.limit.set(3u);
|
||||
std::cerr << "------------------------\n";
|
||||
serialize(s, printer).str();
|
||||
std::cerr << "------------------------\n";
|
||||
@@ -424,8 +433,8 @@ int SelectType(int, char* [])
|
||||
.group_by(l.gamma, r.a)
|
||||
.having(r.a != true)
|
||||
.order_by(l.beta.asc())
|
||||
.limit(17)
|
||||
.offset(3)
|
||||
.limit(17u)
|
||||
.offset(3u)
|
||||
.as(alias::a);
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -23,11 +23,11 @@
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "MockDb.h"
|
||||
#include "Sample.h"
|
||||
#include "is_regular.h"
|
||||
#include <iostream>
|
||||
#include <sqlpp11/sqlpp11.h>
|
||||
#include "Sample.h"
|
||||
#include "MockDb.h"
|
||||
#include "is_regular.h"
|
||||
|
||||
int Update(int, char* [])
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user