From 5a8f43110e1602de877c98b0275d8d87c08a9f14 Mon Sep 17 00:00:00 2001 From: bergmann Date: Sat, 11 May 2019 19:40:10 +0200 Subject: [PATCH] * added method to build a simple query to mariadb driver * fixed some compiler errors --- include/cpphibernate/driver/mariadb/impl/where.h | 14 +++++++------- include/cpphibernate/driver/mariadb/mariadb.h | 13 ++++++++++++- include/cpphibernate/types.h | 4 +++- src/cpphibernate/types.cpp | 9 ++++++++- 4 files changed, 30 insertions(+), 10 deletions(-) diff --git a/include/cpphibernate/driver/mariadb/impl/where.h b/include/cpphibernate/driver/mariadb/impl/where.h index 6db3582..a8ef2bc 100644 --- a/include/cpphibernate/driver/mariadb/impl/where.h +++ b/include/cpphibernate/driver/mariadb/impl/where.h @@ -30,13 +30,13 @@ beg_namespace_cpphibernate_driver_mariadb -> mp::enable_if>> { os << "("; - build_clause(os, p_clause.clauses[hana::size_c<0>]); + build_clause(p_clause.clauses[hana::size_c<0>]); os << ")"; hana::for_each( hana::remove_at(p_clause.clauses, hana::size_c<0>), - [&](auto& x_clause) { + [this](auto&& x_clause) { os << " AND ("; - build_clause(os, x_clause); + build_clause(x_clause); os << ")"; }); } @@ -46,13 +46,13 @@ beg_namespace_cpphibernate_driver_mariadb -> mp::enable_if>> { os << "("; - build_clause(os, p_clause.clauses[hana::size_c<0>]); + build_clause(p_clause.clauses[hana::size_c<0>]); os << ")"; hana::for_each( hana::remove_at(p_clause.clauses, hana::size_c<0>), - [&](auto& x_clause) { + [this](auto&& x_clause) { os << " OR ("; - build_clause(os, x_clause); + build_clause(x_clause); os << ")"; }); } @@ -62,7 +62,7 @@ beg_namespace_cpphibernate_driver_mariadb -> mp::enable_if>> { os << "NOT ("; - build_clause(os, p_clause.clause); + build_clause(p_clause.clause); os << ")"; } diff --git a/include/cpphibernate/driver/mariadb/mariadb.h b/include/cpphibernate/driver/mariadb/mariadb.h index 4de1e66..8b95bd5 100644 --- a/include/cpphibernate/driver/mariadb/mariadb.h +++ b/include/cpphibernate/driver/mariadb/mariadb.h @@ -49,6 +49,17 @@ beg_namespace_cpphibernate_driver_mariadb inline lock_type lock() { return std::make_unique(*_connection); } + template + inline std::string build_query(const std::string& query, T_modifiers&& modifiers) const + { + auto where = build_where(_schema, modifiers).query(*_connection); + std::ostringstream os; + os << query; + if (!where.empty()) + os << " " << where; + return os.str(); + } + protected: inline void init_impl(bool recreate) const { @@ -106,4 +117,4 @@ beg_namespace_cpphibernate_driver_mariadb }; } -end_namespace_cpphibernate_driver_mariadb \ No newline at end of file +end_namespace_cpphibernate_driver_mariadb diff --git a/include/cpphibernate/types.h b/include/cpphibernate/types.h index a47b14f..9f7d2d2 100644 --- a/include/cpphibernate/types.h +++ b/include/cpphibernate/types.h @@ -65,9 +65,11 @@ beg_namespace_cpphibernate void to_string(std::ostream& os) const; + std::ostream& operator<<(std::ostream& os) const; + public: static bool from_string(const std::string& str, uuid& val); }; } -end_namespace_cpphibernate \ No newline at end of file +end_namespace_cpphibernate diff --git a/src/cpphibernate/types.cpp b/src/cpphibernate/types.cpp index a2a9256..fdfce8f 100644 --- a/src/cpphibernate/types.cpp +++ b/src/cpphibernate/types.cpp @@ -1,4 +1,5 @@ #include +#include #include @@ -28,6 +29,12 @@ void uuid::to_string(std::ostream& os) const << std::setw(2) << std::setfill('0') << std::hex << (int)(*this)[15]; } +std::ostream& uuid::operator<<(std::ostream& os) const +{ + to_string(os); + return os; +} + bool uuid::from_string(const std::string& str, uuid& val) { const char* c = str.data(); @@ -51,4 +58,4 @@ bool uuid::from_string(const std::string& str, uuid& val) if (i != 32 || c != e) return false; return true; -} \ No newline at end of file +}