mirror of
https://github.com/rbock/sqlpp11.git
synced 2024-11-16 04:47:18 +08:00
Add tests for (insert) into and (update) single_table
Repaired a few other tests while at it
This commit is contained in:
parent
6589c9ccbe
commit
eaa7d24924
@ -75,11 +75,6 @@ namespace sqlpp
|
||||
{
|
||||
};
|
||||
|
||||
template <typename TableSpec>
|
||||
struct provided_optional_tables_of<table_t<TableSpec>> : public provided_tables_of<table_t<TableSpec>>
|
||||
{
|
||||
};
|
||||
|
||||
template <typename Context, typename TableSpec>
|
||||
auto to_sql_string(Context& context, const table_t<TableSpec>& /*unused*/) -> std::string
|
||||
{
|
||||
|
@ -90,7 +90,7 @@ namespace sqlpp
|
||||
template <typename Table>
|
||||
struct check_update_table
|
||||
{
|
||||
using type = static_combined_check_t<static_check_t<is_table<Table>::value, assert_update_table_arg_is_table_t>>;
|
||||
using type = static_combined_check_t<static_check_t<is_raw_table<Table>::value, assert_update_table_arg_is_table_t>>;
|
||||
};
|
||||
template <typename Table>
|
||||
using check_update_table_t = typename check_update_table<Table>::type;
|
||||
@ -147,4 +147,10 @@ namespace sqlpp
|
||||
{
|
||||
return to_sql_string(context, t._table);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
auto single_table(T&& t) -> decltype(statement_t<no_single_table_t>().single_table(std::forward<T>(t)))
|
||||
{
|
||||
return statement_t<no_single_table_t>().single_table(std::forward<T>(t));
|
||||
}
|
||||
} // namespace sqlpp
|
||||
|
@ -76,7 +76,7 @@ namespace sqlpp
|
||||
struct is_aggregate_expression
|
||||
: public std::integral_constant<bool,
|
||||
is_aggregate_function<T>::value or
|
||||
KnownAggregateColumns::template contains<T>::value>
|
||||
KnownAggregateColumns::template contains<T>()>
|
||||
{
|
||||
};
|
||||
|
||||
|
@ -33,4 +33,10 @@ test_compile(result_row)
|
||||
test_compile(select_as)
|
||||
test_compile(value)
|
||||
|
||||
add_subdirectory(aggregate_function)
|
||||
add_subdirectory(basic)
|
||||
add_subdirectory(clause)
|
||||
add_subdirectory(detail)
|
||||
add_subdirectory(operator)
|
||||
add_subdirectory(type_traits)
|
||||
|
||||
|
@ -152,6 +152,7 @@ void test_group_by()
|
||||
|
||||
|
||||
#warning: Need to add tests with verbatim tables
|
||||
#warning: Need to add tests with schema qualified tables
|
||||
#warning: Need to add tests with 3 tables
|
||||
|
||||
#warning: Need to add tests with CTEs
|
||||
|
@ -37,7 +37,8 @@ void test_table()
|
||||
static_assert(std::is_same<sqlpp::name_tag_of_t<test::TabFoo>, test::TabFoo_::_sqlpp_name_tag>::value, "");
|
||||
static_assert(std::is_same<sqlpp::provided_tables_of_t<test::TabFoo>, sqlpp::detail::type_vector<test::TabFoo>>::value, "");
|
||||
static_assert(std::is_same<sqlpp::provided_static_tables_of_t<test::TabFoo>, sqlpp::provided_tables_of_t<test::TabFoo>>::value, "");
|
||||
static_assert(std::is_same<sqlpp::provided_optional_tables_of_t<test::TabFoo>, sqlpp::provided_tables_of_t<test::TabFoo>>::value, "");
|
||||
// Only joins can provide optional tables.
|
||||
static_assert(std::is_same<sqlpp::provided_optional_tables_of_t<test::TabFoo>, sqlpp::detail::type_vector<>>::value, "");
|
||||
}
|
||||
|
||||
int main()
|
||||
|
@ -29,5 +29,7 @@ function(test_compile name)
|
||||
endfunction()
|
||||
|
||||
test_compile(group_by)
|
||||
test_compile(into)
|
||||
test_compile(select_columns)
|
||||
test_compile(single_table)
|
||||
|
||||
|
63
tests/core/types/clause/into.cpp
Normal file
63
tests/core/types/clause/into.cpp
Normal file
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* 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 "Sample.h"
|
||||
#include <sqlpp11/sqlpp11.h>
|
||||
|
||||
SQLPP_CREATE_NAME_TAG(cheese);
|
||||
|
||||
template <typename T>
|
||||
void assert_invalid_argument(T t)
|
||||
{
|
||||
using I = decltype(sqlpp::into(t));
|
||||
static_assert(std::is_same<I, sqlpp::assert_into_arg_is_table>::value, "");
|
||||
}
|
||||
|
||||
void test_into()
|
||||
{
|
||||
auto v = sqlpp::value(17);
|
||||
auto foo = test::TabFoo{};
|
||||
auto bar = test::TabBar{};
|
||||
using Foo = decltype(foo);
|
||||
auto id = foo.id;
|
||||
|
||||
// Valid into clause
|
||||
{
|
||||
using I = decltype(sqlpp::into(foo));
|
||||
static_assert(std::is_same<sqlpp::provided_tables_of_t<I>, sqlpp::detail::type_vector<Foo>>::value, "");
|
||||
static_assert(std::is_same<sqlpp::provided_static_tables_of_t<I>, sqlpp::provided_tables_of_t<I>>::value, "");
|
||||
static_assert(std::is_same<sqlpp::provided_optional_tables_of_t<I>, sqlpp::detail::type_vector<>>::value, "");
|
||||
}
|
||||
|
||||
assert_invalid_argument(foo.join(bar));
|
||||
assert_invalid_argument(foo.as(cheese));
|
||||
assert_invalid_argument(id);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
void test_into();
|
||||
}
|
||||
|
63
tests/core/types/clause/single_table.cpp
Normal file
63
tests/core/types/clause/single_table.cpp
Normal file
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* 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 "Sample.h"
|
||||
#include <sqlpp11/sqlpp11.h>
|
||||
|
||||
SQLPP_CREATE_NAME_TAG(cheese);
|
||||
|
||||
template <typename T>
|
||||
void assert_invalid_argument(T t)
|
||||
{
|
||||
using S = decltype(sqlpp::single_table(t));
|
||||
static_assert(std::is_same<S, sqlpp::assert_update_table_arg_is_table_t>::value, "");
|
||||
}
|
||||
|
||||
void test_single_table()
|
||||
{
|
||||
auto v = sqlpp::value(17);
|
||||
auto foo = test::TabFoo{};
|
||||
auto bar = test::TabBar{};
|
||||
using Foo = decltype(foo);
|
||||
auto id = foo.id;
|
||||
|
||||
// Valid single table clause
|
||||
{
|
||||
using S = decltype(sqlpp::single_table(foo));
|
||||
static_assert(std::is_same<sqlpp::provided_tables_of_t<S>, sqlpp::detail::type_vector<Foo>>::value, "");
|
||||
static_assert(std::is_same<sqlpp::provided_static_tables_of_t<S>, sqlpp::provided_tables_of_t<S>>::value, "");
|
||||
static_assert(std::is_same<sqlpp::provided_optional_tables_of_t<S>, sqlpp::detail::type_vector<>>::value, "");
|
||||
}
|
||||
|
||||
assert_invalid_argument(foo.join(bar));
|
||||
assert_invalid_argument(foo.as(cheese));
|
||||
assert_invalid_argument(id);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
void test_single_table();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user