mirror of
https://github.com/rbock/sqlpp11.git
synced 2024-11-16 12:51:13 +08:00
Fixed tests
This commit is contained in:
parent
069fcf79b5
commit
7a900b147c
@ -80,6 +80,20 @@ namespace sqlpp
|
||||
using type = sqlpp::force_optional_t<floating_point>;
|
||||
};
|
||||
|
||||
template <typename Context, typename Flag, typename Expr>
|
||||
Context& serialize(Context& context, const avg_t<Flag, Expr>& t)
|
||||
{
|
||||
context << "MAX(";
|
||||
if (std::is_same<distinct_t, Flag>::value)
|
||||
{
|
||||
serialize(context, Flag());
|
||||
context << ' ';
|
||||
}
|
||||
serialize_operand(context, t._expr);
|
||||
context << ")";
|
||||
return context;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
using check_avg_arg =
|
||||
::sqlpp::enable_if_t<(is_numeric<T>::value or is_boolean<T>::value) and not contains_aggregate_function_t<T>::value>;
|
||||
|
@ -116,8 +116,10 @@ namespace sqlpp
|
||||
{
|
||||
using T = column_t<Table, ColumnSpec>;
|
||||
|
||||
context << name_tag_of_t<Table>::_name_t::template char_ptr<Context>() << '.'
|
||||
<< name_tag_of_t<T>::_name_t::template char_ptr<Context>();
|
||||
serialize_name(context, name_tag_of_t<Table>::name);
|
||||
context << '.';
|
||||
serialize_name(context, name_tag_of_t<T>::name);
|
||||
|
||||
return context;
|
||||
}
|
||||
} // namespace sqlpp
|
||||
|
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
* Copyright (c) 2013-2020, Roland Bock, MacDue
|
||||
* Copyright (c) 2013, Roland Bock
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
|
@ -69,7 +69,7 @@ namespace sqlpp
|
||||
template <typename Context, typename TableSpec>
|
||||
Context& serialize(Context& context, const table_t<TableSpec>& /*unused*/)
|
||||
{
|
||||
context << name_tag_of_t<TableSpec>::_name_t::template char_ptr<Context>();
|
||||
serialize_name(context, name_tag_of_t<TableSpec>::name);
|
||||
return context;
|
||||
}
|
||||
} // namespace sqlpp
|
||||
|
@ -58,8 +58,9 @@ namespace sqlpp
|
||||
template <typename Context, typename AliasProvider, typename TableSpec>
|
||||
Context& serialize(Context& context, const table_alias_t<AliasProvider, TableSpec>&)
|
||||
{
|
||||
context << name_tag_of_t<TableSpec>::_name_t::template char_ptr<Context>();
|
||||
context << " AS " << name_tag_of_t<AliasProvider>::_name_t::template char_ptr<Context>();
|
||||
serialize_name(context, name_tag_of_t<TableSpec>::name);
|
||||
context << " AS ";
|
||||
serialize_name(context, name_tag_of_t<AliasProvider>::name);
|
||||
return context;
|
||||
}
|
||||
} // namespace sqlpp
|
||||
|
@ -58,7 +58,8 @@ namespace sqlpp
|
||||
Context& serialize(Context& context, const verbatim_table_alias_t<AliasProvider>& t)
|
||||
{
|
||||
context << t._representation;
|
||||
context << " AS " << name_tag_of_t<AliasProvider>::_name_t::template char_ptr<Context>();
|
||||
context << " AS ";
|
||||
serialize_name(context, name_tag_of_t<AliasProvider>::name);
|
||||
return context;
|
||||
}
|
||||
|
||||
|
@ -54,8 +54,9 @@ namespace sqlpp
|
||||
{
|
||||
using T = pseudo_column_t<TableAliasProvider, ColumnSpec>;
|
||||
|
||||
context << name_tag_of_t<TableAliasProvider>::_name_t::template char_ptr<Context>() << '.'
|
||||
<< name_tag_of_t<T>::_name_t::template char_ptr<Context>();
|
||||
serialize_name(context, name_tag_of_t<TableAliasProvider>::name);
|
||||
context << '.';
|
||||
serialize_name(context, name_tag_of_t<T>::name);
|
||||
return context;
|
||||
}
|
||||
|
||||
@ -97,7 +98,8 @@ namespace sqlpp
|
||||
auto serialize(Context& context, const select_as_t<Select, AliasProvider, ColumnSpecs...>& t) -> Context&
|
||||
{
|
||||
serialize_operand(context, t._select);
|
||||
context << " AS " << name_tag_of_t<AliasProvider>::_name_t::template char_ptr<Context>();
|
||||
context << " AS ";
|
||||
serialize_name(context, name_tag_of_t<AliasProvider>::name);
|
||||
return context;
|
||||
}
|
||||
} // namespace sqlpp
|
||||
|
@ -62,16 +62,17 @@ namespace sqlpp
|
||||
{
|
||||
}
|
||||
|
||||
string_view(const char* data) : _data(data), _size(std::char_traits<char>::length(data))
|
||||
#warning: Can we make char_traits<char>::length constexpr
|
||||
constexpr string_view(const char* data) : _data(data), _size(std::char_traits<char>::length(data))
|
||||
{
|
||||
}
|
||||
|
||||
const char* data() const
|
||||
constexpr const char* data() const
|
||||
{
|
||||
return _data;
|
||||
}
|
||||
|
||||
size_t size() const
|
||||
constexpr size_t size() const
|
||||
{
|
||||
return _size;
|
||||
}
|
||||
@ -104,3 +105,4 @@ namespace sqlpp
|
||||
} // namespace sqlpp
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include <stddef.h>
|
||||
#include <sqlpp11/core/wrong.h>
|
||||
#include <sqlpp11/core/logic.h>
|
||||
#include <sqlpp11/core/name/char_sequence.h>
|
||||
#include <sqlpp11/core/name/name_tag.h>
|
||||
|
||||
namespace sqlpp
|
||||
@ -270,7 +271,8 @@ namespace sqlpp
|
||||
template <typename... E>
|
||||
struct make_name_of_set<type_set<E...>>
|
||||
{
|
||||
using type = make_type_set_t<typename sqlpp::name_tag_of_t<E>::_sqlpp_name_tag::_name_t...>;
|
||||
using type =
|
||||
make_type_set_t<make_char_sequence<sizeof(sqlpp::name_tag_of_t<E>::name), sqlpp::name_tag_of_t<E>::name>...>;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
|
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
* Copyright (c) 2013-2016, Roland Bock
|
||||
* Copyright (c) 2013, Roland Bock
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
@ -30,7 +30,7 @@
|
||||
#include <sqlpp11/core/type_traits.h>
|
||||
|
||||
#define SQLPP_NAME_TAG_GUTS(SQL_NAME, CPP_NAME) \
|
||||
static constexpr auto name = sqlpp::string_view{#SQL_NAME}; \
|
||||
static constexpr const char name[] = #SQL_NAME;\
|
||||
template <typename T> \
|
||||
struct _member_t \
|
||||
{ \
|
||||
|
@ -27,37 +27,14 @@
|
||||
*/
|
||||
|
||||
#include <type_traits>
|
||||
#warning: move index_sequence into compat
|
||||
#include <sqlpp11/core/detail/index_sequence.h>
|
||||
|
||||
namespace sqlpp
|
||||
{
|
||||
template <typename Context>
|
||||
std::integral_constant<char, '"'> get_quote_left(const Context&);
|
||||
|
||||
template <typename Context>
|
||||
std::integral_constant<char, '"'> get_quote_right(const Context&);
|
||||
|
||||
template <char... Cs>
|
||||
struct char_sequence
|
||||
{
|
||||
template <typename Context>
|
||||
static const char* char_ptr()
|
||||
{
|
||||
static char s[] = {Cs..., '\0'};
|
||||
return s;
|
||||
}
|
||||
};
|
||||
|
||||
template <char... Cs>
|
||||
struct char_sequence<'!', Cs...>
|
||||
{
|
||||
template <typename Context>
|
||||
static const char* char_ptr()
|
||||
{
|
||||
static char s[] = {decltype(get_quote_left(std::declval<Context>()))::value, Cs...,
|
||||
decltype(get_quote_right(std::declval<Context>()))::value, '\0'};
|
||||
return s;
|
||||
}
|
||||
};
|
||||
|
||||
template <std::size_t N, const char* s, typename T>
|
||||
|
@ -27,6 +27,7 @@
|
||||
*/
|
||||
|
||||
#include <type_traits>
|
||||
#include <sqlpp11/core/serialize.h>
|
||||
#include <sqlpp11/core/database/prepared_execute.h>
|
||||
|
||||
namespace sqlpp
|
||||
@ -80,7 +81,7 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context>
|
||||
Context& serialize(Context& context, const noop&)
|
||||
auto serialize(Context& context, const noop&) -> Context&
|
||||
{
|
||||
return context;
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ namespace sqlpp
|
||||
{
|
||||
serialize_operand(context, t._expression);
|
||||
context << " AS ";
|
||||
context << name_tag_of_t<AliasProvider>::name;
|
||||
serialize_name(context, name_tag_of_t<AliasProvider>::name);
|
||||
return context;
|
||||
}
|
||||
template <typename Expr, typename AliasProvider>
|
||||
|
@ -107,6 +107,22 @@ namespace sqlpp
|
||||
return context;
|
||||
}
|
||||
|
||||
template <typename Context, typename L, typename Operator, typename R1, typename R2>
|
||||
auto serialize(Context& context,
|
||||
const logical_expression<logical_expression<L, Operator, R1>, Operator, dynamic_t<R2>>& t) -> Context&
|
||||
{
|
||||
if (t._r._condition)
|
||||
{
|
||||
serialize(context, t._l);
|
||||
context << Operator::symbol;
|
||||
serialize_operand(context, t._r);
|
||||
return context;
|
||||
}
|
||||
|
||||
// If the dynamic part is inactive ignore it.
|
||||
return serialize(context, t._l);
|
||||
}
|
||||
|
||||
template <typename Context, typename L, typename Operator, typename R>
|
||||
auto serialize(Context& context, const logical_expression<L, Operator, dynamic_t<R>>& t) -> Context&
|
||||
{
|
||||
|
@ -234,4 +234,14 @@ namespace sqlpp
|
||||
return context;
|
||||
}
|
||||
|
||||
template <typename T, typename Context>
|
||||
auto serialize_name(Context& context, const T& t) -> Context&
|
||||
{
|
||||
#warning: We used to have a version of SQLPP_ALIAS_PROVIDER that escaped the name
|
||||
|
||||
context << t;
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
} // namespace sqlpp
|
||||
|
@ -1,56 +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>
|
||||
|
||||
SQLPP_ALIAS_PROVIDER(cheese);
|
||||
SQLPP_ALIAS_PROVIDER(maxId);
|
||||
|
||||
int As(int, char*[])
|
||||
{
|
||||
const auto foo = test::TabFoo{};
|
||||
const auto bar = test::TabBar{};
|
||||
|
||||
compare(__LINE__, foo, "tab_foo");
|
||||
compare(__LINE__, foo.doubleN.as(cheese), "tab_foo.double_n AS cheese");
|
||||
compare(__LINE__, (foo.doubleN + 17).as(cheese), "(tab_foo.double_n + 17) AS cheese");
|
||||
compare(__LINE__, (foo.doubleN - 17).as(cheese), "(tab_foo.double_n - 17) AS cheese");
|
||||
compare(__LINE__, (foo.doubleN - uint32_t(17)).as(cheese), "(tab_foo.double_n - 17) AS cheese");
|
||||
compare(__LINE__, (foo.doubleN - bar.id).as(cheese), "(tab_foo.double_n - tab_bar.id) AS cheese");
|
||||
compare(__LINE__, (count(foo.doubleN) - bar.id).as(cheese), "(COUNT(tab_foo.double_n) - tab_bar.id) AS cheese");
|
||||
compare(__LINE__, (count(foo.doubleN) - uint32_t(17)).as(cheese), "(COUNT(tab_foo.double_n) - 17) AS cheese");
|
||||
|
||||
compare(__LINE__, select(max(bar.id).as(maxId)), "SELECT MAX(tab_bar.id) AS maxId");
|
||||
compare(__LINE__, select(max(bar.id).as(cheese)), "SELECT MAX(tab_bar.id) AS cheese");
|
||||
compare(__LINE__, select(max(bar.id).as(maxId)).from(bar).unconditionally().as(cheese),
|
||||
"(SELECT MAX(tab_bar.id) AS maxId FROM tab_bar) AS cheese");
|
||||
compare(__LINE__, select(max(bar.id).as(maxId)).from(bar).unconditionally().as(cheese).maxId, "cheese.maxId");
|
||||
|
||||
return 0;
|
||||
}
|
@ -32,17 +32,17 @@ int Avg(int, char* [])
|
||||
const auto bar = test::TabBar{};
|
||||
|
||||
// Single column.
|
||||
compare(__LINE__, avg(bar.id), "AVG(tab_bar.id)");
|
||||
compare(__LINE__, avg(sqlpp::distinct, bar.id), "AVG(DISTINCT tab_bar.id)");
|
||||
SQLPP_COMPARE(avg(bar.id), "AVG(tab_bar.id)");
|
||||
SQLPP_COMPARE(avg(sqlpp::distinct, bar.id), "AVG(DISTINCT tab_bar.id)");
|
||||
|
||||
// Expression.
|
||||
#warning: Note that the inner parens aren't necessary.
|
||||
compare(__LINE__, avg(bar.id + 7), "AVG((tab_bar.id + 7))");
|
||||
compare(__LINE__, avg(sqlpp::distinct, bar.id + 7), "AVG(DISTINCT (tab_bar.id + 7))");
|
||||
SQLPP_COMPARE(avg(bar.id + 7), "AVG((tab_bar.id + 7))");
|
||||
SQLPP_COMPARE(avg(sqlpp::distinct, bar.id + 7), "AVG(DISTINCT (tab_bar.id + 7))");
|
||||
|
||||
// With sub select.
|
||||
compare(__LINE__, avg(select(sqlpp::value(7).as(sqlpp::alias::a))), "AVG((SELECT 7 AS a))");
|
||||
compare(__LINE__, avg(sqlpp::distinct, select(sqlpp::value(7).as(sqlpp::alias::a))), "AVG(DISTINCT (SELECT 7 AS a))");
|
||||
SQLPP_COMPARE(avg(select(sqlpp::value(7).as(sqlpp::alias::a))), "AVG((SELECT 7 AS a))");
|
||||
SQLPP_COMPARE(avg(sqlpp::distinct, select(sqlpp::value(7).as(sqlpp::alias::a))), "AVG(DISTINCT (SELECT 7 AS a))");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -58,17 +58,17 @@ int Blob(int, char*[])
|
||||
// const auto bar = test::TabBar{};
|
||||
|
||||
// Unconditionally
|
||||
compare(__LINE__, select(foo.blobN).from(foo).where(foo.blobN == toByteVector("john doe")),
|
||||
SQLPP_COMPARE(select(foo.blobN).from(foo).where(foo.blobN == toByteVector("john doe")),
|
||||
"SELECT tab_foo.blob_n FROM tab_foo WHERE (tab_foo.blob_n = x'6A6F686E20646F65')");
|
||||
|
||||
std::array<uint8_t, 8> arr{{'j', 'o', 'h', 'n', ' ', 'd', 'o', 'e'}};
|
||||
compare(__LINE__, select(foo.blobN).from(foo).where(foo.blobN == arr),
|
||||
SQLPP_COMPARE(select(foo.blobN).from(foo).where(foo.blobN == arr),
|
||||
"SELECT tab_foo.blob_n FROM tab_foo WHERE (tab_foo.blob_n = x'6A6F686E20646F65')");
|
||||
|
||||
#warning: This should go somewhere else
|
||||
// Never
|
||||
compare(__LINE__, where(sqlpp::value(false)), " WHERE " + getFalse());
|
||||
compare(__LINE__, sqlpp::where(false), " WHERE " + getFalse());
|
||||
SQLPP_COMPARE(where(sqlpp::value(false)), " WHERE " + getFalse());
|
||||
SQLPP_COMPARE(sqlpp::where(false), " WHERE " + getFalse());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -23,25 +23,20 @@
|
||||
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
set(test_files
|
||||
logical_expression.cpp
|
||||
As.cpp
|
||||
Avg.cpp
|
||||
Blob.cpp
|
||||
Count.cpp
|
||||
CustomQuery.cpp
|
||||
DynamicWhere.cpp
|
||||
Exists.cpp
|
||||
Float.cpp
|
||||
ForUpdate.cpp
|
||||
From.cpp
|
||||
In.cpp
|
||||
Insert.cpp
|
||||
IsNotNull.cpp
|
||||
IsNull.cpp
|
||||
Lower.cpp
|
||||
Max.cpp
|
||||
Min.cpp
|
||||
Operator.cpp
|
||||
Over.cpp
|
||||
Parameter.cpp
|
||||
ParameterizedVerbatim.cpp
|
||||
|
@ -32,17 +32,17 @@ int Count(int, char* [])
|
||||
const auto bar = test::TabBar{};
|
||||
|
||||
// Single column.
|
||||
compare(__LINE__, count(bar.id), "COUNT(tab_bar.id)");
|
||||
compare(__LINE__, count(sqlpp::distinct, bar.id), "COUNT(DISTINCT tab_bar.id)");
|
||||
SQLPP_COMPARE(count(bar.id), "COUNT(tab_bar.id)");
|
||||
SQLPP_COMPARE(count(sqlpp::distinct, bar.id), "COUNT(DISTINCT tab_bar.id)");
|
||||
|
||||
// Expression.
|
||||
#warning: Note that the inner parens aren't necessary.
|
||||
compare(__LINE__, count(bar.id + 7), "COUNT((tab_bar.id + 7))");
|
||||
compare(__LINE__, count(sqlpp::distinct, bar.id + 7), "COUNT(DISTINCT (tab_bar.id + 7))");
|
||||
SQLPP_COMPARE(count(bar.id + 7), "COUNT((tab_bar.id + 7))");
|
||||
SQLPP_COMPARE(count(sqlpp::distinct, bar.id + 7), "COUNT(DISTINCT (tab_bar.id + 7))");
|
||||
|
||||
// With sub select.
|
||||
compare(__LINE__, count(select(sqlpp::value(7).as(sqlpp::alias::a))), "COUNT((SELECT 7 AS a))");
|
||||
compare(__LINE__, count(sqlpp::distinct, select(sqlpp::value(7).as(sqlpp::alias::a))), "COUNT(DISTINCT (SELECT 7 AS a))");
|
||||
SQLPP_COMPARE(count(select(sqlpp::value(7).as(sqlpp::alias::a))), "COUNT((SELECT 7 AS a))");
|
||||
SQLPP_COMPARE(count(sqlpp::distinct, select(sqlpp::value(7).as(sqlpp::alias::a))), "COUNT(DISTINCT (SELECT 7 AS a))");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -29,7 +29,7 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
SQLPP_ALIAS_PROVIDER(pragma)
|
||||
SQLPP_ALIAS_PROVIDER(pragma);
|
||||
|
||||
int CustomQuery(int, char*[])
|
||||
{
|
||||
@ -37,13 +37,12 @@ int CustomQuery(int, char*[])
|
||||
const auto bar = test::TabBar{};
|
||||
|
||||
// Unconditionally
|
||||
compare(__LINE__,
|
||||
custom_query(sqlpp::select(), select_flags(sqlpp::distinct), select_columns(foo.doubleN), from(foo),
|
||||
SQLPP_COMPARE(custom_query(sqlpp::select(), select_flags(sqlpp::distinct), select_columns(foo.doubleN), from(foo),
|
||||
sqlpp::unconditionally()),
|
||||
"SELECT DISTINCT tab_foo.double_n FROM tab_foo ");
|
||||
|
||||
// A full select statement made individual clauses
|
||||
compare(__LINE__,
|
||||
SQLPP_COMPARE(
|
||||
custom_query(sqlpp::select(), select_flags(sqlpp::distinct), select_columns(foo.doubleN),
|
||||
from(foo.join(bar).on(foo.doubleN == bar.id)), where(bar.id > 17), group_by(foo.doubleN),
|
||||
having(avg(bar.id) > 19), order_by(foo.doubleN.asc()), sqlpp::limit(10u), sqlpp::offset(100u)),
|
||||
@ -52,26 +51,23 @@ int CustomQuery(int, char*[])
|
||||
"LIMIT 10 OFFSET 100");
|
||||
|
||||
// A full select statement made individual clauses
|
||||
compare(
|
||||
__LINE__,
|
||||
SQLPP_COMPARE(
|
||||
custom_query(sqlpp::select(), select_flags(sqlpp::distinct), select_columns(foo.doubleN),
|
||||
from(foo.join(bar).on(foo.doubleN == bar.id)), where(bar.id > 17),
|
||||
group_by(foo.doubleN), having(avg(bar.id) > 19),
|
||||
order_by(foo.doubleN.asc(), foo.uIntN.order(sqlpp::sort_type::desc)),
|
||||
from(foo.join(bar).on(foo.doubleN == bar.id)), where(bar.id > 17), group_by(foo.doubleN),
|
||||
having(avg(bar.id) > 19), order_by(foo.doubleN.asc(), foo.uIntN.order(sqlpp::sort_type::desc)),
|
||||
sqlpp::limit(7u), sqlpp::offset(3u)),
|
||||
"SELECT DISTINCT tab_foo.double_n FROM tab_foo INNER JOIN tab_bar ON (tab_foo.double_n = tab_bar.id) WHERE "
|
||||
"(tab_bar.id > 17) GROUP BY tab_foo.double_n HAVING (AVG(tab_bar.id) > 19) ORDER BY tab_foo.double_n "
|
||||
"ASC,tab_foo.u_int_n DESC LIMIT 7 OFFSET 3");
|
||||
|
||||
// A pragma query/query for sqlite
|
||||
compare(__LINE__,
|
||||
SQLPP_COMPARE(
|
||||
custom_query(sqlpp::verbatim("PRAGMA user_version")).with_result_type_of(select(sqlpp::value(1).as(pragma))),
|
||||
" PRAGMA user_version");
|
||||
|
||||
// An insert from select for postgresql
|
||||
const auto x = 17;
|
||||
compare(__LINE__,
|
||||
custom_query(insert_into(foo).columns(foo.doubleN),
|
||||
SQLPP_COMPARE(custom_query(insert_into(foo).columns(foo.doubleN),
|
||||
select(sqlpp::value(x).as(foo.doubleN))
|
||||
.from(foo)
|
||||
.where(not exists(select(foo.doubleN).from(foo).where(foo.doubleN == x)))),
|
||||
@ -79,13 +75,13 @@ int CustomQuery(int, char*[])
|
||||
"SELECT 17 AS double_n FROM tab_foo "
|
||||
"WHERE (NOT EXISTS(SELECT tab_foo.double_n FROM tab_foo WHERE (tab_foo.double_n = 17)))");
|
||||
|
||||
#warning: reactivate
|
||||
#warning : reactivate
|
||||
#if 0
|
||||
// A multi-row "insert or ignore"
|
||||
auto batch = insert_columns(bar.textN, bar.boolNn);
|
||||
batch.add_values(bar.textN = "sample", bar.boolNn = true);
|
||||
batch.add_values(bar.textN = "ample", bar.boolNn = false);
|
||||
compare(__LINE__, custom_query(sqlpp::insert(), sqlpp::verbatim(" OR IGNORE"), into(bar), batch),
|
||||
SQLPP_COMPARE( custom_query(sqlpp::insert(), sqlpp::verbatim(" OR IGNORE"), into(bar), batch),
|
||||
"INSERT OR IGNORE INTO tab_bar (text_n,bool_nn) VALUES ('sample',1),('ample',0)");
|
||||
#endif
|
||||
|
||||
|
@ -35,11 +35,11 @@ int DynamicWhere(int, char*[])
|
||||
const auto bar = test::TabBar{};
|
||||
auto db = MockDb{};
|
||||
|
||||
compare(__LINE__, sqlpp::unconditionally(), "");
|
||||
compare(__LINE__, where(bar.boolNn), " WHERE tab_bar.bool_nn");
|
||||
SQLPP_COMPARE(sqlpp::unconditionally(), "");
|
||||
SQLPP_COMPARE(where(bar.boolNn), " WHERE tab_bar.bool_nn");
|
||||
|
||||
compare(__LINE__, where(bar.boolNn and dynamic(true, foo.boolN)), " WHERE (tab_bar.bool_nn AND tab_foo.bool_n)");
|
||||
compare(__LINE__, where(bar.boolNn and dynamic(false, foo.boolN)), " WHERE tab_bar.bool_nn");
|
||||
SQLPP_COMPARE(where(bar.boolNn and dynamic(true, foo.boolN)), " WHERE (tab_bar.bool_nn AND tab_foo.bool_n)");
|
||||
SQLPP_COMPARE(where(bar.boolNn and dynamic(false, foo.boolN)), " WHERE tab_bar.bool_nn");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,41 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2023, 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 Exists(int, char* [])
|
||||
{
|
||||
const auto bar = test::TabBar{};
|
||||
|
||||
// With sub select.
|
||||
compare(__LINE__, exists(select(bar.id).from(bar).where(bar.id > 17)),
|
||||
"EXISTS(SELECT tab_bar.id FROM tab_bar WHERE (tab_bar.id > 17))");
|
||||
compare(__LINE__, bar.textN == "" and exists(select(bar.id).from(bar).where(bar.id > 17)),
|
||||
"((tab_bar.text_n = '') AND EXISTS(SELECT tab_bar.id FROM tab_bar WHERE (tab_bar.id > 17)))");
|
||||
|
||||
return 0;
|
||||
}
|
@ -30,6 +30,18 @@
|
||||
|
||||
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 float_safe_ostringstream_serializes_in_deserializable_format(int line, T value)
|
||||
{
|
||||
@ -65,11 +77,10 @@ int Float(int, char*[])
|
||||
float_safe_ostringstream_serializes_in_deserializable_format(__LINE__, 10.0000086);
|
||||
float_safe_ostringstream_serializes_in_deserializable_format(__LINE__, 10.0000086l);
|
||||
|
||||
compare(__LINE__, 10.0000114, "10.0000114");
|
||||
compare(__LINE__, 10.0000086f, string_for_10_0000086<float>());
|
||||
compare(__LINE__, 10.0000086, string_for_10_0000086<double>());
|
||||
compare(__LINE__, 10.0000086l, string_for_10_0000086<long double>());
|
||||
|
||||
SQLPP_COMPARE(10.0000114, "10.0000114");
|
||||
SQLPP_COMPARE(10.0000086f, string_for_10_0000086<float>());
|
||||
SQLPP_COMPARE(10.0000086, string_for_10_0000086<double>());
|
||||
SQLPP_COMPARE(10.0000086l, string_for_10_0000086<long double>());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -31,10 +31,10 @@ int ForUpdate(int, char* [])
|
||||
{
|
||||
const auto foo = test::TabFoo{};
|
||||
|
||||
compare(__LINE__, sqlpp::for_update(),
|
||||
SQLPP_COMPARE(sqlpp::for_update(),
|
||||
" FOR UPDATE ");
|
||||
|
||||
compare(__LINE__, select(foo.doubleN).from(foo).unconditionally().for_update(),
|
||||
SQLPP_COMPARE(select(foo.doubleN).from(foo).unconditionally().for_update(),
|
||||
"SELECT tab_foo.double_n FROM tab_foo FOR UPDATE ");
|
||||
|
||||
return 0;
|
||||
|
@ -41,37 +41,36 @@ int From(int, char* [])
|
||||
const auto cFoo = foo.as(sqlpp::alias::c);
|
||||
|
||||
// Single table
|
||||
compare(__LINE__, from(foo), " FROM tab_foo");
|
||||
compare(__LINE__, from(bar), " FROM tab_bar");
|
||||
SQLPP_COMPARE(from(foo), " FROM tab_foo");
|
||||
SQLPP_COMPARE(from(bar), " FROM tab_bar");
|
||||
|
||||
// Static joins
|
||||
compare(__LINE__, from(foo.cross_join(bar)), " FROM tab_foo CROSS JOIN tab_bar");
|
||||
compare(__LINE__, from(foo.join(bar).on(foo.doubleN > bar.id)),
|
||||
SQLPP_COMPARE(from(foo.cross_join(bar)), " FROM tab_foo CROSS JOIN tab_bar");
|
||||
SQLPP_COMPARE(from(foo.join(bar).on(foo.doubleN > bar.id)),
|
||||
" FROM tab_foo INNER JOIN tab_bar ON (tab_foo.double_n > tab_bar.id)");
|
||||
compare(__LINE__, from(foo.inner_join(bar).on(foo.doubleN > bar.id)),
|
||||
SQLPP_COMPARE(from(foo.inner_join(bar).on(foo.doubleN > bar.id)),
|
||||
" FROM tab_foo INNER JOIN tab_bar ON (tab_foo.double_n > tab_bar.id)");
|
||||
compare(__LINE__, from(foo.outer_join(bar).on(foo.doubleN > bar.id)),
|
||||
SQLPP_COMPARE(from(foo.outer_join(bar).on(foo.doubleN > bar.id)),
|
||||
" FROM tab_foo OUTER JOIN tab_bar ON (tab_foo.double_n > tab_bar.id)");
|
||||
compare(__LINE__, from(foo.left_outer_join(bar).on(foo.doubleN > bar.id)),
|
||||
SQLPP_COMPARE(from(foo.left_outer_join(bar).on(foo.doubleN > bar.id)),
|
||||
" FROM tab_foo LEFT OUTER JOIN tab_bar ON (tab_foo.double_n > tab_bar.id)");
|
||||
compare(__LINE__, from(foo.right_outer_join(bar).on(foo.doubleN > bar.id)),
|
||||
SQLPP_COMPARE(from(foo.right_outer_join(bar).on(foo.doubleN > bar.id)),
|
||||
" FROM tab_foo RIGHT OUTER JOIN tab_bar ON (tab_foo.double_n > tab_bar.id)");
|
||||
compare(__LINE__, from(aFoo.join(bFoo).on(aFoo.doubleN > bFoo.doubleN)),
|
||||
SQLPP_COMPARE(from(aFoo.join(bFoo).on(aFoo.doubleN > bFoo.doubleN)),
|
||||
" FROM tab_foo AS a INNER JOIN tab_foo AS b ON (a.double_n > b.double_n)");
|
||||
compare(
|
||||
__LINE__, from(aFoo.join(bFoo).on(aFoo.doubleN > bFoo.doubleN).join(cFoo).on(bFoo.doubleN > cFoo.doubleN)),
|
||||
SQLPP_COMPARE(from(aFoo.join(bFoo).on(aFoo.doubleN > bFoo.doubleN).join(cFoo).on(bFoo.doubleN > cFoo.doubleN)),
|
||||
" FROM tab_foo AS a INNER JOIN tab_foo AS b ON (a.double_n > b.double_n) INNER JOIN tab_foo AS c ON (b.double_n > c.double_n)");
|
||||
compare(__LINE__, from(foo.join(bar).unconditionally()), " FROM tab_foo INNER JOIN tab_bar");
|
||||
SQLPP_COMPARE(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"))
|
||||
SQLPP_COMPARE(from(aFoo.join(sqlpp::verbatim_table("unknown_table"))
|
||||
.on(aFoo.doubleN > sqlpp::verbatim<sqlpp::floating_point>("unknown_table.column_x"))),
|
||||
" FROM tab_foo AS a INNER JOIN unknown_table ON (a.double_n > unknown_table.column_x)");
|
||||
compare(__LINE__, from(sqlpp::verbatim_table("unknown_table")
|
||||
SQLPP_COMPARE(from(sqlpp::verbatim_table("unknown_table")
|
||||
.join(aFoo)
|
||||
.on(aFoo.doubleN > sqlpp::verbatim<sqlpp::floating_point>("unknown_table.column_x"))),
|
||||
" FROM unknown_table INNER JOIN tab_foo AS a ON (a.double_n > unknown_table.column_x)");
|
||||
compare(__LINE__, from(sqlpp::verbatim_table("unknown_table")
|
||||
SQLPP_COMPARE(from(sqlpp::verbatim_table("unknown_table")
|
||||
.as(sqlpp::alias::a)
|
||||
.join(sqlpp::verbatim_table("another_table"))
|
||||
.on(sqlpp::verbatim<sqlpp::boolean>("a.column_x > another_table.x"))),
|
||||
|
@ -1,63 +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 getFalse() -> std::string
|
||||
{
|
||||
MockDb::_serializer_context_t printer = {};
|
||||
return serialize(printer, sqlpp::value(false)).str();
|
||||
}
|
||||
}
|
||||
|
||||
int In(int, char* [])
|
||||
{
|
||||
const auto foo = test::TabFoo{};
|
||||
const auto bar = test::TabBar{};
|
||||
|
||||
// Individual values
|
||||
compare(__LINE__, foo.doubleN.in(17), "tab_foo.double_n IN(17)");
|
||||
compare(__LINE__, foo.doubleN.in(17, bar.id), "tab_foo.double_n IN(17,tab_bar.id)");
|
||||
compare(__LINE__, foo.doubleN.in(17, bar.id, sqlpp::value(19)), "tab_foo.double_n IN(17,tab_bar.id,19)");
|
||||
|
||||
// Lists
|
||||
compare(__LINE__, foo.doubleN.in(std::vector<float>{1.75f, 2.5f, 17.f, 0.f}),
|
||||
"tab_foo.double_n IN(1.75,2.5,17,0)");
|
||||
|
||||
// Sub select
|
||||
compare(__LINE__, foo.doubleN.in(select(bar.id).from(bar).unconditionally()),
|
||||
"tab_foo.double_n IN(SELECT tab_bar.id FROM tab_bar)");
|
||||
|
||||
// Empty list (not normally allowed by SQL)
|
||||
compare(__LINE__, foo.doubleN.in(std::vector<int>{}), getFalse());
|
||||
|
||||
return 0;
|
||||
}
|
@ -42,15 +42,15 @@ int Insert(int, char* [])
|
||||
{
|
||||
const auto bar = test::TabBar{};
|
||||
|
||||
compare(__LINE__, insert_into(bar).default_values(), "INSERT INTO tab_bar DEFAULT VALUES");
|
||||
compare(__LINE__, insert_into(bar).set(bar.textN = "cheesecake", bar.boolNn = true),
|
||||
SQLPP_COMPARE(insert_into(bar).default_values(), "INSERT INTO tab_bar DEFAULT VALUES");
|
||||
SQLPP_COMPARE(insert_into(bar).set(bar.textN = "cheesecake", bar.boolNn = true),
|
||||
"INSERT INTO tab_bar (text_n,bool_nn) VALUES('cheesecake'," + getTrue() + ")");
|
||||
compare(__LINE__, insert_into(bar).set(bar.textN = ::::sqlpp::nullopt, bar.boolNn = true),
|
||||
SQLPP_COMPARE(insert_into(bar).set(bar.textN = ::sqlpp::nullopt, bar.boolNn = true),
|
||||
"INSERT INTO tab_bar (text_n,bool_nn) VALUES(NULL," + getTrue() + ")");
|
||||
::sqlpp::string_view cheeseCake = "cheesecake";
|
||||
compare(__LINE__, insert_into(bar).set(bar.textN = std::string(cheeseCake), bar.boolNn = true),
|
||||
SQLPP_COMPARE(insert_into(bar).set(bar.textN = std::string(cheeseCake), bar.boolNn = true),
|
||||
"INSERT INTO tab_bar (text_n,bool_nn) VALUES('cheesecake'," + getTrue() + ")");
|
||||
compare(__LINE__, insert_into(bar).set(bar.textN = ::sqlpp::string_view(cheeseCake), bar.boolNn = true),
|
||||
SQLPP_COMPARE(insert_into(bar).set(bar.textN = ::sqlpp::string_view(cheeseCake), bar.boolNn = true),
|
||||
"INSERT INTO tab_bar (text_n,bool_nn) VALUES('cheesecake'," + getTrue() + ")");
|
||||
|
||||
return 0;
|
||||
|
@ -32,17 +32,17 @@ int IsNotNull(int, char* [])
|
||||
const auto bar = test::TabBar{};
|
||||
|
||||
// Single column.
|
||||
compare(__LINE__, is_not_null(bar.textN), "(tab_bar.text_n IS NOT NULL)");
|
||||
SQLPP_COMPARE(is_not_null(bar.textN), "(tab_bar.text_n IS NOT NULL)");
|
||||
|
||||
// Expression.
|
||||
compare(__LINE__, is_not_null(bar.textN + "suffix"), "((tab_bar.text_n || 'suffix') IS NOT NULL)");
|
||||
SQLPP_COMPARE(is_not_null(bar.textN + "suffix"), "((tab_bar.text_n || 'suffix') IS NOT NULL)");
|
||||
|
||||
// With sub select.
|
||||
compare(__LINE__, is_not_null(select(sqlpp::value("something").as(sqlpp::alias::a))), "((SELECT 'something' AS a) IS NOT NULL)");
|
||||
SQLPP_COMPARE(is_not_null(select(sqlpp::value("something").as(sqlpp::alias::a))), "((SELECT 'something' AS a) IS NOT NULL)");
|
||||
|
||||
// Requires parens.
|
||||
compare(__LINE__, is_not_null(bar.textN) or bar.textN == "", "((tab_bar.text_n IS NOT NULL) OR (tab_bar.text_n = ''))");
|
||||
compare(__LINE__, bar.textN == "" or is_not_null(bar.textN), "((tab_bar.text_n = '') OR (tab_bar.text_n IS NOT NULL))");
|
||||
SQLPP_COMPARE(is_not_null(bar.textN) or bar.textN == "", "((tab_bar.text_n IS NOT NULL) OR (tab_bar.text_n = ''))");
|
||||
SQLPP_COMPARE(bar.textN == "" or is_not_null(bar.textN), "((tab_bar.text_n = '') OR (tab_bar.text_n IS NOT NULL))");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -32,17 +32,17 @@ int IsNull(int, char* [])
|
||||
const auto bar = test::TabBar{};
|
||||
|
||||
// Single column.
|
||||
compare(__LINE__, is_null(bar.textN), "(tab_bar.text_n IS NULL)");
|
||||
SQLPP_COMPARE(is_null(bar.textN), "(tab_bar.text_n IS NULL)");
|
||||
|
||||
// Expression.
|
||||
compare(__LINE__, is_null(bar.textN + "suffix"), "((tab_bar.text_n || 'suffix') IS NULL)");
|
||||
SQLPP_COMPARE(is_null(bar.textN + "suffix"), "((tab_bar.text_n || 'suffix') IS NULL)");
|
||||
|
||||
// With sub select.
|
||||
compare(__LINE__, is_null(select(sqlpp::value("something").as(sqlpp::alias::a))), "((SELECT 'something' AS a) IS NULL)");
|
||||
SQLPP_COMPARE(is_null(select(sqlpp::value("something").as(sqlpp::alias::a))), "((SELECT 'something' AS a) IS NULL)");
|
||||
|
||||
// Requires parens.
|
||||
compare(__LINE__, is_null(bar.textN) or bar.textN == "", "((tab_bar.text_n IS NULL) OR (tab_bar.text_n = ''))");
|
||||
compare(__LINE__, bar.textN == "" or is_null(bar.textN), "((tab_bar.text_n = '') OR (tab_bar.text_n IS NULL))");
|
||||
SQLPP_COMPARE(is_null(bar.textN) or bar.textN == "", "((tab_bar.text_n IS NULL) OR (tab_bar.text_n = ''))");
|
||||
SQLPP_COMPARE(bar.textN == "" or is_null(bar.textN), "((tab_bar.text_n = '') OR (tab_bar.text_n IS NULL))");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -32,14 +32,14 @@ int Lower(int, char* [])
|
||||
const auto bar = test::TabBar{};
|
||||
|
||||
// Single column.
|
||||
compare(__LINE__, lower(bar.textN), "LOWER(tab_bar.text_n)");
|
||||
SQLPP_COMPARE(lower(bar.textN), "LOWER(tab_bar.text_n)");
|
||||
|
||||
// Expression.
|
||||
#warning: Note that the inner parens aren't necessary.
|
||||
compare(__LINE__, lower(bar.textN + "suffix"), "LOWER((tab_bar.text_n || 'suffix'))");
|
||||
SQLPP_COMPARE(lower(bar.textN + "suffix"), "LOWER((tab_bar.text_n || 'suffix'))");
|
||||
|
||||
// With sub select.
|
||||
compare(__LINE__, lower(select(sqlpp::value("something").as(sqlpp::alias::a))), "LOWER((SELECT 'something' AS a))");
|
||||
SQLPP_COMPARE(lower(select(sqlpp::value("something").as(sqlpp::alias::a))), "LOWER((SELECT 'something' AS a))");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -32,17 +32,17 @@ int Max(int, char* [])
|
||||
const auto bar = test::TabBar{};
|
||||
|
||||
// Single column.
|
||||
compare(__LINE__, max(bar.id), "MAX(tab_bar.id)");
|
||||
compare(__LINE__, max(sqlpp::distinct, bar.id), "MAX(DISTINCT tab_bar.id)");
|
||||
SQLPP_COMPARE(max(bar.id), "MAX(tab_bar.id)");
|
||||
SQLPP_COMPARE(max(sqlpp::distinct, bar.id), "MAX(DISTINCT tab_bar.id)");
|
||||
|
||||
// Expression.
|
||||
// Note that the inner parens aren't necessary.
|
||||
compare(__LINE__, max(bar.id + 7), "MAX((tab_bar.id + 7))");
|
||||
compare(__LINE__, max(sqlpp::distinct, bar.id + 7), "MAX(DISTINCT (tab_bar.id + 7))");
|
||||
SQLPP_COMPARE(max(bar.id + 7), "MAX((tab_bar.id + 7))");
|
||||
SQLPP_COMPARE(max(sqlpp::distinct, bar.id + 7), "MAX(DISTINCT (tab_bar.id + 7))");
|
||||
|
||||
// With sub select.
|
||||
compare(__LINE__, max(select(sqlpp::value(7).as(sqlpp::alias::a))), "MAX((SELECT 7 AS a))");
|
||||
compare(__LINE__, max(sqlpp::distinct, select(sqlpp::value(7).as(sqlpp::alias::a))), "MAX(DISTINCT (SELECT 7 AS a))");
|
||||
SQLPP_COMPARE(max(select(sqlpp::value(7).as(sqlpp::alias::a))), "MAX((SELECT 7 AS a))");
|
||||
SQLPP_COMPARE(max(sqlpp::distinct, select(sqlpp::value(7).as(sqlpp::alias::a))), "MAX(DISTINCT (SELECT 7 AS a))");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -32,17 +32,17 @@ int Min(int, char* [])
|
||||
const auto bar = test::TabBar{};
|
||||
|
||||
// Single column.
|
||||
compare(__LINE__, min(bar.id), "MIN(tab_bar.id)");
|
||||
compare(__LINE__, min(sqlpp::distinct, bar.id), "MIN(DISTINCT tab_bar.id)");
|
||||
SQLPP_COMPARE(min(bar.id), "MIN(tab_bar.id)");
|
||||
SQLPP_COMPARE(min(sqlpp::distinct, bar.id), "MIN(DISTINCT tab_bar.id)");
|
||||
|
||||
// Expression.
|
||||
// Note that the inner parens aren't necessary.
|
||||
compare(__LINE__, min(bar.id + 7), "MIN((tab_bar.id + 7))");
|
||||
compare(__LINE__, min(sqlpp::distinct, bar.id + 7), "MIN(DISTINCT (tab_bar.id + 7))");
|
||||
SQLPP_COMPARE(min(bar.id + 7), "MIN((tab_bar.id + 7))");
|
||||
SQLPP_COMPARE(min(sqlpp::distinct, bar.id + 7), "MIN(DISTINCT (tab_bar.id + 7))");
|
||||
|
||||
// With sub select.
|
||||
compare(__LINE__, min(select(sqlpp::value(7).as(sqlpp::alias::a))), "MIN((SELECT 7 AS a))");
|
||||
compare(__LINE__, min(sqlpp::distinct, select(sqlpp::value(7).as(sqlpp::alias::a))), "MIN(DISTINCT (SELECT 7 AS a))");
|
||||
SQLPP_COMPARE(min(select(sqlpp::value(7).as(sqlpp::alias::a))), "MIN((SELECT 7 AS a))");
|
||||
SQLPP_COMPARE(min(sqlpp::distinct, select(sqlpp::value(7).as(sqlpp::alias::a))), "MIN(DISTINCT (SELECT 7 AS a))");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2021, 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 Operator(int, char* [])
|
||||
{
|
||||
const auto foo = test::TabFoo{};
|
||||
const auto bar = test::TabBar{};
|
||||
|
||||
// Plus
|
||||
compare(__LINE__, bar.id + 3u, "(tab_bar.id + 3)");
|
||||
compare(__LINE__, sqlpp::value(3) + foo.uIntN, "(3 + tab_foo.u_int_n)");
|
||||
|
||||
// Shift left
|
||||
compare(__LINE__, sqlpp::value(3) << foo.uIntN, "(3 << tab_foo.u_int_n)");
|
||||
compare(__LINE__, bar.id << 3u, "(tab_bar.id << 3)");
|
||||
|
||||
// Shift right
|
||||
compare(__LINE__, sqlpp::value(3) >> foo.uIntN, "(3 >> tab_foo.u_int_n)");
|
||||
compare(__LINE__, bar.id >> 3u, "(tab_bar.id >> 3)");
|
||||
|
||||
// Comparison
|
||||
compare(__LINE__, bar.id < 3u, "(tab_bar.id < 3)");
|
||||
compare(__LINE__, bar.id <= 3u, "(tab_bar.id <= 3)");
|
||||
compare(__LINE__, bar.id == 3u, "(tab_bar.id = 3)");
|
||||
compare(__LINE__, bar.id != 3u, "(tab_bar.id <> 3)");
|
||||
compare(__LINE__, bar.id >= 3u, "(tab_bar.id >= 3)");
|
||||
compare(__LINE__, bar.id > 3u, "(tab_bar.id > 3)");
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016-2020, Roland Bock, MacDue
|
||||
* Copyright (c) 2016, Roland Bock
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
@ -27,16 +27,16 @@
|
||||
#include "compare.h"
|
||||
#include <sqlpp11/sqlpp11.h>
|
||||
|
||||
SQLPP_ALIAS_PROVIDER(dueutil)
|
||||
SQLPP_ALIAS_PROVIDER(cheese);
|
||||
|
||||
int Over(int, char* []) {
|
||||
auto const foo = test::TabFoo{};
|
||||
|
||||
compare(__LINE__, select(avg(foo.doubleN).over().as(dueutil)), "SELECT AVG(tab_foo.double_n) OVER() AS dueutil");
|
||||
compare(__LINE__, select(count(foo.doubleN).over().as(dueutil)), "SELECT COUNT(tab_foo.double_n) OVER() AS dueutil");
|
||||
compare(__LINE__, select(max(foo.doubleN).over().as(dueutil)), "SELECT MAX(tab_foo.double_n) OVER() AS dueutil");
|
||||
compare(__LINE__, select(min(foo.doubleN).over().as(dueutil)), "SELECT MIN(tab_foo.double_n) OVER() AS dueutil");
|
||||
compare(__LINE__, select(sum(foo.doubleN).over().as(dueutil)), "SELECT SUM(tab_foo.double_n) OVER() AS dueutil");
|
||||
SQLPP_COMPARE(select(avg(foo.doubleN).over().as(cheese)), "SELECT AVG(tab_foo.double_n) OVER() AS cheese");
|
||||
SQLPP_COMPARE(select(count(foo.doubleN).over().as(cheese)), "SELECT COUNT(tab_foo.double_n) OVER() AS cheese");
|
||||
SQLPP_COMPARE(select(max(foo.doubleN).over().as(cheese)), "SELECT MAX(tab_foo.double_n) OVER() AS cheese");
|
||||
SQLPP_COMPARE(select(min(foo.doubleN).over().as(cheese)), "SELECT MIN(tab_foo.double_n) OVER() AS cheese");
|
||||
SQLPP_COMPARE(select(sum(foo.doubleN).over().as(cheese)), "SELECT SUM(tab_foo.double_n) OVER() AS cheese");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -32,8 +32,8 @@ int Parameter(int, char*[])
|
||||
const auto foo = test::TabFoo{};
|
||||
const auto bar = test::TabBar{};
|
||||
|
||||
compare(__LINE__, parameter(foo.doubleN), "?");
|
||||
compare(__LINE__, bar.id > parameter(foo.doubleN), "(tab_bar.id > ?)");
|
||||
SQLPP_COMPARE(parameter(foo.doubleN), "?");
|
||||
SQLPP_COMPARE(bar.id > parameter(foo.doubleN), "(tab_bar.id > ?)");
|
||||
|
||||
#warning: Need type tests for parameter, too (do they have the right value type and the right paramter type?)
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2020, Roland Bock, MacDue
|
||||
* Copyright (c) 2013, Roland Bock
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
@ -29,7 +29,7 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
SQLPP_ALIAS_PROVIDER(quester_player_level)
|
||||
SQLPP_ALIAS_PROVIDER(quester_player_level);
|
||||
|
||||
int ParameterizedVerbatim(int, char* [])
|
||||
{
|
||||
@ -37,7 +37,7 @@ int ParameterizedVerbatim(int, char* [])
|
||||
auto checking_value_in_range = sqlpp::parameterized_verbatim<sqlpp::boolean>(
|
||||
"(quests.spawn_level_range @> CAST(", parameter(sqlpp::integral(), quester_player_level), " AS integer))");
|
||||
|
||||
compare(__LINE__, checking_value_in_range, "(quests.spawn_level_range @> CAST(? AS integer))");
|
||||
SQLPP_COMPARE(checking_value_in_range, "(quests.spawn_level_range @> CAST(? AS integer))");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -29,8 +29,8 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
SQLPP_ALIAS_PROVIDER(id_count)
|
||||
SQLPP_ALIAS_PROVIDER(cheese)
|
||||
SQLPP_ALIAS_PROVIDER(id_count);
|
||||
SQLPP_ALIAS_PROVIDER(cheese);
|
||||
|
||||
using namespace sqlpp;
|
||||
|
||||
@ -41,7 +41,7 @@ int SelectAs(int, char*[])
|
||||
|
||||
#warning: The select itself should not offer an "as" that yields a value.
|
||||
#warning: The id_count should offer the alias that offers the value.
|
||||
compare(__LINE__, select(foo.doubleN, select(count(bar.id).as(id_count)).from(bar).unconditionally().as(cheese)),
|
||||
SQLPP_COMPARE(select(foo.doubleN, select(count(bar.id).as(id_count)).from(bar).unconditionally().as(cheese)),
|
||||
"SELECT tab_foo.double_n,(SELECT COUNT(tab_bar.id) AS id_count FROM tab_bar) AS cheese");
|
||||
|
||||
return 0;
|
||||
|
@ -35,35 +35,33 @@ int SelectColumns(int, char*[])
|
||||
const auto bar = test::TabBar{};
|
||||
|
||||
// Single column
|
||||
compare(__LINE__, select(foo.doubleN), "SELECT tab_foo.double_n");
|
||||
SQLPP_COMPARE(select(foo.doubleN), "SELECT tab_foo.double_n");
|
||||
|
||||
// Two columns
|
||||
compare(__LINE__, select(foo.doubleN, bar.id), "SELECT tab_foo.double_n,tab_bar.id");
|
||||
SQLPP_COMPARE(select(foo.doubleN, bar.id), "SELECT tab_foo.double_n,tab_bar.id");
|
||||
|
||||
// All columns of a table
|
||||
compare(__LINE__, select(all_of(foo)),
|
||||
SQLPP_COMPARE(select(all_of(foo)),
|
||||
"SELECT tab_foo.id,tab_foo.text_nn_d,tab_foo.int_n,tab_foo.double_n,tab_foo.u_int_n,tab_foo.blob_n,tab_foo.bool_n");
|
||||
|
||||
// All columns of a table plus one more
|
||||
compare(
|
||||
__LINE__, select(all_of(foo), bar.id),
|
||||
SQLPP_COMPARE(select(all_of(foo), bar.id),
|
||||
"SELECT tab_foo.id,tab_foo.text_nn_d,tab_foo.int_n,tab_foo.double_n,tab_foo.u_int_n,tab_foo.blob_n,tab_foo.bool_n,tab_bar.id");
|
||||
|
||||
// One more, plus all columns of a table
|
||||
compare(
|
||||
__LINE__, select(bar.id, all_of(foo)),
|
||||
SQLPP_COMPARE(select(bar.id, all_of(foo)),
|
||||
"SELECT tab_bar.id,tab_foo.id,tab_foo.text_nn_d,tab_foo.int_n,tab_foo.double_n,tab_foo.u_int_n,tab_foo.blob_n,tab_foo.bool_n");
|
||||
|
||||
// Column and aggregate function
|
||||
compare(__LINE__, select(foo.doubleN, count(bar.id).as(id_count)), "SELECT tab_foo.double_n,COUNT(tab_bar.id) AS id_count");
|
||||
SQLPP_COMPARE(select(foo.doubleN, count(bar.id).as(id_count)), "SELECT tab_foo.double_n,COUNT(tab_bar.id) AS id_count");
|
||||
|
||||
// Column aliases
|
||||
compare(__LINE__, select(foo.doubleN.as(sqlpp::alias::o), count(bar.id).as(sqlpp::alias::a)),
|
||||
SQLPP_COMPARE(select(foo.doubleN.as(sqlpp::alias::o), count(bar.id).as(sqlpp::alias::a)),
|
||||
"SELECT tab_foo.double_n AS o,COUNT(tab_bar.id) AS a");
|
||||
|
||||
// Optional column manually
|
||||
compare(__LINE__, select(dynamic(true, bar.id)), "SELECT tab_bar.id");
|
||||
compare(__LINE__, select(dynamic(false, bar.id)), "SELECT NULL");
|
||||
SQLPP_COMPARE(select(dynamic(true, bar.id)), "SELECT tab_bar.id");
|
||||
SQLPP_COMPARE(select(dynamic(false, bar.id)), "SELECT NULL");
|
||||
|
||||
#warning: add more optional column tests
|
||||
|
||||
|
@ -33,17 +33,17 @@ int SelectFlags(int, char*[])
|
||||
const auto bar = test::TabBar{};
|
||||
|
||||
// No flags
|
||||
compare(__LINE__, select(foo.doubleN), "SELECT tab_foo.double_n");
|
||||
SQLPP_COMPARE(select(foo.doubleN), "SELECT tab_foo.double_n");
|
||||
|
||||
// No flags
|
||||
#warning: This should work
|
||||
//compare(__LINE__, sqlpp::select_flags(), "");
|
||||
//SQLPP_COMPARE(sqlpp::select_flags(), "");
|
||||
|
||||
// No flags
|
||||
compare(__LINE__, select(foo.doubleN).flags(sqlpp::distinct), "SELECT DISTINCT tab_foo.double_n");
|
||||
SQLPP_COMPARE(select(foo.doubleN).flags(sqlpp::distinct), "SELECT DISTINCT tab_foo.double_n");
|
||||
|
||||
// One flag
|
||||
compare(__LINE__, select_flags(sqlpp::distinct), "DISTINCT ");
|
||||
SQLPP_COMPARE(select_flags(sqlpp::distinct), "DISTINCT ");
|
||||
|
||||
#warning: Add tests for dynamic select flags
|
||||
|
||||
|
@ -32,17 +32,17 @@ int Sum(int, char* [])
|
||||
const auto bar = test::TabBar{};
|
||||
|
||||
// Single column.
|
||||
compare(__LINE__, sum(bar.id), "SUM(tab_bar.id)");
|
||||
compare(__LINE__, sum(sqlpp::distinct, bar.id), "SUM(DISTINCT tab_bar.id)");
|
||||
SQLPP_COMPARE(sum(bar.id), "SUM(tab_bar.id)");
|
||||
SQLPP_COMPARE(sum(sqlpp::distinct, bar.id), "SUM(DISTINCT tab_bar.id)");
|
||||
|
||||
// Expression.
|
||||
// Note that the inner parens aren't necessary.
|
||||
compare(__LINE__, sum(bar.id + 7), "SUM((tab_bar.id + 7))");
|
||||
compare(__LINE__, sum(sqlpp::distinct, bar.id + 7), "SUM(DISTINCT (tab_bar.id + 7))");
|
||||
SQLPP_COMPARE(sum(bar.id + 7), "SUM((tab_bar.id + 7))");
|
||||
SQLPP_COMPARE(sum(sqlpp::distinct, bar.id + 7), "SUM(DISTINCT (tab_bar.id + 7))");
|
||||
|
||||
// With sub select.
|
||||
compare(__LINE__, sum(select(sqlpp::value(7).as(sqlpp::alias::a))), "SUM((SELECT 7 AS a))");
|
||||
compare(__LINE__, sum(sqlpp::distinct, select(sqlpp::value(7).as(sqlpp::alias::a))), "SUM(DISTINCT (SELECT 7 AS a))");
|
||||
SQLPP_COMPARE(sum(select(sqlpp::value(7).as(sqlpp::alias::a))), "SUM((SELECT 7 AS a))");
|
||||
SQLPP_COMPARE(sum(sqlpp::distinct, select(sqlpp::value(7).as(sqlpp::alias::a))), "SUM(DISTINCT (SELECT 7 AS a))");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -29,7 +29,7 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
SQLPP_ALIAS_PROVIDER(sample)
|
||||
SQLPP_ALIAS_PROVIDER(sample);
|
||||
|
||||
int TableAlias(int, char* [])
|
||||
{
|
||||
@ -37,13 +37,13 @@ int TableAlias(int, char* [])
|
||||
const auto bar = test::TabBar{};
|
||||
|
||||
// Individual values
|
||||
compare(__LINE__, foo.as(bar), "tab_foo AS tab_bar");
|
||||
compare(__LINE__, select(foo.doubleN).from(foo).unconditionally().as(bar),
|
||||
SQLPP_COMPARE(foo.as(bar), "tab_foo AS tab_bar");
|
||||
SQLPP_COMPARE(select(foo.doubleN).from(foo).unconditionally().as(bar),
|
||||
"(SELECT tab_foo.double_n FROM tab_foo) AS tab_bar");
|
||||
|
||||
// Table alias
|
||||
const auto tab = foo.as(sample);
|
||||
compare(__LINE__, select(tab.doubleN).from(tab).unconditionally(),
|
||||
SQLPP_COMPARE(select(tab.doubleN).from(tab).unconditionally(),
|
||||
"SELECT sample.double_n FROM tab_foo AS sample");
|
||||
|
||||
return 0;
|
||||
|
@ -32,14 +32,14 @@ int Trim(int, char* [])
|
||||
const auto bar = test::TabBar{};
|
||||
|
||||
// Single column.
|
||||
compare(__LINE__, trim(bar.textN), "TRIM(tab_bar.text_n)");
|
||||
SQLPP_COMPARE(trim(bar.textN), "TRIM(tab_bar.text_n)");
|
||||
|
||||
// Expression.
|
||||
#warning: Note that the inner parens aren't necessary.
|
||||
compare(__LINE__, trim(bar.textN + "suffix"), "TRIM((tab_bar.text_n || 'suffix'))");
|
||||
SQLPP_COMPARE(trim(bar.textN + "suffix"), "TRIM((tab_bar.text_n || 'suffix'))");
|
||||
|
||||
// With sub select.
|
||||
compare(__LINE__, trim(select(sqlpp::value("something").as(sqlpp::alias::a))), "TRIM((SELECT 'something' AS a))");
|
||||
SQLPP_COMPARE(trim(select(sqlpp::value("something").as(sqlpp::alias::a))), "TRIM((SELECT 'something' AS a))");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -32,14 +32,14 @@ int Upper(int, char* [])
|
||||
const auto bar = test::TabBar{};
|
||||
|
||||
// Single column.
|
||||
compare(__LINE__, upper(bar.textN), "UPPER(tab_bar.text_n)");
|
||||
SQLPP_COMPARE(upper(bar.textN), "UPPER(tab_bar.text_n)");
|
||||
|
||||
// Expression.
|
||||
#warning: Note that the inner parens aren't necessary.
|
||||
compare(__LINE__, upper(bar.textN + "suffix"), "UPPER((tab_bar.text_n || 'suffix'))");
|
||||
SQLPP_COMPARE(upper(bar.textN + "suffix"), "UPPER((tab_bar.text_n || 'suffix'))");
|
||||
|
||||
// With sub select.
|
||||
compare(__LINE__, upper(select(sqlpp::value("something").as(sqlpp::alias::a))), "UPPER((SELECT 'something' AS a))");
|
||||
SQLPP_COMPARE(upper(select(sqlpp::value("something").as(sqlpp::alias::a))), "UPPER((SELECT 'something' AS a))");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -50,9 +50,9 @@ int Where(int, char*[])
|
||||
const auto bar = test::TabBar{};
|
||||
|
||||
// Unconditionally
|
||||
compare(__LINE__, select(foo.doubleN).from(foo).unconditionally(), "SELECT tab_foo.double_n FROM tab_foo");
|
||||
compare(__LINE__, remove_from(foo).unconditionally(), "DELETE FROM tab_foo");
|
||||
compare(__LINE__, update(foo).set(foo.doubleN = 42).unconditionally(), "UPDATE tab_foo SET double_n = 42");
|
||||
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,
|
||||
"");
|
||||
@ -65,32 +65,32 @@ int Where(int, char*[])
|
||||
static_assert(
|
||||
sqlpp::values_are_comparable<decltype(foo.doubleN), decltype(-1)>::value,
|
||||
"");
|
||||
compare(__LINE__, update(foo).set(foo.doubleN = foo.doubleN - -1).unconditionally(),
|
||||
SQLPP_COMPARE(update(foo).set(foo.doubleN = foo.doubleN - -1).unconditionally(),
|
||||
"UPDATE tab_foo SET double_n = (tab_foo.double_n - -1)");
|
||||
compare(__LINE__, where(sqlpp::value(true)), " WHERE " + getTrue());
|
||||
SQLPP_COMPARE(where(sqlpp::value(true)), " WHERE " + getTrue());
|
||||
|
||||
// Never
|
||||
compare(__LINE__, where(sqlpp::value(false)), " WHERE " + getFalse());
|
||||
SQLPP_COMPARE(where(sqlpp::value(false)), " WHERE " + getFalse());
|
||||
|
||||
// Sometimes
|
||||
compare(__LINE__, where(bar.boolNn), " WHERE tab_bar.bool_nn");
|
||||
compare(__LINE__, where(bar.boolNn == false), " WHERE (tab_bar.bool_nn = " + getFalse() + ")");
|
||||
compare(__LINE__, where(bar.textN.is_null()), " WHERE (tab_bar.text_n IS NULL)");
|
||||
compare(__LINE__, where(bar.textN == "SQL"), " WHERE (tab_bar.text_n = 'SQL')");
|
||||
compare(__LINE__, where(is_not_distinct_from(bar.textN, ::sqlpp::make_optional("SQL"))),
|
||||
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')");
|
||||
compare(__LINE__, where(is_not_distinct_from(bar.textN, ::sqlpp::nullopt)),
|
||||
SQLPP_COMPARE(where(is_not_distinct_from(bar.textN, ::sqlpp::nullopt)),
|
||||
" WHERE (tab_bar.text_n IS NOT DISTINCT FROM NULL)");
|
||||
compare(__LINE__, where(bar.textN.is_not_distinct_from(::sqlpp::make_optional("SQL"))),
|
||||
SQLPP_COMPARE(where(bar.textN.is_not_distinct_from(::sqlpp::make_optional("SQL"))),
|
||||
" WHERE (tab_bar.text_n IS NOT DISTINCT FROM 'SQL')");
|
||||
compare(__LINE__, where(bar.textN.is_not_distinct_from(::sqlpp::nullopt)),
|
||||
SQLPP_COMPARE(where(bar.textN.is_not_distinct_from(::sqlpp::nullopt)),
|
||||
" WHERE (tab_bar.text_n IS NOT DISTINCT FROM NULL)");
|
||||
|
||||
// string argument
|
||||
compare(__LINE__, where(bar.textN == std::string("SQL")), " WHERE (tab_bar.text_n = 'SQL')");
|
||||
SQLPP_COMPARE(where(bar.textN == std::string("SQL")), " WHERE (tab_bar.text_n = 'SQL')");
|
||||
|
||||
// string_view argument
|
||||
compare(__LINE__, where(bar.textN == ::sqlpp::string_view("SQL")), " WHERE (tab_bar.text_n = 'SQL')");
|
||||
SQLPP_COMPARE(where(bar.textN == ::sqlpp::string_view("SQL")), " WHERE (tab_bar.text_n = 'SQL')");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -28,31 +28,6 @@
|
||||
#include "MockDb.h"
|
||||
#include <iostream>
|
||||
|
||||
namespace
|
||||
{
|
||||
template <typename Result, typename Expected>
|
||||
void assert_equal(const std::string& file, 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");
|
||||
}
|
||||
}
|
||||
|
||||
#warning Drop compare and use SQLPP_COMPARE instead
|
||||
template <typename Expression>
|
||||
void compare(int lineNo, const Expression& expr, const std::string& expected)
|
||||
{
|
||||
MockDb::_serializer_context_t printer = {};
|
||||
|
||||
using sqlpp::serialize;
|
||||
const auto result = serialize(printer, expr).str();
|
||||
|
||||
assert_equal(lineNo, result, expected);
|
||||
}
|
||||
|
||||
#warning: Maybe move this into the library/test_support together with MockDb
|
||||
#define SQLPP_COMPARE(expr, expected_string) \
|
||||
{ \
|
||||
@ -69,4 +44,3 @@ namespace
|
||||
return -1; \
|
||||
} \
|
||||
}
|
||||
}
|
||||
|
@ -1,89 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2021, 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 logical_expression(int, char* [])
|
||||
{
|
||||
const auto foo = test::TabFoo{};
|
||||
const auto bar = test::TabBar{};
|
||||
|
||||
// Basic logical expression.
|
||||
compare(__LINE__, foo.boolN and bar.boolNn, "(tab_foo.bool_n AND tab_bar.bool_nn)");
|
||||
compare(__LINE__, foo.boolN or bar.boolNn, "(tab_foo.bool_n OR tab_bar.bool_nn)");
|
||||
compare(__LINE__, not foo.boolN, "(NOT tab_foo.bool_n)");
|
||||
|
||||
// With dynamic part.
|
||||
compare(__LINE__, foo.boolN and dynamic(true, bar.boolNn), "(tab_foo.bool_n AND tab_bar.bool_nn)");
|
||||
compare(__LINE__, foo.boolN and dynamic(false, bar.boolNn), "tab_foo.bool_n");
|
||||
|
||||
compare(__LINE__, foo.boolN or dynamic(true, bar.boolNn), "(tab_foo.bool_n OR tab_bar.bool_nn)");
|
||||
compare(__LINE__, foo.boolN or dynamic(false, bar.boolNn), "tab_foo.bool_n");
|
||||
|
||||
// Advanced logical expression.
|
||||
compare(__LINE__, not foo.boolN and not bar.boolNn, "((NOT tab_foo.bool_n) AND (NOT tab_bar.bool_nn))");
|
||||
compare(__LINE__, not foo.boolN or not bar.boolNn, "((NOT tab_foo.bool_n) OR (NOT tab_bar.bool_nn))");
|
||||
compare(__LINE__, not (foo.boolN and bar.boolNn), "(NOT (tab_foo.bool_n AND tab_bar.bool_nn))");
|
||||
compare(__LINE__, not (foo.boolN or bar.boolNn), "(NOT (tab_foo.bool_n OR tab_bar.bool_nn))");
|
||||
|
||||
// With dynamic part.
|
||||
compare(__LINE__, not foo.boolN and dynamic(true, not bar.boolNn), "((NOT tab_foo.bool_n) AND (NOT tab_bar.bool_nn))");
|
||||
compare(__LINE__, not foo.boolN and dynamic(false, not bar.boolNn), "(NOT tab_foo.bool_n)");
|
||||
|
||||
compare(__LINE__, not foo.boolN or dynamic(true, not bar.boolNn), "((NOT tab_foo.bool_n) OR (NOT tab_bar.bool_nn))");
|
||||
compare(__LINE__, not foo.boolN or dynamic(false, not bar.boolNn), "(NOT tab_foo.bool_n)");
|
||||
|
||||
#warning: Consider reducing braces a bit as in sqlpp17
|
||||
|
||||
// Chained expression.
|
||||
compare(__LINE__, foo.boolN and bar.boolNn and (bar.id > 17),
|
||||
"((tab_foo.bool_n AND tab_bar.bool_nn) AND (tab_bar.id > 17))");
|
||||
compare(__LINE__, foo.boolN or bar.boolNn or (bar.id > 17),
|
||||
"((tab_foo.bool_n OR tab_bar.bool_nn) OR (tab_bar.id > 17))");
|
||||
|
||||
compare(__LINE__, foo.boolN and bar.boolNn and dynamic(true, bar.id > 17),
|
||||
"((tab_foo.bool_n AND tab_bar.bool_nn) AND (tab_bar.id > 17))");
|
||||
compare(__LINE__, foo.boolN and bar.boolNn and dynamic(false, bar.id > 17),
|
||||
"(tab_foo.bool_n AND tab_bar.bool_nn)");
|
||||
compare(__LINE__, foo.boolN or bar.boolNn or dynamic(true, bar.id > 17),
|
||||
"((tab_foo.bool_n OR tab_bar.bool_nn) OR (tab_bar.id > 17))");
|
||||
compare(__LINE__, foo.boolN or bar.boolNn or dynamic(false, bar.id > 17),
|
||||
"(tab_foo.bool_n OR tab_bar.bool_nn)");
|
||||
|
||||
compare(__LINE__, foo.boolN and dynamic(true, bar.boolNn and (bar.id > 17)),
|
||||
"(tab_foo.bool_n AND (tab_bar.bool_nn AND (tab_bar.id > 17)))");
|
||||
compare(__LINE__, foo.boolN and dynamic(false, bar.boolNn and (bar.id > 17)),
|
||||
"tab_foo.bool_n");
|
||||
compare(__LINE__, foo.boolN or dynamic(true, bar.boolNn or (bar.id > 17)),
|
||||
"(tab_foo.bool_n OR (tab_bar.bool_nn OR (tab_bar.id > 17)))");
|
||||
compare(__LINE__, foo.boolN or dynamic(false, bar.boolNn or (bar.id > 17)),
|
||||
"tab_foo.bool_n");
|
||||
|
||||
return 0;
|
||||
}
|
@ -35,12 +35,15 @@ int main(int, char* [])
|
||||
|
||||
SQLPP_COMPARE(val.as(v), "17 AS v");
|
||||
SQLPP_COMPARE(expr.as(v), "(17 + 4) AS v");
|
||||
SQLPP_COMPARE(count(val).as(v), "COUNT(17) AS v");
|
||||
|
||||
SQLPP_COMPARE(dynamic(true, val).as(v), "17 AS v");
|
||||
SQLPP_COMPARE(dynamic(true, expr).as(v), "(17 + 4) AS v");
|
||||
SQLPP_COMPARE(dynamic(true, count(val)).as(v), "COUNT(17) AS v");
|
||||
|
||||
SQLPP_COMPARE(dynamic(false, val).as(v), "NULL AS v");
|
||||
SQLPP_COMPARE(dynamic(false, expr).as(v), "NULL AS v");
|
||||
SQLPP_COMPARE(dynamic(false, count(val)).as(v), "NULL AS v");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -33,6 +33,8 @@ int main(int, char* [])
|
||||
const auto val = sqlpp::value(17);
|
||||
|
||||
SQLPP_COMPARE(exists(select(val.as(v))), "EXISTS (SELECT 17 AS v)");
|
||||
SQLPP_COMPARE(true and exists(select(val.as(v))), "1 AND EXISTS (SELECT 17 AS v)");
|
||||
SQLPP_COMPARE(exists(select(val.as(v))) and true, "EXISTS (SELECT 17 AS v) AND 1");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -45,6 +45,12 @@ int main(int, char* [])
|
||||
SQLPP_COMPARE(not val, "NOT 1");
|
||||
SQLPP_COMPARE(not expr, "NOT (17 > 15)");
|
||||
|
||||
// Combined logical expression.
|
||||
SQLPP_COMPARE(not val and not expr, "(NOT 1) AND (NOT (17 > 15))");
|
||||
SQLPP_COMPARE(not val or not expr, "(NOT 1) OR (NOT (17 > 15))");
|
||||
SQLPP_COMPARE(not (val and expr), "NOT (1 AND (17 > 15))");
|
||||
SQLPP_COMPARE(not (val or expr), "NOT (1 OR (17 > 15))");
|
||||
|
||||
// Chains are not nested in parentheses.
|
||||
SQLPP_COMPARE(val and val and val and val and val, "1 AND 1 AND 1 AND 1 AND 1");
|
||||
SQLPP_COMPARE(val or val or val or val or val, "1 OR 1 OR 1 OR 1 OR 1");
|
||||
|
@ -42,5 +42,6 @@ int main(int, char* [])
|
||||
SQLPP_COMPARE(expr.order(sqlpp::sort_type::asc), "(17 + 4) ASC");
|
||||
SQLPP_COMPARE(expr.order(sqlpp::sort_type::desc), "(17 + 4) DESC");
|
||||
|
||||
#warning: Make sure to test order_by with dynamic sort orders
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user