mirror of
https://github.com/rbock/sqlpp11.git
synced 2024-11-16 04:47:18 +08:00
Add serialize tests for limit and offset
This commit is contained in:
parent
e3eb52a080
commit
040047e5ff
@ -73,16 +73,17 @@ namespace sqlpp
|
||||
};
|
||||
};
|
||||
|
||||
SQLPP_PORTABLE_STATIC_ASSERT(assert_limit_is_unsigned_integral,
|
||||
"argument for limit() must be an unsigned integral expressions");
|
||||
SQLPP_PORTABLE_STATIC_ASSERT(assert_limit_is_integral,
|
||||
"argument for limit() must be an integral expressions");
|
||||
template <typename T>
|
||||
struct check_limit
|
||||
{
|
||||
#warning: document that limits can be integral (not just unsigned integral)
|
||||
using type =
|
||||
static_combined_check_t<static_check_t<is_unsigned_integral<T>::value, assert_limit_is_unsigned_integral>>;
|
||||
static_combined_check_t<static_check_t<is_integral<T>::value, assert_limit_is_integral>>;
|
||||
};
|
||||
template <typename T>
|
||||
using check_limit_t = typename check_limit<T>::type;
|
||||
using check_limit_t = typename check_limit<remove_dynamic_t<T>>::type;
|
||||
|
||||
struct no_limit_t
|
||||
{
|
||||
@ -133,6 +134,16 @@ namespace sqlpp
|
||||
return " LIMIT " + operand_to_sql_string(context, t._value);
|
||||
}
|
||||
|
||||
template <typename Context, typename Limit>
|
||||
auto to_sql_string(Context& context, const limit_data_t<dynamic_t<Limit>>& t) -> std::string
|
||||
{
|
||||
if (not t._value._condition)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
return " LIMIT " + operand_to_sql_string(context, t._value._expr);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
auto limit(T&& t) -> decltype(statement_t<no_limit_t>().limit(std::forward<T>(t)))
|
||||
{
|
||||
|
@ -72,16 +72,16 @@ namespace sqlpp
|
||||
};
|
||||
};
|
||||
|
||||
SQLPP_PORTABLE_STATIC_ASSERT(assert_offset_is_unsigned_integral,
|
||||
SQLPP_PORTABLE_STATIC_ASSERT(assert_offset_is_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_unsigned_integral<T>::value, assert_offset_is_unsigned_integral>>;
|
||||
static_combined_check_t<static_check_t<is_integral<T>::value, assert_offset_is_integral>>;
|
||||
};
|
||||
template <typename T>
|
||||
using check_offset_t = typename check_offset<T>::type;
|
||||
using check_offset_t = typename check_offset<remove_dynamic_t<T>>::type;
|
||||
|
||||
struct no_offset_t
|
||||
{
|
||||
@ -144,6 +144,16 @@ namespace sqlpp
|
||||
return " OFFSET " + operand_to_sql_string(context, t._value);
|
||||
}
|
||||
|
||||
template <typename Context, typename Offset>
|
||||
auto to_sql_string(Context& context, const offset_data_t<dynamic_t<Offset>>& t) -> std::string
|
||||
{
|
||||
if (not t._value._condition)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
return " OFFSET " + operand_to_sql_string(context, t._value._expr);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
auto offset(T&& t) -> decltype(statement_t<no_offset_t>().offset(std::forward<T>(t)))
|
||||
{
|
||||
|
@ -36,6 +36,8 @@ create_test(insert)
|
||||
create_test(insert_columns)
|
||||
create_test(insert_default_values)
|
||||
create_test(insert_set)
|
||||
create_test(limit)
|
||||
create_test(offset)
|
||||
create_test(order_by)
|
||||
create_test(select_columns)
|
||||
create_test(select_flags)
|
||||
|
45
tests/core/serialize/clause/limit.cpp
Normal file
45
tests/core/serialize/clause/limit.cpp
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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 "../compare.h"
|
||||
#include <sqlpp11/sqlpp11.h>
|
||||
|
||||
int main(int, char* [])
|
||||
{
|
||||
const auto val = sqlpp::value(17);
|
||||
const auto expr = sqlpp::value(17) + 4;
|
||||
|
||||
// Without static limit.
|
||||
SQLPP_COMPARE(sqlpp::limit(17), " LIMIT 17");
|
||||
SQLPP_COMPARE(limit(val), " LIMIT 17");
|
||||
SQLPP_COMPARE(limit(expr), " LIMIT (17 + 4)");
|
||||
|
||||
// With dynamic limit.
|
||||
SQLPP_COMPARE(limit(dynamic(true, val)), " LIMIT 17");
|
||||
SQLPP_COMPARE(limit(dynamic(false, val)), "");
|
||||
|
||||
return 0;
|
||||
}
|
45
tests/core/serialize/clause/offset.cpp
Normal file
45
tests/core/serialize/clause/offset.cpp
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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 "../compare.h"
|
||||
#include <sqlpp11/sqlpp11.h>
|
||||
|
||||
int main(int, char* [])
|
||||
{
|
||||
const auto val = sqlpp::value(17);
|
||||
const auto expr = sqlpp::value(17) + 4;
|
||||
|
||||
// Without static offset.
|
||||
SQLPP_COMPARE(sqlpp::offset(17), " OFFSET 17");
|
||||
SQLPP_COMPARE(offset(val), " OFFSET 17");
|
||||
SQLPP_COMPARE(offset(expr), " OFFSET (17 + 4)");
|
||||
|
||||
// With dynamic offset.
|
||||
SQLPP_COMPARE(offset(dynamic(true, val)), " OFFSET 17");
|
||||
SQLPP_COMPARE(offset(dynamic(false, val)), "");
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user