mirror of
https://github.com/rbock/sqlpp11.git
synced 2024-11-16 12:51:13 +08:00
Serialize tests compile and pass again
This commit is contained in:
parent
b9987ccf4d
commit
7f59918a09
@ -116,10 +116,6 @@ namespace sqlpp
|
||||
{
|
||||
using T = column_t<Table, ColumnSpec>;
|
||||
|
||||
name_to_sql_string(context, name_tag_of_t<Table>::name);
|
||||
context << '.';
|
||||
name_to_sql_string(context, name_tag_of_t<T>::name);
|
||||
|
||||
return context;
|
||||
return name_to_sql_string(context, name_tag_of_t<Table>::name) + "." + name_to_sql_string(context, name_tag_of_t<T>::name);
|
||||
}
|
||||
} // namespace sqlpp
|
||||
|
@ -87,8 +87,6 @@ namespace sqlpp
|
||||
template <typename Context, typename PreJoin, typename On>
|
||||
auto to_sql_string(Context& context, const join_t<PreJoin, On>& t) -> std::string
|
||||
{
|
||||
to_sql_string(context, t._pre_join);
|
||||
to_sql_string(context, t._on);
|
||||
return context;
|
||||
return to_sql_string(context, t._pre_join) + to_sql_string(context, t._on);
|
||||
}
|
||||
} // namespace sqlpp
|
||||
|
@ -61,16 +61,14 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context>
|
||||
auto to_sql_string(Context& context, const on_t<unconditional_t>&) -> std::string
|
||||
auto to_sql_string(Context& , const on_t<unconditional_t>&) -> std::string
|
||||
{
|
||||
return context;
|
||||
return {};
|
||||
}
|
||||
|
||||
template <typename Context, typename Expression>
|
||||
auto to_sql_string(Context& context, const on_t<Expression>& t) -> std::string
|
||||
{
|
||||
context << " ON ";
|
||||
to_sql_string(context, t._expression);
|
||||
return context;
|
||||
return " ON " + to_sql_string(context, t._expression);
|
||||
}
|
||||
} // namespace sqlpp
|
||||
|
@ -64,10 +64,9 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context, typename ValueType, typename NameType>
|
||||
auto to_sql_string(Context& context, const parameter_t<ValueType, NameType>&) -> std::string
|
||||
auto to_sql_string(Context& , const parameter_t<ValueType, NameType>&) -> std::string
|
||||
{
|
||||
context << "?";
|
||||
return context;
|
||||
return "?";
|
||||
}
|
||||
|
||||
template <typename NamedExpr>
|
||||
|
@ -71,10 +71,7 @@ namespace sqlpp
|
||||
template <typename Context, typename ValueType, typename Expr>
|
||||
auto to_sql_string(Context& context, const parameterized_verbatim_t<ValueType, Expr>& t) -> std::string
|
||||
{
|
||||
context << t._verbatim_lhs;
|
||||
to_sql_string(context, t._expr);
|
||||
context << t._verbatim_rhs;
|
||||
return context;
|
||||
return t._verbatim_lhs + to_sql_string(context, t._expr) + t._verbatim_rhs;
|
||||
}
|
||||
|
||||
template <typename ValueType, typename Expr>
|
||||
|
@ -135,11 +135,7 @@ namespace sqlpp
|
||||
template <typename Context, typename JoinType, typename Lhs, typename Rhs>
|
||||
auto to_sql_string(Context& context, const pre_join_t<JoinType, Lhs, Rhs>& t) -> std::string
|
||||
{
|
||||
to_sql_string(context, t._lhs);
|
||||
context << JoinType::_name;
|
||||
context << " JOIN ";
|
||||
to_sql_string(context, t._rhs);
|
||||
return context;
|
||||
return to_sql_string(context, t._lhs) + JoinType::_name + " JOIN " + to_sql_string(context, t._rhs);
|
||||
}
|
||||
|
||||
namespace detail
|
||||
|
@ -69,7 +69,6 @@ namespace sqlpp
|
||||
template <typename Context, typename TableSpec>
|
||||
auto to_sql_string(Context& context, const table_t<TableSpec>& /*unused*/) -> std::string
|
||||
{
|
||||
name_to_sql_string(context, name_tag_of_t<TableSpec>::name);
|
||||
return context;
|
||||
return name_to_sql_string(context, name_tag_of_t<TableSpec>::name);
|
||||
}
|
||||
} // namespace sqlpp
|
||||
|
@ -58,9 +58,7 @@ namespace sqlpp
|
||||
template <typename Context, typename AliasProvider, typename TableSpec>
|
||||
auto to_sql_string(Context& context, const table_alias_t<AliasProvider, TableSpec>&) -> std::string
|
||||
{
|
||||
name_to_sql_string(context, name_tag_of_t<TableSpec>::name);
|
||||
context << " AS ";
|
||||
return name_to_sql_string(context, name_tag_of_t<TableSpec>::name) + " AS " +
|
||||
name_to_sql_string(context, name_tag_of_t<AliasProvider>::name);
|
||||
return context;
|
||||
}
|
||||
} // namespace sqlpp
|
||||
|
@ -62,10 +62,9 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context, typename ValueType>
|
||||
auto to_sql_string(Context& context, const verbatim_t<ValueType>& t) -> std::string
|
||||
auto to_sql_string(Context& , const verbatim_t<ValueType>& t) -> std::string
|
||||
{
|
||||
context << t._verbatim;
|
||||
return context;
|
||||
return t._verbatim;
|
||||
}
|
||||
|
||||
template <typename ValueType, typename StringType>
|
||||
|
@ -57,10 +57,7 @@ namespace sqlpp
|
||||
template <typename Context, typename AliasProvider>
|
||||
auto to_sql_string(Context& context, const verbatim_table_alias_t<AliasProvider>& t) -> std::string
|
||||
{
|
||||
context << t._representation;
|
||||
context << " AS ";
|
||||
name_to_sql_string(context, name_tag_of_t<AliasProvider>::name);
|
||||
return context;
|
||||
return t._representation + " AS " + name_to_sql_string(context, name_tag_of_t<AliasProvider>::name);
|
||||
}
|
||||
|
||||
struct verbatim_table_t: public enable_join<verbatim_table_t>
|
||||
@ -90,10 +87,9 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context>
|
||||
auto to_sql_string(Context& context, const verbatim_table_t& t) -> std::string
|
||||
auto to_sql_string(Context& , const verbatim_table_t& t) -> std::string
|
||||
{
|
||||
context << t._representation;
|
||||
return context;
|
||||
return t._representation;
|
||||
}
|
||||
|
||||
inline verbatim_table_t verbatim_table(std::string name)
|
||||
|
@ -92,10 +92,9 @@ namespace sqlpp
|
||||
|
||||
// Interpreters
|
||||
template <typename Context>
|
||||
auto to_sql_string(Context& context, const for_update_data_t&) -> std::string
|
||||
auto to_sql_string(Context& , const for_update_data_t&) -> std::string
|
||||
{
|
||||
context << " FOR UPDATE ";
|
||||
return context;
|
||||
return " FOR UPDATE ";
|
||||
}
|
||||
|
||||
inline auto for_update() -> decltype(statement_t<no_for_update_t>().for_update())
|
||||
|
@ -143,9 +143,7 @@ namespace sqlpp
|
||||
template <typename Context, typename Table>
|
||||
auto to_sql_string(Context& context, const from_data_t<Table>& t) -> std::string
|
||||
{
|
||||
context << " FROM ";
|
||||
to_sql_string(context, t._table);
|
||||
return context;
|
||||
return " FROM " + to_sql_string(context, t._table);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
@ -148,9 +148,7 @@ namespace sqlpp
|
||||
template <typename Context, typename... Expressions>
|
||||
auto to_sql_string(Context& context, const group_by_data_t<Expressions...>& t) -> std::string
|
||||
{
|
||||
context << " GROUP BY ";
|
||||
interpret_tuple(t._expressions, ',', context);
|
||||
return context;
|
||||
return " GROUP BY " + interpret_tuple(t._expressions, ',', context);
|
||||
}
|
||||
|
||||
template <typename... T>
|
||||
|
@ -173,9 +173,7 @@ namespace sqlpp
|
||||
template <typename Context, typename Expression>
|
||||
auto to_sql_string(Context& context, const having_data_t<Expression>& t) -> std::string
|
||||
{
|
||||
context << " HAVING ";
|
||||
to_sql_string(context, t._expression);
|
||||
return context;
|
||||
return " HAVING " + to_sql_string(context, t._expression);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
@ -87,11 +87,9 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context>
|
||||
auto to_sql_string(Context& context, const insert_name_t&) -> std::string
|
||||
auto to_sql_string(Context& , const insert_name_t&) -> std::string
|
||||
{
|
||||
context << "INSERT";
|
||||
|
||||
return context;
|
||||
return "INSERT";
|
||||
}
|
||||
|
||||
using blank_insert_t = statement_t<insert_t, no_into_t, no_insert_value_list_t>;
|
||||
|
@ -83,12 +83,8 @@ namespace sqlpp
|
||||
{
|
||||
if (t._is_default)
|
||||
{
|
||||
context << "DEFAULT";
|
||||
return "DEFAULT";
|
||||
}
|
||||
else
|
||||
{
|
||||
operand_to_sql_string(context, t._value);
|
||||
}
|
||||
return context;
|
||||
return operand_to_sql_string(context, t._value);
|
||||
}
|
||||
} // namespace sqlpp
|
||||
|
@ -395,49 +395,47 @@ namespace sqlpp
|
||||
|
||||
// Interpreters
|
||||
template <typename Context>
|
||||
auto to_sql_string(Context& context, const insert_default_values_data_t&) -> std::string
|
||||
auto to_sql_string(Context& , const insert_default_values_data_t&) -> std::string
|
||||
{
|
||||
context << " DEFAULT VALUES";
|
||||
return context;
|
||||
return " DEFAULT VALUES";
|
||||
}
|
||||
|
||||
|
||||
template <typename Context, typename... Columns>
|
||||
auto to_sql_string(Context& context, const column_list_data_t<Columns...>& t) -> std::string
|
||||
{
|
||||
context << " (";
|
||||
interpret_tuple(t._columns, ",", context);
|
||||
context << ")";
|
||||
auto result = std::string{" ("};
|
||||
result += interpret_tuple(t._columns, ",", context);
|
||||
result += ")";
|
||||
bool first = true;
|
||||
for (const auto& row : t._insert_values)
|
||||
{
|
||||
if (first)
|
||||
{
|
||||
context << " VALUES ";
|
||||
result += " VALUES ";
|
||||
first = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
context << ',';
|
||||
result += ',';
|
||||
}
|
||||
context << '(';
|
||||
interpret_tuple(row, ",", context);
|
||||
context << ')';
|
||||
result += '(';
|
||||
result += interpret_tuple(row, ",", context);
|
||||
result += ')';
|
||||
}
|
||||
|
||||
return context;
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename Context, typename... Assignments>
|
||||
auto to_sql_string(Context& context, const insert_list_data_t<Assignments...>& t) -> std::string
|
||||
{
|
||||
context << " (";
|
||||
interpret_tuple(t._columns, ",", context);
|
||||
context << ")";
|
||||
context << " VALUES(";
|
||||
interpret_tuple(t._values, ",", context);
|
||||
context << ")";
|
||||
return context;
|
||||
auto result = std::string{" ("};
|
||||
result += interpret_tuple(t._columns, ",", context);
|
||||
result += ") VALUES(";
|
||||
result += interpret_tuple(t._values, ",", context);
|
||||
result += ")";
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename... Assignments>
|
||||
|
@ -140,13 +140,10 @@ namespace sqlpp
|
||||
};
|
||||
};
|
||||
|
||||
// Interpreters
|
||||
template <typename Context, typename Table>
|
||||
auto to_sql_string(Context& context, const into_data_t<Table>& t) -> std::string
|
||||
{
|
||||
context << " INTO ";
|
||||
to_sql_string(context, t._table);
|
||||
return context;
|
||||
return " INTO " + to_sql_string(context, t._table);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
@ -130,9 +130,7 @@ namespace sqlpp
|
||||
template <typename Context, typename Limit>
|
||||
auto to_sql_string(Context& context, const limit_data_t<Limit>& t) -> std::string
|
||||
{
|
||||
context << " LIMIT ";
|
||||
operand_to_sql_string(context, t._value);
|
||||
return context;
|
||||
return " LIMIT " + operand_to_sql_string(context, t._value);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
@ -138,13 +138,10 @@ namespace sqlpp
|
||||
};
|
||||
};
|
||||
|
||||
// Interpreters
|
||||
template <typename Context, typename Offset>
|
||||
auto to_sql_string(Context& context, const offset_data_t<Offset>& t) -> std::string
|
||||
{
|
||||
context << " OFFSET ";
|
||||
operand_to_sql_string(context, t._value);
|
||||
return context;
|
||||
return " OFFSET " + operand_to_sql_string(context, t._value);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
@ -148,9 +148,7 @@ namespace sqlpp
|
||||
template <typename Context, typename... Expressions>
|
||||
auto to_sql_string(Context& context, const order_by_data_t<Expressions...>& t) -> std::string
|
||||
{
|
||||
context << " ORDER BY ";
|
||||
interpret_tuple(t._expressions, ',', context);
|
||||
return context;
|
||||
return " ORDER BY " + interpret_tuple(t._expressions, ',', context);
|
||||
}
|
||||
|
||||
template <typename... T>
|
||||
|
@ -86,11 +86,9 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context>
|
||||
auto to_sql_string(Context& context, const remove_name_t&) -> std::string
|
||||
auto to_sql_string(Context& , const remove_name_t&) -> std::string
|
||||
{
|
||||
context << "DELETE";
|
||||
|
||||
return context;
|
||||
return "DELETE";
|
||||
}
|
||||
|
||||
using blank_remove_t = statement_t<remove_t, no_from_t, no_using_t, no_where_t<true>>;
|
||||
|
@ -55,7 +55,7 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context>
|
||||
auto to_sql_string(Context& context, const select_name_t&) -> std::string
|
||||
auto to_sql_string(Context& , const select_name_t&) -> std::string
|
||||
{
|
||||
return "SELECT ";
|
||||
}
|
||||
|
@ -54,10 +54,7 @@ namespace sqlpp
|
||||
{
|
||||
using T = pseudo_column_t<TableAliasProvider, ColumnSpec>;
|
||||
|
||||
name_to_sql_string(context, name_tag_of_t<TableAliasProvider>::name);
|
||||
context << '.';
|
||||
name_to_sql_string(context, name_tag_of_t<T>::name);
|
||||
return context;
|
||||
return name_to_sql_string(context, name_tag_of_t<TableAliasProvider>::name) + "."+ name_to_sql_string(context, name_tag_of_t<T>::name);
|
||||
}
|
||||
|
||||
template <typename Select, typename AliasProvider, typename... ColumnSpecs>
|
||||
@ -97,9 +94,6 @@ namespace sqlpp
|
||||
template <typename Context, typename Select, typename AliasProvider, typename... ColumnSpecs>
|
||||
auto to_sql_string(Context& context, const select_as_t<Select, AliasProvider, ColumnSpecs...>& t) -> std::string
|
||||
{
|
||||
operand_to_sql_string(context, t._select);
|
||||
context << " AS ";
|
||||
name_to_sql_string(context, name_tag_of_t<AliasProvider>::name);
|
||||
return context;
|
||||
return operand_to_sql_string(context, t._select) + " AS " +name_to_sql_string(context, name_tag_of_t<AliasProvider>::name);
|
||||
}
|
||||
} // namespace sqlpp
|
||||
|
@ -137,12 +137,7 @@ namespace sqlpp
|
||||
template <typename Context, typename... Flags>
|
||||
auto to_sql_string(Context& context, const select_flag_list_data_t<Flags...>& t) -> std::string
|
||||
{
|
||||
interpret_tuple(t._flags, ' ', context);
|
||||
if (sizeof...(Flags) != 0u)
|
||||
{
|
||||
context << ' ';
|
||||
}
|
||||
return context;
|
||||
return interpret_tuple(t._flags, "", context);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
@ -42,10 +42,9 @@ namespace sqlpp
|
||||
static constexpr all_t all = {};
|
||||
|
||||
template <typename Context>
|
||||
auto to_sql_string(Context& context, const all_t&) -> std::string
|
||||
auto to_sql_string(Context& , const all_t&) -> std::string
|
||||
{
|
||||
context << "ALL";
|
||||
return context;
|
||||
return "ALL ";
|
||||
}
|
||||
|
||||
struct distinct_t
|
||||
@ -56,10 +55,9 @@ namespace sqlpp
|
||||
static constexpr distinct_t distinct = {};
|
||||
|
||||
template <typename Context>
|
||||
auto to_sql_string(Context& context, const distinct_t&) -> std::string
|
||||
auto to_sql_string(Context& , const distinct_t&) -> std::string
|
||||
{
|
||||
context << "DISTINCT";
|
||||
return context;
|
||||
return "DISTINCT ";
|
||||
}
|
||||
|
||||
struct straight_join_t
|
||||
@ -69,10 +67,10 @@ namespace sqlpp
|
||||
};
|
||||
static constexpr straight_join_t straight_join = {};
|
||||
|
||||
#warning: Why is this in the select flags?
|
||||
template <typename Context>
|
||||
auto to_sql_string(Context& context, const straight_join_t&) -> std::string
|
||||
auto to_sql_string(Context& , const straight_join_t&) -> std::string
|
||||
{
|
||||
context << "STRAIGHT_JOIN";
|
||||
return context;
|
||||
return "STRAIGHT_JOIN";
|
||||
}
|
||||
} // namespace sqlpp
|
||||
|
@ -49,8 +49,7 @@ namespace sqlpp
|
||||
template <typename Context, typename Column>
|
||||
auto to_sql_string(Context& context, const simple_column_t<Column>&) -> std::string
|
||||
{
|
||||
context << name_tag_of_t<typename simple_column_t<Column>::_column_t>::name;
|
||||
return context;
|
||||
return name_to_sql_string(context, name_tag_of_t<typename simple_column_t<Column>::_column_t>::name);
|
||||
}
|
||||
|
||||
template <typename Column>
|
||||
|
@ -145,7 +145,6 @@ namespace sqlpp
|
||||
template <typename Context, typename Table>
|
||||
auto to_sql_string(Context& context, const single_table_data_t<Table>& t) -> std::string
|
||||
{
|
||||
to_sql_string(context, t._table);
|
||||
return context;
|
||||
return to_sql_string(context, t._table);
|
||||
}
|
||||
} // namespace sqlpp
|
||||
|
@ -87,10 +87,9 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context>
|
||||
auto to_sql_string(Context& context, const update_name_t&) -> std::string
|
||||
auto to_sql_string(Context& , const update_name_t&) -> std::string
|
||||
{
|
||||
context << "UPDATE ";
|
||||
return context;
|
||||
return "UPDATE ";
|
||||
}
|
||||
|
||||
using blank_update_t = statement_t<update_t, no_single_table_t, no_update_list_t, no_where_t<true>>;
|
||||
|
@ -167,8 +167,6 @@ namespace sqlpp
|
||||
template <typename Context, typename... Assignments>
|
||||
auto to_sql_string(Context& context, const update_list_data_t<Assignments...>& t) -> std::string
|
||||
{
|
||||
context << " SET ";
|
||||
interpret_tuple(t._assignments, ",", context);
|
||||
return context;
|
||||
return " SET " + interpret_tuple(t._assignments, ",", context);
|
||||
}
|
||||
} // namespace sqlpp
|
||||
|
@ -194,15 +194,13 @@ namespace sqlpp
|
||||
template <typename Context, typename Expression>
|
||||
auto to_sql_string(Context& context, const where_data_t<Expression>& t) -> std::string
|
||||
{
|
||||
context << " WHERE ";
|
||||
to_sql_string(context, t._expression);
|
||||
return context;
|
||||
return " WHERE " + to_sql_string(context, t._expression);
|
||||
}
|
||||
|
||||
template <typename Context>
|
||||
auto to_sql_string(Context& context, const where_data_t<unconditional_t>&) -> std::string
|
||||
auto to_sql_string(Context& , const where_data_t<unconditional_t>&) -> std::string
|
||||
{
|
||||
return context;
|
||||
return {};
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
@ -1,72 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
* 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 <limits>
|
||||
#include <sstream>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
#include <sqlpp11/core/compat/type_traits.h>
|
||||
|
||||
namespace sqlpp
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
template <typename T, typename = void>
|
||||
struct float_safe_ostringstream_implementation
|
||||
{
|
||||
template <typename U>
|
||||
void operator()(std::ostringstream& os, U&& x) const
|
||||
{
|
||||
os << std::forward<U>(x);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct float_safe_ostringstream_implementation<T, ::sqlpp::enable_if_t<std::is_floating_point<T>::value>>
|
||||
{
|
||||
template <typename U>
|
||||
void operator()(std::ostringstream& os, U&& x) const
|
||||
{
|
||||
auto const old_precision = os.precision(std::numeric_limits<T>::max_digits10);
|
||||
os << std::forward<U>(x);
|
||||
os.precision(old_precision);
|
||||
}
|
||||
};
|
||||
|
||||
struct float_safe_ostringstream : std::ostringstream
|
||||
{
|
||||
template <typename T>
|
||||
friend float_safe_ostringstream& operator<<(float_safe_ostringstream& os, T&& x)
|
||||
{
|
||||
float_safe_ostringstream_implementation<typename std::decay<T>::type>{}(os, x);
|
||||
return os;
|
||||
}
|
||||
};
|
||||
} // namespace detail
|
||||
} // namespace sqlpp
|
@ -54,10 +54,7 @@ namespace sqlpp
|
||||
template <typename Context, typename Expr>
|
||||
auto to_sql_string(Context& context, const lower_t<Expr>& t) -> std::string
|
||||
{
|
||||
context << "LOWER(";
|
||||
operand_to_sql_string(context, t._expr);
|
||||
context << ")";
|
||||
return context;
|
||||
return "LOWER("+ to_sql_string(context, t._expr) + ")";
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
@ -62,10 +62,7 @@ namespace sqlpp
|
||||
template <typename Context, typename Expr>
|
||||
auto to_sql_string(Context& context, const trim_t<Expr>& t) -> std::string
|
||||
{
|
||||
context << "TRIM(";
|
||||
operand_to_sql_string(context, t._expr);
|
||||
context << ")";
|
||||
return context;
|
||||
return "TRIM(" + to_sql_string(context, t._expr)+ ")";
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
@ -54,10 +54,7 @@ namespace sqlpp
|
||||
template <typename Context, typename Expr>
|
||||
auto to_sql_string(Context& context, const upper_t<Expr>& t) -> std::string
|
||||
{
|
||||
context << "UPPER(";
|
||||
operand_to_sql_string(context, t._expr);
|
||||
context << ")";
|
||||
return context;
|
||||
return "UPPER(" + to_sql_string(context, t._expr) + ")";
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
@ -43,9 +43,9 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context, typename Clause>
|
||||
auto to_sql_string(Context& context, const hidden_t<Clause>&) -> std::string
|
||||
auto to_sql_string(Context& , const hidden_t<Clause>&) -> std::string
|
||||
{
|
||||
return context;
|
||||
return {};
|
||||
}
|
||||
|
||||
template <typename Clause>
|
||||
|
@ -37,17 +37,14 @@ namespace sqlpp
|
||||
static auto interpret_tuple_element(
|
||||
const Element& element, const Separator& separator, Context& context, const UseBraces& /*unused*/, size_t index) -> std::string
|
||||
{
|
||||
if (index)
|
||||
{
|
||||
return separator;
|
||||
}
|
||||
const auto prefix = index ? std::string{separator} : std::string{};
|
||||
if (UseBraces::value)
|
||||
{
|
||||
return operand_to_sql_string(context, element);
|
||||
return prefix + operand_to_sql_string(context, element);
|
||||
}
|
||||
else
|
||||
{
|
||||
return to_sql_string(context, element);
|
||||
return prefix + to_sql_string(context, element);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,7 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context>
|
||||
auto to_sql_string(Context& context, const no_data_t&) -> std::string
|
||||
auto to_sql_string(Context& , const no_data_t&) -> std::string
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
@ -81,9 +81,9 @@ namespace sqlpp
|
||||
};
|
||||
|
||||
template <typename Context>
|
||||
auto to_sql_string(Context& context, const noop&) -> std::string
|
||||
auto to_sql_string(Context& , const noop&) -> std::string
|
||||
{
|
||||
return context;
|
||||
return {};
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
@ -77,7 +77,7 @@ namespace sqlpp
|
||||
template <typename Context, typename L, typename Operator, typename R>
|
||||
auto to_sql_string(Context& context, const bit_expression<L, Operator, R>& t) -> std::string
|
||||
{
|
||||
return to_sql_string(context, simple_column(t._l)) + Operator::symbol + operand_to_sql_string(context, t._r);
|
||||
return operand_to_sql_string(context, t._l) + Operator::symbol + operand_to_sql_string(context, t._r);
|
||||
}
|
||||
|
||||
struct bit_and
|
||||
|
@ -128,7 +128,7 @@ namespace sqlpp
|
||||
else
|
||||
{
|
||||
#warning: interpret_tuple arguments should take Context first, too
|
||||
interpret_tuple(t._r, ", ", context);
|
||||
result += interpret_tuple(t._r, ", ", context);
|
||||
}
|
||||
result += ")";
|
||||
return result;
|
||||
|
@ -84,9 +84,9 @@ namespace sqlpp
|
||||
|
||||
#warning: rename
|
||||
template <typename Context, typename L, typename Operator, typename R>
|
||||
auto serialize_impl(Context& context, const logical_expression<L, Operator, R>& t) -> Context&
|
||||
auto serialize_impl(Context& context, const logical_expression<L, Operator, R>& t) -> std::string
|
||||
{
|
||||
return operand_to_sql_string(context, simple_column(t._l)) + Operator::symbol + operand_to_sql_string(context, t._r);
|
||||
return operand_to_sql_string(context, t._l) + Operator::symbol + operand_to_sql_string(context, t._r);
|
||||
}
|
||||
|
||||
template <typename Context, typename L, typename Operator, typename R>
|
||||
@ -97,14 +97,14 @@ namespace sqlpp
|
||||
|
||||
template <typename Context, typename L, typename Operator, typename R1, typename R2>
|
||||
auto to_sql_string(Context& context,
|
||||
const logical_expression<logical_expression<L, Operator, R1>, Operator, R2>& t) -> Context&
|
||||
const logical_expression<logical_expression<L, Operator, R1>, Operator, R2>& t) -> std::string
|
||||
{
|
||||
return to_sql_string(context, t._l) + Operator::symbol + operand_to_sql_string(context, t._r);
|
||||
}
|
||||
|
||||
template <typename Context, typename L, typename Operator, typename R1, typename R2>
|
||||
auto to_sql_string(Context& context,
|
||||
const logical_expression<logical_expression<L, Operator, R1>, Operator, dynamic_t<R2>>& t) -> Context&
|
||||
const logical_expression<logical_expression<L, Operator, R1>, Operator, dynamic_t<R2>>& t) -> std::string
|
||||
{
|
||||
if (t._r._condition)
|
||||
{
|
||||
|
@ -67,7 +67,7 @@ namespace sqlpp
|
||||
struct is_sort_order<sort_order_expression<L>> : std::true_type {};
|
||||
|
||||
template <typename Context>
|
||||
auto to_sql_string(Context& context, const sort_type& t) -> std::string
|
||||
auto to_sql_string(Context& , const sort_type& t) -> std::string
|
||||
{
|
||||
switch (t)
|
||||
{
|
||||
|
@ -124,8 +124,7 @@ namespace sqlpp
|
||||
template <typename Context, typename... Parts>
|
||||
auto to_sql_string(Context& context, const custom_query_t<Parts...>& t) -> std::string
|
||||
{
|
||||
interpret_tuple_without_braces(t._parts, " ", context);
|
||||
return context;
|
||||
return interpret_tuple_without_braces(t._parts, " ", context);
|
||||
}
|
||||
|
||||
template <typename... Parts>
|
||||
|
@ -79,27 +79,19 @@ namespace sqlpp
|
||||
{
|
||||
if (t._condition)
|
||||
{
|
||||
to_sql_string(context, t._expr);
|
||||
return to_sql_string(context, t._expr);
|
||||
}
|
||||
else
|
||||
{
|
||||
to_sql_string(context, ::sqlpp::nullopt);
|
||||
}
|
||||
return context;
|
||||
return to_sql_string(context, ::sqlpp::nullopt);
|
||||
}
|
||||
|
||||
template <typename Context, typename Select>
|
||||
Context& operand_to_sql_string(Context& context, const dynamic_t<Select>& t)
|
||||
auto operand_to_sql_string(Context& context, const dynamic_t<Select>& t) -> std::string
|
||||
{
|
||||
if (t._condition)
|
||||
{
|
||||
operand_to_sql_string(context, t._expr);
|
||||
return operand_to_sql_string(context, t._expr);
|
||||
}
|
||||
else
|
||||
{
|
||||
to_sql_string(context, ::sqlpp::nullopt);
|
||||
}
|
||||
return context;
|
||||
return to_sql_string(context, ::sqlpp::nullopt);
|
||||
}
|
||||
|
||||
template <typename Expr>
|
||||
|
@ -47,73 +47,73 @@ namespace sqlpp
|
||||
}
|
||||
|
||||
template <typename Context>
|
||||
auto to_sql_string(Context& context, const bool& t) -> std::string
|
||||
auto to_sql_string(Context& , const bool& t) -> std::string
|
||||
{
|
||||
return std::to_string(t);
|
||||
}
|
||||
|
||||
template <typename Context>
|
||||
auto to_sql_string(Context& context, const int8_t& t) -> std::string
|
||||
auto to_sql_string(Context& , const int8_t& t) -> std::string
|
||||
{
|
||||
return std::to_string(t);
|
||||
}
|
||||
|
||||
template <typename Context>
|
||||
auto to_sql_string(Context& context, const int16_t& t) -> std::string
|
||||
auto to_sql_string(Context& , const int16_t& t) -> std::string
|
||||
{
|
||||
return std::to_string(t);
|
||||
}
|
||||
|
||||
template <typename Context>
|
||||
auto to_sql_string(Context& context, const int32_t& t) -> std::string
|
||||
auto to_sql_string(Context& , const int32_t& t) -> std::string
|
||||
{
|
||||
return std::to_string(t);
|
||||
}
|
||||
|
||||
template <typename Context>
|
||||
auto to_sql_string(Context& context, const int64_t& t) -> std::string
|
||||
auto to_sql_string(Context& , const int64_t& t) -> std::string
|
||||
{
|
||||
return std::to_string(t);
|
||||
}
|
||||
|
||||
template <typename Context>
|
||||
auto to_sql_string(Context& context, const uint8_t& t) -> std::string
|
||||
auto to_sql_string(Context& , const uint8_t& t) -> std::string
|
||||
{
|
||||
return std::to_string(t);
|
||||
}
|
||||
|
||||
template <typename Context>
|
||||
auto to_sql_string(Context& context, const uint16_t& t) -> std::string
|
||||
auto to_sql_string(Context& , const uint16_t& t) -> std::string
|
||||
{
|
||||
return std::to_string(t);
|
||||
}
|
||||
|
||||
template <typename Context>
|
||||
auto to_sql_string(Context& context, const uint32_t& t) -> std::string
|
||||
auto to_sql_string(Context& , const uint32_t& t) -> std::string
|
||||
{
|
||||
return std::to_string(t);
|
||||
}
|
||||
|
||||
template <typename Context>
|
||||
auto to_sql_string(Context& context, const uint64_t& t) -> std::string
|
||||
auto to_sql_string(Context& , const uint64_t& t) -> std::string
|
||||
{
|
||||
return std::to_string(t);
|
||||
}
|
||||
|
||||
template <typename Context>
|
||||
auto nan_to_sql_string(Context& context) -> std::string
|
||||
auto nan_to_sql_string(Context& ) -> std::string
|
||||
{
|
||||
throw ::sqlpp::exception("Serialization of NaN is not supported by this connector");
|
||||
}
|
||||
|
||||
template <typename Context>
|
||||
auto inf_to_sql_string(Context& context) -> std::string
|
||||
auto inf_to_sql_string(Context& ) -> std::string
|
||||
{
|
||||
throw ::sqlpp::exception("Serialization of Infinity is not supported by this connector");
|
||||
}
|
||||
|
||||
template <typename Context>
|
||||
auto neg_inf_to_sql_string(Context& context) -> std::string
|
||||
auto neg_inf_to_sql_string(Context& ) -> std::string
|
||||
{
|
||||
throw ::sqlpp::exception("Serialization of Infinity is not supported by this connector");
|
||||
}
|
||||
@ -133,7 +133,7 @@ namespace sqlpp
|
||||
{
|
||||
// TODO: Once gcc and clang support to_chars, try that
|
||||
auto oss = std::ostringstream{};
|
||||
oss << std::setprecision(std::numeric_limits<long double>::digits10 + 1) << f;
|
||||
oss << std::setprecision(std::numeric_limits<T>::max_digits10) << f;
|
||||
return oss.str();
|
||||
}
|
||||
}
|
||||
@ -141,26 +141,23 @@ namespace sqlpp
|
||||
template <typename Context>
|
||||
auto to_sql_string(Context& context, const float& t) -> std::string
|
||||
{
|
||||
context << t;
|
||||
return context;
|
||||
return float_to_sql_string(context, t);
|
||||
}
|
||||
|
||||
template <typename Context>
|
||||
auto to_sql_string(Context& context, const double& t) -> std::string
|
||||
{
|
||||
context << t;
|
||||
return context;
|
||||
return float_to_sql_string(context, t);
|
||||
}
|
||||
|
||||
template <typename Context>
|
||||
auto to_sql_string(Context& context, const long double& t) -> std::string
|
||||
{
|
||||
context << t;
|
||||
return context;
|
||||
return float_to_sql_string(context, t);
|
||||
}
|
||||
|
||||
template <typename Context>
|
||||
auto to_sql_string(Context& context, const ::sqlpp::string_view& t) -> std::string
|
||||
auto to_sql_string(Context& , const ::sqlpp::string_view& t) -> std::string
|
||||
{
|
||||
auto result = std::string{"'"};
|
||||
result.reserve(t.size() * 2);
|
||||
@ -194,7 +191,7 @@ namespace sqlpp
|
||||
}
|
||||
|
||||
template <typename Context>
|
||||
auto to_sql_string(Context& context, const ::sqlpp::span<uint8_t>& t) -> std::string
|
||||
auto to_sql_string(Context& , const ::sqlpp::span<uint8_t>& t) -> std::string
|
||||
{
|
||||
constexpr char hexChars[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
|
||||
auto result = std::string{"x'"};
|
||||
@ -248,7 +245,7 @@ namespace sqlpp
|
||||
}
|
||||
|
||||
template <typename Context>
|
||||
auto to_sql_string(Context& context, const ::sqlpp::nullopt_t&) -> std::string
|
||||
auto to_sql_string(Context&, const ::sqlpp::nullopt_t&) -> std::string
|
||||
{
|
||||
return "NULL";
|
||||
}
|
||||
@ -274,7 +271,7 @@ namespace sqlpp
|
||||
}
|
||||
|
||||
template <typename Context>
|
||||
auto name_to_sql_string(Context& context, const char* t) -> std::string
|
||||
auto name_to_sql_string(Context& , const char* t) -> std::string
|
||||
{
|
||||
#warning: We used to have a version of SQLPP_ALIAS_PROVIDER that escaped the name
|
||||
|
||||
|
@ -32,18 +32,10 @@
|
||||
|
||||
namespace
|
||||
{
|
||||
/*
|
||||
auto getTrue() -> std::string
|
||||
{
|
||||
MockDb::_serializer_context_t printer = {};
|
||||
return to_sql_string(sqlpp::value(true), printer).str();
|
||||
}
|
||||
*/
|
||||
|
||||
auto getFalse() -> std::string
|
||||
{
|
||||
MockDb::_serializer_context_t printer = {};
|
||||
return to_sql_string(printer, sqlpp::value(false)).str();
|
||||
return to_sql_string(printer, sqlpp::value(false));
|
||||
}
|
||||
|
||||
auto toByteVector(const std::string& s) -> std::vector<std::uint8_t>
|
||||
@ -59,11 +51,11 @@ int Blob(int, char*[])
|
||||
|
||||
// Unconditionally
|
||||
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')");
|
||||
"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'}};
|
||||
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')");
|
||||
"SELECT tab_foo.blob_n FROM tab_foo WHERE tab_foo.blob_n = x'6A6F686E20646F65'");
|
||||
|
||||
#warning: This should go somewhere else
|
||||
// Never
|
||||
|
@ -46,8 +46,8 @@ int CustomQuery(int, char*[])
|
||||
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)),
|
||||
"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 "
|
||||
"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 "
|
||||
"LIMIT 10 OFFSET 100");
|
||||
|
||||
// A full select statement made individual clauses
|
||||
@ -56,8 +56,8 @@ int CustomQuery(int, char*[])
|
||||
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 "
|
||||
"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
|
||||
@ -73,7 +73,7 @@ int CustomQuery(int, char*[])
|
||||
.where(not exists(select(foo.doubleN).from(foo).where(foo.doubleN == x)))),
|
||||
"INSERT INTO tab_foo (double_n) "
|
||||
"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)))");
|
||||
"WHERE NOT EXISTS (SELECT tab_foo.double_n FROM tab_foo WHERE tab_foo.double_n = 17)");
|
||||
|
||||
#warning : reactivate
|
||||
#if 0
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016-2019, Roland Bock
|
||||
* Copyright (c) 2016, Roland Bock
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
@ -38,7 +38,7 @@ int DynamicWhere(int, char*[])
|
||||
SQLPP_COMPARE(sqlpp::unconditionally(), "");
|
||||
SQLPP_COMPARE(where(bar.boolNn), " 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(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;
|
||||
|
@ -23,7 +23,6 @@
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sqlpp11/core/detail/float_safe_ostringstream.h>
|
||||
#include <sqlpp11/sqlpp11.h>
|
||||
|
||||
#include "compare.h"
|
||||
@ -43,11 +42,11 @@ namespace
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void float_safe_ostringstream_serializes_in_deserializable_format(int line, T value)
|
||||
void to_sql_string_serializes_in_deserializable_format(int line, T value)
|
||||
{
|
||||
sqlpp::detail::float_safe_ostringstream os;
|
||||
os << value;
|
||||
std::istringstream is{os.str()};
|
||||
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);
|
||||
@ -73,9 +72,9 @@ namespace
|
||||
int Float(int, char*[])
|
||||
{
|
||||
#warning: document that connectors need to use float_safe_ostringstream or similar.
|
||||
float_safe_ostringstream_serializes_in_deserializable_format(__LINE__, 10.0000086f);
|
||||
float_safe_ostringstream_serializes_in_deserializable_format(__LINE__, 10.0000086);
|
||||
float_safe_ostringstream_serializes_in_deserializable_format(__LINE__, 10.0000086l);
|
||||
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.0000086f, string_for_10_0000086<float>());
|
||||
|
@ -47,29 +47,29 @@ int From(int, char* [])
|
||||
// Static joins
|
||||
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)");
|
||||
" FROM tab_foo INNER JOIN tab_bar ON tab_foo.double_n > tab_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)");
|
||||
" FROM tab_foo INNER JOIN tab_bar ON tab_foo.double_n > tab_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)");
|
||||
" FROM tab_foo OUTER JOIN tab_bar ON tab_foo.double_n > tab_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)");
|
||||
" FROM tab_foo LEFT OUTER JOIN tab_bar ON tab_foo.double_n > tab_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)");
|
||||
" FROM tab_foo RIGHT OUTER JOIN tab_bar ON tab_foo.double_n > tab_bar.id");
|
||||
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)");
|
||||
" FROM tab_foo AS a INNER JOIN tab_foo AS b ON a.double_n > b.double_n");
|
||||
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)");
|
||||
" 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");
|
||||
SQLPP_COMPARE(from(foo.join(bar).unconditionally()), " FROM tab_foo INNER JOIN tab_bar");
|
||||
|
||||
// Static joins involving verbatim tables
|
||||
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)");
|
||||
" FROM tab_foo AS a INNER JOIN unknown_table ON a.double_n > unknown_table.column_x");
|
||||
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)");
|
||||
" FROM unknown_table INNER JOIN tab_foo AS a ON a.double_n > unknown_table.column_x");
|
||||
SQLPP_COMPARE(from(sqlpp::verbatim_table("unknown_table")
|
||||
.as(sqlpp::alias::a)
|
||||
.join(sqlpp::verbatim_table("another_table"))
|
||||
|
@ -34,7 +34,7 @@ namespace
|
||||
auto getTrue() -> std::string
|
||||
{
|
||||
MockDb::_serializer_context_t printer = {};
|
||||
return to_sql_string(printer, sqlpp::value(true)).str();
|
||||
return to_sql_string(printer, sqlpp::value(true));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -35,11 +35,10 @@ int Lower(int, char* [])
|
||||
SQLPP_COMPARE(lower(bar.textN), "LOWER(tab_bar.text_n)");
|
||||
|
||||
// Expression.
|
||||
#warning: Note that the inner parens aren't necessary.
|
||||
SQLPP_COMPARE(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.
|
||||
SQLPP_COMPARE(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;
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ int Parameter(int, char*[])
|
||||
const auto bar = test::TabBar{};
|
||||
|
||||
SQLPP_COMPARE(parameter(foo.doubleN), "?");
|
||||
SQLPP_COMPARE(bar.id > parameter(foo.doubleN), "(tab_bar.id > ?)");
|
||||
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?)
|
||||
|
||||
|
@ -39,7 +39,7 @@ int SelectFlags(int, char*[])
|
||||
#warning: This should work
|
||||
//SQLPP_COMPARE(sqlpp::select_flags(), "");
|
||||
|
||||
// No flags
|
||||
// One flag
|
||||
SQLPP_COMPARE(select(foo.doubleN).flags(sqlpp::distinct), "SELECT DISTINCT tab_foo.double_n");
|
||||
|
||||
// One flag
|
||||
|
@ -35,11 +35,10 @@ int Trim(int, char* [])
|
||||
SQLPP_COMPARE(trim(bar.textN), "TRIM(tab_bar.text_n)");
|
||||
|
||||
// Expression.
|
||||
#warning: Note that the inner parens aren't necessary.
|
||||
SQLPP_COMPARE(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.
|
||||
SQLPP_COMPARE(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;
|
||||
}
|
||||
|
@ -35,11 +35,10 @@ int Upper(int, char* [])
|
||||
SQLPP_COMPARE(upper(bar.textN), "UPPER(tab_bar.text_n)");
|
||||
|
||||
// Expression.
|
||||
#warning: Note that the inner parens aren't necessary.
|
||||
SQLPP_COMPARE(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.
|
||||
SQLPP_COMPARE(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;
|
||||
}
|
||||
|
@ -34,13 +34,13 @@ namespace
|
||||
auto getTrue() -> std::string
|
||||
{
|
||||
MockDb::_serializer_context_t printer = {};
|
||||
return to_sql_string(printer, sqlpp::value(true)).str();
|
||||
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)).str();
|
||||
return to_sql_string(printer, sqlpp::value(false));
|
||||
}
|
||||
} // namespace
|
||||
|
||||
@ -74,23 +74,23 @@ int Where(int, char*[])
|
||||
|
||||
// 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(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')");
|
||||
" 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)");
|
||||
" 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')");
|
||||
" 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)");
|
||||
" 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')");
|
||||
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')");
|
||||
SQLPP_COMPARE(where(bar.textN == ::sqlpp::string_view("SQL")), " WHERE tab_bar.text_n = 'SQL'");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ int main(int, char* [])
|
||||
SQLPP_COMPARE(val.not_in(select(val.as(v))), "17 NOT IN (SELECT 17 AS v)");
|
||||
|
||||
// IN expressions with multiple arguments require inner parentheses.
|
||||
SQLPP_COMPARE(val.in(1, select(val.as(v))), "17 IN (1, (SELECT 17 AS v))");
|
||||
SQLPP_COMPARE(val.in(1, select(val.as(v)), 23), "17 IN (1, (SELECT 17 AS v), 23)");
|
||||
SQLPP_COMPARE(val.in(std::vector<int>{17, 18, 19}), "17 IN (17, 18, 19)");
|
||||
SQLPP_COMPARE(val.in(std::vector<expr_t>{expr, expr, expr}), "17 IN ((17 + 4), (17 + 4), (17 + 4))");
|
||||
|
||||
|
@ -27,7 +27,6 @@
|
||||
|
||||
#include <iostream>
|
||||
#include <sqlpp11/core/database/connection.h>
|
||||
#include <sqlpp11/core/detail/float_safe_ostringstream.h>
|
||||
#include <sqlpp11/core/database/transaction.h>
|
||||
#include <sqlpp11/core/basic/schema.h>
|
||||
#include <sqlpp11/core/to_sql_string.h>
|
||||
@ -48,7 +47,7 @@ struct MockDb : public sqlpp::connection
|
||||
|
||||
struct _serializer_context_t
|
||||
{
|
||||
::sqlpp::detail::float_safe_ostringstream _os;
|
||||
::std::ostringstream _os;
|
||||
|
||||
_serializer_context_t() = default;
|
||||
_serializer_context_t(const _serializer_context_t& rhs)
|
||||
@ -66,8 +65,9 @@ struct MockDb : public sqlpp::connection
|
||||
_os.str("");
|
||||
}
|
||||
|
||||
#warning This can be removed, I guess
|
||||
template <typename T>
|
||||
::sqlpp::detail::float_safe_ostringstream& operator<<(T t)
|
||||
::std::ostringstream& operator<<(T t)
|
||||
{
|
||||
return _os << t;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user