0
0
mirror of https://github.com/rbock/sqlpp11.git synced 2024-11-16 12:51:13 +08:00

Continued migration

This commit is contained in:
Roland Bock 2024-08-10 15:54:32 +02:00
parent e17e9aebde
commit b9987ccf4d
8 changed files with 31 additions and 24 deletions

View File

@ -60,9 +60,7 @@ namespace sqlpp
auto to_sql_string(Context& context, const value_t<T>& t) -> std::string auto to_sql_string(Context& context, const value_t<T>& t) -> std::string
{ {
#warning: Untested #warning: Untested
to_sql_string(context, t._value); return to_sql_string(context, t._value);
return context;
} }
template <typename T, typename = check_value_arg<T>> template <typename T, typename = check_value_arg<T>>

View File

@ -57,9 +57,7 @@ namespace sqlpp
template <typename Context> template <typename Context>
auto to_sql_string(Context& context, const select_name_t&) -> std::string auto to_sql_string(Context& context, const select_name_t&) -> std::string
{ {
context << "SELECT "; return "SELECT ";
return context;
} }
using blank_select_t = statement_t<no_with_t, using blank_select_t = statement_t<no_with_t,

View File

@ -311,8 +311,7 @@ namespace sqlpp
template <typename Context, typename... Columns> template <typename Context, typename... Columns>
auto to_sql_string(Context& context, const std::tuple<Columns...>& t) -> std::string auto to_sql_string(Context& context, const std::tuple<Columns...>& t) -> std::string
{ {
interpret_tuple(t, ',', context); return interpret_tuple(t, ",", context);
return context;
} }
template <typename... T> template <typename... T>

View File

@ -34,20 +34,20 @@
namespace sqlpp namespace sqlpp
{ {
template <typename Element, typename Separator, typename Context, typename UseBraces> template <typename Element, typename Separator, typename Context, typename UseBraces>
static void interpret_tuple_element( static auto interpret_tuple_element(
const Element& element, const Separator& separator, Context& context, const UseBraces& /*unused*/, size_t index) const Element& element, const Separator& separator, Context& context, const UseBraces& /*unused*/, size_t index) -> std::string
{ {
if (index) if (index)
{ {
context << separator; return separator;
} }
if (UseBraces::value) if (UseBraces::value)
{ {
operand_to_sql_string(context, element); return operand_to_sql_string(context, element);
} }
else else
{ {
to_sql_string(context, element); return to_sql_string(context, element);
} }
} }
@ -57,7 +57,7 @@ namespace sqlpp
Context& context, Context& context,
const UseBraces& useBraces, const UseBraces& useBraces,
const ::sqlpp::index_sequence<Is...> & const ::sqlpp::index_sequence<Is...> &
/*unused*/) -> Context& /*unused*/) -> std::string
{ {
// Note: A braced-init-list does guarantee the order of evaluation according to 12.6.1 [class.explicit.init] // Note: A braced-init-list does guarantee the order of evaluation according to 12.6.1 [class.explicit.init]
// paragraph 2 and 8.5.4 [dcl.init.list] paragraph 4. // paragraph 2 and 8.5.4 [dcl.init.list] paragraph 4.
@ -65,21 +65,22 @@ namespace sqlpp
// See also: "http://stackoverflow.com/questions/6245735/pretty-print-stdtuple/6245777#6245777" // See also: "http://stackoverflow.com/questions/6245735/pretty-print-stdtuple/6245777#6245777"
// Beware of gcc-bug: "http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51253", otherwise an empty swallow struct could // Beware of gcc-bug: "http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51253", otherwise an empty swallow struct could
// be used // be used
auto result = std::string{};
using swallow = int[]; using swallow = int[];
(void)swallow{0, // workaround against -Wpedantic GCC warning "zero-size array 'int [0]'" (void)swallow{0, // workaround against -Wpedantic GCC warning "zero-size array 'int [0]'"
(interpret_tuple_element(std::get<Is>(t), separator, context, useBraces, Is), 0)...}; (result += interpret_tuple_element(std::get<Is>(t), separator, context, useBraces, Is), 0)...};
return context; return result;
} }
template <typename Tuple, typename Separator, typename Context> template <typename Tuple, typename Separator, typename Context>
auto interpret_tuple(const Tuple& t, const Separator& separator, Context& context) -> Context& auto interpret_tuple(const Tuple& t, const Separator& separator, Context& context) -> std::string
{ {
return interpret_tuple_impl(t, separator, context, std::true_type{}, return interpret_tuple_impl(t, separator, context, std::true_type{},
::sqlpp::make_index_sequence<std::tuple_size<Tuple>::value>{}); ::sqlpp::make_index_sequence<std::tuple_size<Tuple>::value>{});
} }
template <typename Tuple, typename Separator, typename Context> template <typename Tuple, typename Separator, typename Context>
auto interpret_tuple_without_braces(const Tuple& t, const Separator& separator, Context& context) -> Context& auto interpret_tuple_without_braces(const Tuple& t, const Separator& separator, Context& context) -> std::string
{ {
return interpret_tuple_impl(t, separator, context, std::false_type{}, return interpret_tuple_impl(t, separator, context, std::false_type{},
::sqlpp::make_index_sequence<std::tuple_size<Tuple>::value>{}); ::sqlpp::make_index_sequence<std::tuple_size<Tuple>::value>{});

View File

@ -36,6 +36,6 @@ namespace sqlpp
template <typename Context> template <typename Context>
auto to_sql_string(Context& context, const no_data_t&) -> std::string auto to_sql_string(Context& context, const no_data_t&) -> std::string
{ {
return context; return {};
} }
} // namespace sqlpp } // namespace sqlpp

View File

@ -281,10 +281,13 @@ namespace sqlpp
{ {
using P = detail::statement_policies_t<Policies...>; using P = detail::statement_policies_t<Policies...>;
auto result = std::string{};
using swallow = int[]; using swallow = int[];
(void)swallow{0, (to_sql_string(context, static_cast<const typename Policies::template _base_t<P>&>(t)._data), 0)...}; (void)swallow{
0,
(result += to_sql_string(context, static_cast<const typename Policies::template _base_t<P>&>(t)._data), 0)...};
return context; return result;
} }
template <typename NameData, typename Tag = tag::is_noop> template <typename NameData, typename Tag = tag::is_noop>

View File

@ -26,6 +26,14 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include <string>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <sqlpp11/core/compat/optional.h>
#include <sqlpp11/core/compat/span.h>
#include <sqlpp11/core/compat/string_view.h>
#include <sqlpp11/core/type_traits.h> #include <sqlpp11/core/type_traits.h>
#include <sqlpp11/core/database/exception.h> #include <sqlpp11/core/database/exception.h>
@ -156,7 +164,7 @@ namespace sqlpp
{ {
auto result = std::string{"'"}; auto result = std::string{"'"};
result.reserve(t.size() * 2); result.reserve(t.size() * 2);
for (const auto c : s) for (const auto c : t)
{ {
if (c == '\'') if (c == '\'')
result.push_back(c); // Escaping result.push_back(c); // Escaping

View File

@ -33,8 +33,8 @@
{ \ { \
MockDb::_serializer_context_t printer = {}; \ MockDb::_serializer_context_t printer = {}; \
\ \
using sqlpp::serialize; \ using sqlpp::to_sql_string; \
const auto result = to_sql_string(printer, expr).str(); \ const auto result = to_sql_string(printer, expr); \
\ \
if (result != expected_string) \ if (result != expected_string) \
{ \ { \