mirror of
https://github.com/rbock/sqlpp11.git
synced 2024-11-16 04:47:18 +08:00
Add tests for some value types and for CTE
plus some cleanup, e.g. removing superseded tests
This commit is contained in:
parent
32dee26d1a
commit
8a59fb44a2
@ -77,10 +77,10 @@ namespace sqlpp
|
|||||||
struct provided_optional_tables_of<join_t<Lhs, JoinType, Rhs, Condition>>
|
struct provided_optional_tables_of<join_t<Lhs, JoinType, Rhs, Condition>>
|
||||||
{
|
{
|
||||||
using type = detail::type_vector_cat_t<
|
using type = detail::type_vector_cat_t<
|
||||||
typename std::conditional<detail::type_vector<right_outer_join_t, full_outer_join_t>::contains<JoinType>(),
|
typename std::conditional<detail::type_vector<right_outer_join_t, full_outer_join_t>::contains<JoinType>::value,
|
||||||
provided_tables_of_t<Lhs>,
|
provided_tables_of_t<Lhs>,
|
||||||
detail::type_vector<>>::type,
|
detail::type_vector<>>::type,
|
||||||
typename std::conditional<detail::type_vector<left_outer_join_t, full_outer_join_t>::contains<JoinType>(),
|
typename std::conditional<detail::type_vector<left_outer_join_t, full_outer_join_t>::contains<JoinType>::value,
|
||||||
provided_tables_of_t<Rhs>,
|
provided_tables_of_t<Rhs>,
|
||||||
detail::type_vector<>>::type>;
|
detail::type_vector<>>::type>;
|
||||||
};
|
};
|
||||||
@ -142,9 +142,9 @@ namespace sqlpp
|
|||||||
#warning: Verify that the Expr does not require tables other than Lhs, Rhs
|
#warning: Verify that the Expr does not require tables other than Lhs, Rhs
|
||||||
template <typename Expr, typename StaticTableTypeVector, typename AllTableTypeVector>
|
template <typename Expr, typename StaticTableTypeVector, typename AllTableTypeVector>
|
||||||
struct are_table_requirements_satisfied
|
struct are_table_requirements_satisfied
|
||||||
: std::integral_constant<bool,
|
: public std::integral_constant<bool,
|
||||||
StaticTableTypeVector::contains_all(required_static_tables_of_t<Expr>{}) and
|
StaticTableTypeVector::template contains_all<required_static_tables_of_t<Expr>>::value and
|
||||||
AllTableTypeVector::contains_all(required_tables_of_t<Expr>{})>
|
AllTableTypeVector::template contains_all<required_tables_of_t<Expr>>::value>
|
||||||
{
|
{
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -118,7 +118,7 @@ namespace sqlpp
|
|||||||
template <typename NameTagProvider, typename FieldSpec>
|
template <typename NameTagProvider, typename FieldSpec>
|
||||||
struct cte_base
|
struct cte_base
|
||||||
{
|
{
|
||||||
using type = member_t<cte_column_spec_t<FieldSpec>, column_t<NameTagProvider, cte_column_spec_t<FieldSpec>>>;
|
using type = member_t<FieldSpec, column_t<NameTagProvider, cte_column_spec_t<FieldSpec>>>;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename Check, typename Union>
|
template <typename Check, typename Union>
|
||||||
@ -229,11 +229,8 @@ namespace sqlpp
|
|||||||
template <typename Context, typename NameTagProvider, typename Statement, typename... ColumnSpecs>
|
template <typename Context, typename NameTagProvider, typename Statement, typename... ColumnSpecs>
|
||||||
auto to_sql_string(Context& context, const cte_t<NameTagProvider, Statement, ColumnSpecs...>& t) -> std::string
|
auto to_sql_string(Context& context, const cte_t<NameTagProvider, Statement, ColumnSpecs...>& t) -> std::string
|
||||||
{
|
{
|
||||||
using T = cte_t<NameTagProvider, Statement, ColumnSpecs...>;
|
return name_to_sql_string(context, name_tag_of_t<NameTagProvider>::name) + " AS (" +
|
||||||
context << name_tag_of_t<T>::template char_ptr<Context>() << " AS (";
|
to_sql_string(context, t._statement) + ")";
|
||||||
to_sql_string(context, t._statement);
|
|
||||||
context << ")";
|
|
||||||
return context;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// The cte_t is displayed as NameTagProviderName except within the with:
|
// The cte_t is displayed as NameTagProviderName except within the with:
|
||||||
@ -250,7 +247,7 @@ namespace sqlpp
|
|||||||
template <typename Statement>
|
template <typename Statement>
|
||||||
auto as(Statement statement) -> make_cte_t<NameTagProvider, Statement>
|
auto as(Statement statement) -> make_cte_t<NameTagProvider, Statement>
|
||||||
{
|
{
|
||||||
static_assert(required_tables_of_t<Statement>::size::value == 0,
|
static_assert(required_tables_of_t<Statement>::empty(),
|
||||||
"common table expression must not use unknown tables");
|
"common table expression must not use unknown tables");
|
||||||
static_assert(not required_ctes_of<Statement>::template count<NameTagProvider>(),
|
static_assert(not required_ctes_of<Statement>::template count<NameTagProvider>(),
|
||||||
"common table expression must not self-reference in the first part, use union_all/union_distinct "
|
"common table expression must not self-reference in the first part, use union_all/union_distinct "
|
||||||
@ -270,12 +267,11 @@ namespace sqlpp
|
|||||||
template <typename Context, typename NameTagProvider>
|
template <typename Context, typename NameTagProvider>
|
||||||
auto to_sql_string(Context& context, const cte_ref_t<NameTagProvider>&) -> std::string
|
auto to_sql_string(Context& context, const cte_ref_t<NameTagProvider>&) -> std::string
|
||||||
{
|
{
|
||||||
context << name_tag_of_t<cte_ref_t<NameTagProvider>>::template char_ptr<Context>();
|
return name_to_sql_string(context, name_tag_of_t<NameTagProvider>::name);
|
||||||
return context;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename NameTagProvider>
|
template <typename NameTagProvider>
|
||||||
auto cte(const NameTagProvider & /*unused*/) -> cte_ref_t<NameTagProvider>
|
auto cte(const NameTagProvider& /*unused*/) -> cte_ref_t<NameTagProvider>
|
||||||
{
|
{
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
@ -80,7 +80,7 @@ namespace sqlpp
|
|||||||
{
|
{
|
||||||
#warning: document that limits can be integral (not just unsigned integral)
|
#warning: document that limits can be integral (not just unsigned integral)
|
||||||
using type =
|
using type =
|
||||||
static_combined_check_t<static_check_t<is_integral<T>::value, assert_limit_is_integral>>;
|
static_combined_check_t<static_check_t<is_integral<T>::value or is_unsigned_integral<T>::value, assert_limit_is_integral>>;
|
||||||
};
|
};
|
||||||
template <typename T>
|
template <typename T>
|
||||||
using check_limit_t = typename check_limit<remove_dynamic_t<T>>::type;
|
using check_limit_t = typename check_limit<remove_dynamic_t<T>>::type;
|
||||||
|
@ -78,7 +78,7 @@ namespace sqlpp
|
|||||||
struct check_offset
|
struct check_offset
|
||||||
{
|
{
|
||||||
using type =
|
using type =
|
||||||
static_combined_check_t<static_check_t<is_integral<T>::value, assert_offset_is_integral>>;
|
static_combined_check_t<static_check_t<is_integral<T>::value or is_unsigned_integral<T>::value, assert_offset_is_integral>>;
|
||||||
};
|
};
|
||||||
template <typename T>
|
template <typename T>
|
||||||
using check_offset_t = typename check_offset<remove_dynamic_t<T>>::type;
|
using check_offset_t = typename check_offset<remove_dynamic_t<T>>::type;
|
||||||
|
@ -137,11 +137,7 @@ namespace sqlpp
|
|||||||
template <typename Context, typename... Flags>
|
template <typename Context, typename... Flags>
|
||||||
auto to_sql_string(Context& context, const select_flag_list_data_t<Flags...>& t) -> std::string
|
auto to_sql_string(Context& context, const select_flag_list_data_t<Flags...>& t) -> std::string
|
||||||
{
|
{
|
||||||
auto flags = tuple_to_sql_string(context, t._flags, tuple_operand_no_dynamic{" "});
|
return tuple_to_sql_string(context, t._flags, tuple_operand_no_dynamic{""});
|
||||||
if (flags.empty()) {
|
|
||||||
return flags;
|
|
||||||
}
|
|
||||||
return flags + " ";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename... T>
|
template <typename... T>
|
||||||
|
@ -45,7 +45,7 @@ namespace sqlpp
|
|||||||
template <typename Context>
|
template <typename Context>
|
||||||
auto to_sql_string(Context& , const all_t&) -> std::string
|
auto to_sql_string(Context& , const all_t&) -> std::string
|
||||||
{
|
{
|
||||||
return "ALL";
|
return "ALL ";
|
||||||
}
|
}
|
||||||
|
|
||||||
struct distinct_t
|
struct distinct_t
|
||||||
@ -59,7 +59,7 @@ namespace sqlpp
|
|||||||
template <typename Context>
|
template <typename Context>
|
||||||
auto to_sql_string(Context& , const distinct_t&) -> std::string
|
auto to_sql_string(Context& , const distinct_t&) -> std::string
|
||||||
{
|
{
|
||||||
return "DISTINCT";
|
return "DISTINCT ";
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace sqlpp
|
} // namespace sqlpp
|
||||||
|
@ -76,27 +76,32 @@ namespace sqlpp
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename X>
|
template <typename X>
|
||||||
static constexpr bool contains()
|
struct contains : public ::sqlpp::logic::any<std::is_same<T, X>::value...> {
|
||||||
{
|
};
|
||||||
return ::sqlpp::logic::any<std::is_same<T, X>::value...>::value;
|
|
||||||
}
|
template <typename X>
|
||||||
|
struct contains_not : public ::sqlpp::logic::none<std::is_same<T, X>::value...> {
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename TypeVector>
|
||||||
|
struct contains_all;
|
||||||
|
|
||||||
template <typename... X>
|
template <typename... X>
|
||||||
static constexpr bool contains_all(type_vector<X...>)
|
struct contains_all<type_vector<X...>> : public ::sqlpp::logic::all<contains<X>::value...>
|
||||||
{
|
{
|
||||||
return ::sqlpp::logic::all<contains<X>()...>::value;
|
};
|
||||||
}
|
|
||||||
|
|
||||||
|
#warning turn into structs
|
||||||
template <typename... X>
|
template <typename... X>
|
||||||
static constexpr bool contains_any(type_vector<X...>)
|
static constexpr bool contains_any(type_vector<X...>)
|
||||||
{
|
{
|
||||||
return ::sqlpp::logic::any<contains<X>()...>::value;
|
return ::sqlpp::logic::any<contains<X>::value...>::value;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename... X>
|
template <typename... X>
|
||||||
static constexpr bool contains_none(type_vector<X...>)
|
static constexpr bool contains_none(type_vector<X...>)
|
||||||
{
|
{
|
||||||
return ::sqlpp::logic::none<contains<X>()...>::value;
|
return ::sqlpp::logic::none<contains<X>::value...>::value;
|
||||||
}
|
}
|
||||||
|
|
||||||
static constexpr size_t size()
|
static constexpr size_t size()
|
||||||
@ -155,5 +160,18 @@ namespace sqlpp
|
|||||||
template <typename TypeVector, template <typename> class Transform>
|
template <typename TypeVector, template <typename> class Transform>
|
||||||
using transform_t = typename transform<TypeVector, Transform>::type;
|
using transform_t = typename transform<TypeVector, Transform>::type;
|
||||||
|
|
||||||
|
template <typename TypeVector, template <typename> class Predicate>
|
||||||
|
struct copy_if;
|
||||||
|
|
||||||
|
template <template <typename> class Predicate, typename... T>
|
||||||
|
struct copy_if<type_vector<T...>, Predicate>
|
||||||
|
{
|
||||||
|
using type =
|
||||||
|
type_vector_cat_t<typename std::conditional<Predicate<T>::value, type_vector<T>, type_vector<>>::type...>;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename TypeVector, template <typename> class Predicate>
|
||||||
|
using copy_if_t = typename copy_if<TypeVector, Predicate>::type;
|
||||||
|
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
} // namespace sqlpp
|
} // namespace sqlpp
|
||||||
|
@ -79,7 +79,7 @@ namespace sqlpp
|
|||||||
{
|
{
|
||||||
using ValueType = select_column_value_type_of_t<NamedExpr>;
|
using ValueType = select_column_value_type_of_t<NamedExpr>;
|
||||||
static constexpr bool _depends_on_optional_table =
|
static constexpr bool _depends_on_optional_table =
|
||||||
Select::_used_optional_tables::contains_any(required_tables_of_t<NamedExpr>{});
|
Select::_provided_optional_tables::contains_any(required_tables_of_t<NamedExpr>{});
|
||||||
|
|
||||||
using type = field_spec_t<
|
using type = field_spec_t<
|
||||||
select_column_name_tag_of_t<NamedExpr>,
|
select_column_name_tag_of_t<NamedExpr>,
|
||||||
|
@ -82,8 +82,10 @@ namespace sqlpp
|
|||||||
using _all_provided_optional_tables = detail::type_vector_cat_t<provided_optional_tables_of_t<Policies>...>;
|
using _all_provided_optional_tables = detail::type_vector_cat_t<provided_optional_tables_of_t<Policies>...>;
|
||||||
using _all_provided_aggregates = detail::make_joined_set_t<provided_aggregates_of<Policies>...>;
|
using _all_provided_aggregates = detail::make_joined_set_t<provided_aggregates_of<Policies>...>;
|
||||||
|
|
||||||
|
using _required_tables_of = detail::copy_if_t<_all_required_tables, _all_provided_tables::template contains_not>;
|
||||||
|
|
||||||
template <typename Expression>
|
template <typename Expression>
|
||||||
static constexpr bool _no_unknown_tables = _all_provided_tables::contains_all(required_tables_of_t<Expression>{});
|
static constexpr bool _no_unknown_tables = _all_provided_tables::template contains_all<required_tables_of_t<Expression>>::value;
|
||||||
|
|
||||||
// workaround for msvc bug https://connect.microsoft.com/VisualStudio/Feedback/Details/2086629
|
// workaround for msvc bug https://connect.microsoft.com/VisualStudio/Feedback/Details/2086629
|
||||||
// template <typename... Expressions>
|
// template <typename... Expressions>
|
||||||
@ -208,8 +210,7 @@ namespace sqlpp
|
|||||||
>;
|
>;
|
||||||
using _name_tag_of = name_tag_of<_result_type_provider>;
|
using _name_tag_of = name_tag_of<_result_type_provider>;
|
||||||
using _nodes = detail::type_vector<_policies_t>;
|
using _nodes = detail::type_vector<_policies_t>;
|
||||||
#warning: This is an odd name, why "used"?
|
using _provided_optional_tables = typename _policies_t::_all_provided_optional_tables;
|
||||||
using _used_optional_tables = typename _policies_t::_all_provided_optional_tables;
|
|
||||||
|
|
||||||
// Constructors
|
// Constructors
|
||||||
statement_t() = default;
|
statement_t() = default;
|
||||||
@ -275,6 +276,12 @@ namespace sqlpp
|
|||||||
using type = typename detail::type_vector<Policies...>;
|
using type = typename detail::type_vector<Policies...>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <typename... Policies>
|
||||||
|
struct required_tables_of<statement_t<Policies...>>
|
||||||
|
{
|
||||||
|
using type = typename detail::statement_policies_t<Policies...>::_required_tables_of;
|
||||||
|
};
|
||||||
|
|
||||||
template <typename... Policies>
|
template <typename... Policies>
|
||||||
struct known_aggregate_columns_of<statement_t<Policies...>>
|
struct known_aggregate_columns_of<statement_t<Policies...>>
|
||||||
{
|
{
|
||||||
|
@ -23,11 +23,8 @@
|
|||||||
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
set(test_files
|
set(test_files
|
||||||
Blob.cpp
|
|
||||||
CustomQuery.cpp
|
CustomQuery.cpp
|
||||||
DynamicWhere.cpp
|
DynamicWhere.cpp
|
||||||
Float.cpp
|
|
||||||
ForUpdate.cpp
|
|
||||||
From.cpp
|
From.cpp
|
||||||
Insert.cpp
|
Insert.cpp
|
||||||
Lower.cpp
|
Lower.cpp
|
||||||
@ -38,7 +35,6 @@ set(test_files
|
|||||||
TableAlias.cpp
|
TableAlias.cpp
|
||||||
Trim.cpp
|
Trim.cpp
|
||||||
Upper.cpp
|
Upper.cpp
|
||||||
Where.cpp
|
|
||||||
)
|
)
|
||||||
|
|
||||||
create_test_sourcelist(test_sources test_serializer_main.cpp ${test_files})
|
create_test_sourcelist(test_sources test_serializer_main.cpp ${test_files})
|
||||||
@ -57,3 +53,4 @@ add_subdirectory(basic)
|
|||||||
add_subdirectory(clause)
|
add_subdirectory(clause)
|
||||||
add_subdirectory(operator)
|
add_subdirectory(operator)
|
||||||
add_subdirectory(query)
|
add_subdirectory(query)
|
||||||
|
add_subdirectory(value_types)
|
||||||
|
@ -1,96 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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 "compare.h"
|
|
||||||
#include "Sample.h"
|
|
||||||
#include <sqlpp11/sqlpp11.h>
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
namespace
|
|
||||||
{
|
|
||||||
auto getTrue() -> std::string
|
|
||||||
{
|
|
||||||
MockDb::_serializer_context_t printer = {};
|
|
||||||
return to_sql_string(printer, sqlpp::value(true));
|
|
||||||
}
|
|
||||||
|
|
||||||
auto getFalse() -> std::string
|
|
||||||
{
|
|
||||||
MockDb::_serializer_context_t printer = {};
|
|
||||||
return to_sql_string(printer, sqlpp::value(false));
|
|
||||||
}
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
int Where(int, char*[])
|
|
||||||
{
|
|
||||||
const auto foo = test::TabFoo{};
|
|
||||||
const auto bar = test::TabBar{};
|
|
||||||
|
|
||||||
// Unconditionally
|
|
||||||
SQLPP_COMPARE(select(foo.doubleN).from(foo).unconditionally(), "SELECT tab_foo.double_n FROM tab_foo");
|
|
||||||
SQLPP_COMPARE(remove_from(foo).unconditionally(), "DELETE FROM tab_foo");
|
|
||||||
SQLPP_COMPARE(update(foo).set(foo.doubleN = 42).unconditionally(), "UPDATE tab_foo SET double_n = 42");
|
|
||||||
static_assert(
|
|
||||||
sqlpp::is_numeric<decltype(foo.doubleN)>::value,
|
|
||||||
"");
|
|
||||||
static_assert(
|
|
||||||
sqlpp::is_numeric<decltype(foo.doubleN - 1)>::value,
|
|
||||||
"");
|
|
||||||
static_assert(
|
|
||||||
sqlpp::values_are_comparable<decltype(foo.doubleN), decltype(foo.doubleN - -1)>::value,
|
|
||||||
"");
|
|
||||||
static_assert(
|
|
||||||
sqlpp::values_are_comparable<decltype(foo.doubleN), decltype(-1)>::value,
|
|
||||||
"");
|
|
||||||
SQLPP_COMPARE(update(foo).set(foo.doubleN = foo.doubleN - -1).unconditionally(),
|
|
||||||
"UPDATE tab_foo SET double_n = (tab_foo.double_n - -1)");
|
|
||||||
SQLPP_COMPARE(where(sqlpp::value(true)), " WHERE " + getTrue());
|
|
||||||
|
|
||||||
// Never
|
|
||||||
SQLPP_COMPARE(where(sqlpp::value(false)), " WHERE " + getFalse());
|
|
||||||
|
|
||||||
// Sometimes
|
|
||||||
SQLPP_COMPARE(where(bar.boolNn), " WHERE tab_bar.bool_nn");
|
|
||||||
SQLPP_COMPARE(where(bar.boolNn == false), " WHERE tab_bar.bool_nn = " + getFalse());
|
|
||||||
SQLPP_COMPARE(where(bar.textN.is_null()), " WHERE tab_bar.text_n IS NULL");
|
|
||||||
SQLPP_COMPARE(where(bar.textN == "SQL"), " WHERE tab_bar.text_n = 'SQL'");
|
|
||||||
SQLPP_COMPARE(where(is_not_distinct_from(bar.textN, ::sqlpp::make_optional("SQL"))),
|
|
||||||
" WHERE tab_bar.text_n IS NOT DISTINCT FROM 'SQL'");
|
|
||||||
SQLPP_COMPARE(where(is_not_distinct_from(bar.textN, ::sqlpp::nullopt)),
|
|
||||||
" WHERE tab_bar.text_n IS NOT DISTINCT FROM NULL");
|
|
||||||
SQLPP_COMPARE(where(bar.textN.is_not_distinct_from(::sqlpp::make_optional("SQL"))),
|
|
||||||
" WHERE tab_bar.text_n IS NOT DISTINCT FROM 'SQL'");
|
|
||||||
SQLPP_COMPARE(where(bar.textN.is_not_distinct_from(::sqlpp::nullopt)),
|
|
||||||
" WHERE tab_bar.text_n IS NOT DISTINCT FROM NULL");
|
|
||||||
|
|
||||||
// string argument
|
|
||||||
SQLPP_COMPARE(where(bar.textN == std::string("SQL")), " WHERE tab_bar.text_n = 'SQL'");
|
|
||||||
|
|
||||||
// string_view argument
|
|
||||||
SQLPP_COMPARE(where(bar.textN == ::sqlpp::string_view("SQL")), " WHERE tab_bar.text_n = 'SQL'");
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
@ -29,6 +29,7 @@ function(create_test name)
|
|||||||
add_test(NAME ${target} COMMAND ${target})
|
add_test(NAME ${target} COMMAND ${target})
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
|
create_test(cte)
|
||||||
create_test(delete_from)
|
create_test(delete_from)
|
||||||
create_test(group_by)
|
create_test(group_by)
|
||||||
create_test(for_update)
|
create_test(for_update)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2017, Serge Robyns
|
* Copyright (c) 2024, Roland Bock
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without modification,
|
* Redistribution and use in source and binary forms, with or without modification,
|
||||||
@ -23,19 +23,22 @@
|
|||||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "compare.h"
|
|
||||||
#include "Sample.h"
|
#include "Sample.h"
|
||||||
|
#include "../compare.h"
|
||||||
#include <sqlpp11/sqlpp11.h>
|
#include <sqlpp11/sqlpp11.h>
|
||||||
|
|
||||||
int ForUpdate(int, char* [])
|
int main(int, char* [])
|
||||||
{
|
{
|
||||||
const auto foo = test::TabFoo{};
|
const auto foo = test::TabFoo{};
|
||||||
|
|
||||||
SQLPP_COMPARE(sqlpp::for_update(),
|
// No expression (not super useful).
|
||||||
" FOR UPDATE ");
|
SQLPP_COMPARE(cte(sqlpp::alias::x), "x");
|
||||||
|
|
||||||
SQLPP_COMPARE(select(foo.doubleN).from(foo).unconditionally().for_update(),
|
// Select
|
||||||
"SELECT tab_foo.double_n FROM tab_foo FOR UPDATE ");
|
SQLPP_COMPARE(cte(sqlpp::alias::x).as(select(foo.id).from(foo).unconditionally()), "x AS (SELECT tab_foo.id FROM tab_foo)");
|
||||||
|
|
||||||
|
|
||||||
|
#warning: Add more tests
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
@ -32,7 +32,7 @@ int main()
|
|||||||
const auto foo = test::TabFoo{};
|
const auto foo = test::TabFoo{};
|
||||||
|
|
||||||
// Single table
|
// Single table
|
||||||
SQLPP_COMPARE(single_table(foo), " tab_foo");
|
SQLPP_COMPARE(single_table(foo), "tab_foo");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
35
tests/core/serialize/value_types/CMakeLists.txt
Normal file
35
tests/core/serialize/value_types/CMakeLists.txt
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
# Copyright (c) 2024, 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.
|
||||||
|
|
||||||
|
function(create_test name)
|
||||||
|
set(target sqlpp11_core_serialize_value_type_${name})
|
||||||
|
add_executable(${target} ${name}.cpp)
|
||||||
|
target_link_libraries(${target} PRIVATE sqlpp11::sqlpp11 sqlpp11_testing)
|
||||||
|
add_test(NAME ${target} COMMAND ${target})
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
create_test(blob)
|
||||||
|
create_test(float)
|
||||||
|
create_test(text)
|
||||||
|
|
41
tests/core/serialize/value_types/blob.cpp
Normal file
41
tests/core/serialize/value_types/blob.cpp
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024, 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 "../compare.h"
|
||||||
|
#include <sqlpp11/sqlpp11.h>
|
||||||
|
|
||||||
|
int main(int, char* [])
|
||||||
|
{
|
||||||
|
// vector<uint8_t>
|
||||||
|
std::vector<uint8_t> vec{{'c', 'h', 'e', 'e', 's', 'e', 'c', 'a', 'k', 'e'}};
|
||||||
|
SQLPP_COMPARE(vec,
|
||||||
|
"x'63686565736563616B65'");
|
||||||
|
|
||||||
|
// array<uint8_t>
|
||||||
|
std::array<uint8_t, 10> arr{{'c', 'h', 'e', 'e', 's', 'e', 'c', 'a', 'k', 'e'}};
|
||||||
|
SQLPP_COMPARE(arr,
|
||||||
|
"x'63686565736563616B65'");
|
||||||
|
|
||||||
|
}
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2023, Roland Bock
|
* Copyright (c) 2024, Roland Bock
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without modification,
|
* Redistribution and use in source and binary forms, with or without modification,
|
||||||
@ -23,35 +23,12 @@
|
|||||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "Sample.h"
|
||||||
|
#include "../compare.h"
|
||||||
#include <sqlpp11/sqlpp11.h>
|
#include <sqlpp11/sqlpp11.h>
|
||||||
|
|
||||||
#include "compare.h"
|
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
template <typename Result, typename Expected>
|
|
||||||
void assert_equal(int lineNo, const Result& result, const Expected& expected)
|
|
||||||
{
|
|
||||||
if (result != expected)
|
|
||||||
{
|
|
||||||
std::cerr << __FILE__ << " " << lineNo << '\n'
|
|
||||||
<< "Expected: -->|" << expected << "|<--\n"
|
|
||||||
<< "Received: -->|" << result << "|<--\n";
|
|
||||||
throw std::runtime_error("unexpected result");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
void to_sql_string_serializes_in_deserializable_format(int line, T value)
|
|
||||||
{
|
|
||||||
MockDb::_serializer_context_t printer = {};
|
|
||||||
const auto serialized = sqlpp::to_sql_string(printer, value);
|
|
||||||
std::istringstream is{serialized};
|
|
||||||
T deserialized;
|
|
||||||
is >> deserialized;
|
|
||||||
assert_equal(line, deserialized, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
std::string string_for_10_0000086()
|
std::string string_for_10_0000086()
|
||||||
{
|
{
|
||||||
@ -69,14 +46,11 @@ namespace
|
|||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
int Float(int, char*[])
|
int main(int, char* [])
|
||||||
{
|
{
|
||||||
#warning: document that connectors need to use float_safe_ostringstream or similar.
|
SQLPP_COMPARE(10.0000114f, "10.0000114");
|
||||||
to_sql_string_serializes_in_deserializable_format(__LINE__, 10.0000086f);
|
|
||||||
to_sql_string_serializes_in_deserializable_format(__LINE__, 10.0000086);
|
|
||||||
to_sql_string_serializes_in_deserializable_format(__LINE__, 10.0000086l);
|
|
||||||
|
|
||||||
SQLPP_COMPARE(10.0000114, "10.0000114");
|
SQLPP_COMPARE(10.0000114, "10.0000114");
|
||||||
|
SQLPP_COMPARE(10.0000114l, "10.0000114");
|
||||||
SQLPP_COMPARE(10.0000086f, string_for_10_0000086<float>());
|
SQLPP_COMPARE(10.0000086f, string_for_10_0000086<float>());
|
||||||
SQLPP_COMPARE(10.0000086, string_for_10_0000086<double>());
|
SQLPP_COMPARE(10.0000086, string_for_10_0000086<double>());
|
||||||
SQLPP_COMPARE(10.0000086l, string_for_10_0000086<long double>());
|
SQLPP_COMPARE(10.0000086l, string_for_10_0000086<long double>());
|
35
tests/core/serialize/value_types/text.cpp
Normal file
35
tests/core/serialize/value_types/text.cpp
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024, 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 "../compare.h"
|
||||||
|
#include <sqlpp11/sqlpp11.h>
|
||||||
|
|
||||||
|
int main(int, char* [])
|
||||||
|
{
|
||||||
|
SQLPP_COMPARE("", "''");
|
||||||
|
SQLPP_COMPARE("'", "''''");
|
||||||
|
|
||||||
|
#warning: Need more tests here
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user