浏览代码

* added method to build a simple query to mariadb driver

* fixed some compiler errors
master
bergmann 7 年前
父节点
当前提交
5a8f43110e
共有 4 个文件被更改,包括 30 次插入10 次删除
  1. +7
    -7
      include/cpphibernate/driver/mariadb/impl/where.h
  2. +12
    -1
      include/cpphibernate/driver/mariadb/mariadb.h
  3. +3
    -1
      include/cpphibernate/types.h
  4. +8
    -1
      src/cpphibernate/types.cpp

+ 7
- 7
include/cpphibernate/driver/mariadb/impl/where.h 查看文件

@@ -30,13 +30,13 @@ beg_namespace_cpphibernate_driver_mariadb
-> mp::enable_if<modifier::is_where_clause_and<mp::decay_t<T_clause>>> -> mp::enable_if<modifier::is_where_clause_and<mp::decay_t<T_clause>>>
{ {
os << "("; os << "(";
build_clause(os, p_clause.clauses[hana::size_c<0>]);
build_clause(p_clause.clauses[hana::size_c<0>]);
os << ")"; os << ")";
hana::for_each( hana::for_each(
hana::remove_at(p_clause.clauses, hana::size_c<0>), hana::remove_at(p_clause.clauses, hana::size_c<0>),
[&](auto& x_clause) {
[this](auto&& x_clause) {
os << " AND ("; os << " AND (";
build_clause(os, x_clause);
build_clause(x_clause);
os << ")"; os << ")";
}); });
} }
@@ -46,13 +46,13 @@ beg_namespace_cpphibernate_driver_mariadb
-> mp::enable_if<modifier::is_where_clause_or<mp::decay_t<T_clause>>> -> mp::enable_if<modifier::is_where_clause_or<mp::decay_t<T_clause>>>
{ {
os << "("; os << "(";
build_clause(os, p_clause.clauses[hana::size_c<0>]);
build_clause(p_clause.clauses[hana::size_c<0>]);
os << ")"; os << ")";
hana::for_each( hana::for_each(
hana::remove_at(p_clause.clauses, hana::size_c<0>), hana::remove_at(p_clause.clauses, hana::size_c<0>),
[&](auto& x_clause) {
[this](auto&& x_clause) {
os << " OR ("; os << " OR (";
build_clause(os, x_clause);
build_clause(x_clause);
os << ")"; os << ")";
}); });
} }
@@ -62,7 +62,7 @@ beg_namespace_cpphibernate_driver_mariadb
-> mp::enable_if<modifier::is_where_clause_not<mp::decay_t<T_clause>>> -> mp::enable_if<modifier::is_where_clause_not<mp::decay_t<T_clause>>>
{ {
os << "NOT ("; os << "NOT (";
build_clause(os, p_clause.clause);
build_clause(p_clause.clause);
os << ")"; os << ")";
} }




+ 12
- 1
include/cpphibernate/driver/mariadb/mariadb.h 查看文件

@@ -49,6 +49,17 @@ beg_namespace_cpphibernate_driver_mariadb
inline lock_type lock() inline lock_type lock()
{ return std::make_unique<transaction_lock>(*_connection); } { return std::make_unique<transaction_lock>(*_connection); }


template<typename T_modifiers>
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: protected:
inline void init_impl(bool recreate) const inline void init_impl(bool recreate) const
{ {
@@ -106,4 +117,4 @@ beg_namespace_cpphibernate_driver_mariadb
}; };


} }
end_namespace_cpphibernate_driver_mariadb
end_namespace_cpphibernate_driver_mariadb

+ 3
- 1
include/cpphibernate/types.h 查看文件

@@ -65,9 +65,11 @@ beg_namespace_cpphibernate


void to_string(std::ostream& os) const; void to_string(std::ostream& os) const;


std::ostream& operator<<(std::ostream& os) const;

public: public:
static bool from_string(const std::string& str, uuid& val); static bool from_string(const std::string& str, uuid& val);
}; };


} }
end_namespace_cpphibernate
end_namespace_cpphibernate

+ 8
- 1
src/cpphibernate/types.cpp 查看文件

@@ -1,4 +1,5 @@
#include <iomanip> #include <iomanip>
#include <sstream>


#include <cpphibernate/types.h> #include <cpphibernate/types.h>


@@ -28,6 +29,12 @@ void uuid::to_string(std::ostream& os) const
<< std::setw(2) << std::setfill('0') << std::hex << (int)(*this)[15]; << 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) bool uuid::from_string(const std::string& str, uuid& val)
{ {
const char* c = str.data(); const char* c = str.data();
@@ -51,4 +58,4 @@ bool uuid::from_string(const std::string& str, uuid& val)
if (i != 32 || c != e) if (i != 32 || c != e)
return false; return false;
return true; return true;
}
}

正在加载...
取消
保存