mirror of
https://github.com/KingDuckZ/dindexer.git
synced 2024-11-25 00:53:43 +00:00
Tell libpqtypes to not make copies of strings it receives.
The wrapper now copies boost::string_ref into std::string so it's always safe to pass a string ref, even when it's not null-terminated.
This commit is contained in:
parent
fa12bb2d74
commit
7e737f56a2
2 changed files with 9 additions and 5 deletions
|
@ -24,6 +24,7 @@
|
|||
#include <boost/utility/string_ref.hpp>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
struct pg_param;
|
||||
typedef pg_param PGparam;
|
||||
|
@ -49,9 +50,12 @@ namespace pq {
|
|||
};
|
||||
template <>
|
||||
struct get_pqlib_c_type_struct<boost::string_ref> {
|
||||
private:
|
||||
std::string m_str;
|
||||
public:
|
||||
using type = const char*;
|
||||
explicit get_pqlib_c_type_struct ( const Connection& ) { }
|
||||
static type conv ( const boost::string_ref& parParam ) { return parParam.data(); }
|
||||
type conv ( boost::string_ref parParam ) { m_str = std::string(parParam.data(), parParam.size()); return m_str.c_str(); }
|
||||
};
|
||||
template <>
|
||||
struct get_pqlib_c_type_struct<bool> {
|
||||
|
@ -99,11 +103,11 @@ namespace pq {
|
|||
|
||||
template <>
|
||||
struct type_to_pqtypes_name<std::string> {
|
||||
constexpr static const char* name ( void ) { return "text"; }
|
||||
constexpr static const char* name ( void ) { return "text*"; }
|
||||
};
|
||||
template <>
|
||||
struct type_to_pqtypes_name<boost::string_ref> {
|
||||
constexpr static const char* name ( void ) { return "text"; }
|
||||
constexpr static const char* name ( void ) { return "text*"; }
|
||||
};
|
||||
template <>
|
||||
struct type_to_pqtypes_name<bool> {
|
||||
|
|
|
@ -133,8 +133,8 @@ namespace din {
|
|||
system_clock::from_time_t(itm.mtime),
|
||||
itm.hash_valid,
|
||||
itm.unreadable,
|
||||
std::string(itm.mime_type.data(), itm.mime_type.size()),
|
||||
std::string(itm.mime_charset.data(), itm.mime_charset.size())
|
||||
itm.mime_type,
|
||||
itm.mime_charset
|
||||
);
|
||||
}
|
||||
conn.query("COMMIT;");
|
||||
|
|
Loading…
Reference in a new issue