1
0
Fork 0
mirror of https://github.com/KingDuckZ/dindexer.git synced 2025-07-02 14:04:22 +00:00

Fix build error when passing a vector<string_ref> to query()

This commit is contained in:
King_DuckZ 2016-05-13 20:46:13 +02:00
parent 61fa9628a5
commit 537023dbfa
3 changed files with 22 additions and 11 deletions

View file

@ -80,7 +80,7 @@ namespace pq {
auto types_bt = concat_strings(make_pqtypes_name<typename remove_cv<typename remove_reference<Args>::type>::type>()...); auto types_bt = concat_strings(make_pqtypes_name<typename remove_cv<typename remove_reference<Args>::type>::type>()...);
static_assert(types_bt.size() > 0, "Invalid empty types string (function called with no arguments?)"); static_assert(types_bt.size() > 0, "Invalid empty types string (function called with no arguments?)");
const std::string types(types_bt.data(), types_bt.size()); const std::string types(types_bt.data(), types_bt.size());
return this->make_params(&types, implem::get_pqlib_c_type_struct<typename remove_cv<typename remove_reference<Args>::type>::type>(*this).conv(parArgs)...); return this->make_params(&types, implem::get_pqlib_c_type_struct<typename remove_cv<typename remove_reference<Args>::type>::type>(this).conv(parArgs)...);
}; };
PGParams pgparams = make_pgparams(); PGParams pgparams = make_pgparams();

View file

@ -39,13 +39,13 @@ namespace pq {
template <typename T> template <typename T>
struct get_pqlib_c_type_struct { struct get_pqlib_c_type_struct {
using type = T; using type = T;
explicit get_pqlib_c_type_struct ( const Connection& ) { } explicit get_pqlib_c_type_struct ( const Connection* ) { }
static type conv ( T parParam ) { return parParam; } static type conv ( T parParam ) { return parParam; }
}; };
template <> template <>
struct get_pqlib_c_type_struct<std::string> { struct get_pqlib_c_type_struct<std::string> {
using type = const char*; using type = const char*;
explicit get_pqlib_c_type_struct ( const Connection& ) { } explicit get_pqlib_c_type_struct ( const Connection* ) { }
static type conv ( const std::string& parParam ) { return parParam.c_str(); } static type conv ( const std::string& parParam ) { return parParam.c_str(); }
}; };
template <> template <>
@ -54,13 +54,13 @@ namespace pq {
std::string m_str; std::string m_str;
public: public:
using type = const char*; using type = const char*;
explicit get_pqlib_c_type_struct ( const Connection& ) { } explicit get_pqlib_c_type_struct ( const Connection* ) { }
type conv ( boost::string_ref parParam ) { m_str = std::string(parParam.data(), parParam.size()); return m_str.c_str(); } type conv ( boost::string_ref parParam ) { m_str = std::string(parParam.data(), parParam.size()); return m_str.c_str(); }
}; };
template <> template <>
struct get_pqlib_c_type_struct<bool> { struct get_pqlib_c_type_struct<bool> {
using type = int; using type = int;
explicit get_pqlib_c_type_struct ( const Connection& ) { } explicit get_pqlib_c_type_struct ( const Connection* ) { }
static type conv ( bool parParam ) { return (parParam ? 1 : 0); } static type conv ( bool parParam ) { return (parParam ? 1 : 0); }
}; };
template <> template <>
@ -78,7 +78,7 @@ namespace pq {
public: public:
using type = const storage*; using type = const storage*;
explicit get_pqlib_c_type_struct ( const Connection& ) { } explicit get_pqlib_c_type_struct ( const Connection* ) { }
type conv ( const std::chrono::system_clock::time_point& parParam ); type conv ( const std::chrono::system_clock::time_point& parParam );
~get_pqlib_c_type_struct ( void ) noexcept; ~get_pqlib_c_type_struct ( void ) noexcept;
}; };
@ -173,8 +173,10 @@ namespace pq {
storage m_storage; storage m_storage;
PGParams m_par; PGParams m_par;
const Connection* m_conn;
protected: protected:
explicit get_pqlib_c_type_struct_arr ( const Connection& parConn ); explicit get_pqlib_c_type_struct_arr ( const Connection* parConn );
~get_pqlib_c_type_struct_arr ( void ) noexcept; ~get_pqlib_c_type_struct_arr ( void ) noexcept;
void par_reset ( void ); void par_reset ( void );
const void* get_return_ptr ( void ); const void* get_return_ptr ( void );
@ -182,13 +184,13 @@ namespace pq {
void push_param ( const T& parParam ) { void push_param ( const T& parParam ) {
static_assert(std::is_fundamental<T>::value or std::is_same<std::string, T>::value or std::is_same<boost::string_ref, T>::value or std::is_same<std::chrono::system_clock::time_point, T>::value, "Unsupported type in array"); static_assert(std::is_fundamental<T>::value or std::is_same<std::string, T>::value or std::is_same<boost::string_ref, T>::value or std::is_same<std::chrono::system_clock::time_point, T>::value, "Unsupported type in array");
this->push_param(make_pqtypes_name<T>().data(), get_pqlib_c_type_struct<T>::conv(parParam)); this->push_param(make_pqtypes_name<T>().data(), get_pqlib_c_type_struct<T>(m_conn).conv(parParam));
} }
}; };
template <typename VT, typename VU> template <typename VT, typename VU>
struct get_pqlib_c_type_struct<std::vector<VT, VU>> : private get_pqlib_c_type_struct_arr { struct get_pqlib_c_type_struct<std::vector<VT, VU>> : private get_pqlib_c_type_struct_arr {
using type = const void*; using type = const void*;
explicit get_pqlib_c_type_struct ( const Connection& parConn ) : get_pqlib_c_type_struct_arr(parConn) { } explicit get_pqlib_c_type_struct ( const Connection* parConn ) : get_pqlib_c_type_struct_arr(parConn) { }
type conv ( const std::vector<VT, VU>& parParam) { type conv ( const std::vector<VT, VU>& parParam) {
this->par_reset(); this->par_reset();
for (const auto& i : parParam) { for (const auto& i : parParam) {

View file

@ -26,6 +26,13 @@
#endif #endif
namespace pq { namespace pq {
namespace {
const Connection* assert_not_null_and_return (const Connection* parConn) {
assert(parConn);
return parConn;
}
} //unnamed namespace
namespace implem { namespace implem {
template < template <
typename Expected, typename Expected,
@ -76,10 +83,12 @@ namespace pq {
return; return;
} }
get_pqlib_c_type_struct_arr::get_pqlib_c_type_struct_arr (const Connection& parConn) : get_pqlib_c_type_struct_arr::get_pqlib_c_type_struct_arr (const Connection* parConn) :
m_par(parConn.make_empty_params()) m_par(assert_not_null_and_return(parConn)->make_empty_params()),
m_conn(parConn)
{ {
static_assert_size<PGarray, storage>(); static_assert_size<PGarray, storage>();
assert(m_conn);
PGarray arr; PGarray arr;
std::fill(reinterpret_cast<char*>(&arr), reinterpret_cast<char*>(&arr) + sizeof(PGarray), '\0'); std::fill(reinterpret_cast<char*>(&arr), reinterpret_cast<char*>(&arr) + sizeof(PGarray), '\0');