소스 검색

* 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>>>
{
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<modifier::is_where_clause_or<mp::decay_t<T_clause>>>
{
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<modifier::is_where_clause_not<mp::decay_t<T_clause>>>
{
os << "NOT (";
build_clause(os, p_clause.clause);
build_clause(p_clause.clause);
os << ")";
}



+ 12
- 1
include/cpphibernate/driver/mariadb/mariadb.h 파일 보기

@@ -49,6 +49,17 @@ beg_namespace_cpphibernate_driver_mariadb
inline lock_type lock()
{ 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:
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;

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

public:
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 <sstream>

#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::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;
}
}

불러오는 중...
취소
저장