Skip to content

Commit

Permalink
Restrict fill_buffer to non-string types.
Browse files Browse the repository at this point in the history
Well, sort of.  We don't support `char` as a C++ type that can be
written to the database directly, since it's ambiguous.  (Does it mean
"a single character," or "a single-byte character," or "a one-byte
integer," or "a one-byte _unsigned_ integer?)  So, block the overload in
the case where the container being passed has `char` as its content
type.  Such a type would presumably be meant as a string.
  • Loading branch information
jtv committed Feb 12, 2021
1 parent 5148d9e commit 9059114
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions include/pqxx/stream_to.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public:
/** This is the recommended way of inserting data. Pass your field values,
* of any convertible type.
*/
template<typename... Ts> void write_values(const Ts &...fields)
template<typename... Ts> void write_values(Ts const &...fields)
{
fill_buffer(fields...);
write_buffer();
Expand Down Expand Up @@ -335,7 +335,9 @@ private:
}

/// Write raw COPY line into @c m_buffer, based on a container of fields.
template<typename Container> void fill_buffer(Container const &c)
template<typename Container>
std::enable_if_t<not std::is_same_v<typename Container::value_type, char>>
fill_buffer(Container const &c)
{
// To avoid unnecessary allocations and deallocations, we run through c
// twice: once to determine how much buffer space we may need, and once to
Expand Down

0 comments on commit 9059114

Please sign in to comment.