Skip to content

Commit

Permalink
Prepare for 7.9.0 release. (#795)
Browse files Browse the repository at this point in the history
  • Loading branch information
jtv committed Feb 18, 2024
1 parent 16defbd commit c74d039
Show file tree
Hide file tree
Showing 23 changed files with 109 additions and 141 deletions.
5 changes: 3 additions & 2 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
7.9.0
- BREAKING: `std::basic_string<std::byte` becomes `pqxx::bytes`. (#726)
- BREAKING: `std::basic_string_view<std::byte>` becomes `bytes_view`. (#726)
- Support standard libraries without `std::basic_string<std::byte>` etc.
- `std::basic_string<std::byte` becomes `pqxx::bytes`. (#726)
- `std::basic_string_view<std::byte>` becomes `bytes_view`. (#726)
- Fix assertion failure when streaming row ending in empty string. (#774)
- CMake users can `shared_link_libraries(... libpqxx::pqxx)`. (#785)
- Support parameterised versions of `query()` etc. (#646)
Expand Down
5 changes: 2 additions & 3 deletions include/pqxx/connection.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -1087,9 +1087,8 @@ private:

friend class internal::gate::connection_transaction;
result exec(std::string_view, std::string_view = ""sv);
result
PQXX_PRIVATE exec(
std::shared_ptr<std::string> const &, std::string_view = ""sv);
result PQXX_PRIVATE
exec(std::shared_ptr<std::string> const &, std::string_view = ""sv);
void PQXX_PRIVATE register_transaction(transaction_base *);
void PQXX_PRIVATE unregister_transaction(transaction_base *) noexcept;

Expand Down
32 changes: 10 additions & 22 deletions include/pqxx/internal/conversions.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -871,9 +871,7 @@ inline constexpr bool is_unquoted_safe<std::shared_ptr<T>>{
is_unquoted_safe<T>};


template<>
struct nullness<bytes>
: no_null<bytes>
template<> struct nullness<bytes> : no_null<bytes>
{};


Expand Down Expand Up @@ -930,20 +928,17 @@ template<> struct string_traits<bytes>
static constexpr bool converts_to_string{true};
static constexpr bool converts_from_string{true};

static std::size_t
size_buffer(bytes const &value) noexcept
static std::size_t size_buffer(bytes const &value) noexcept
{
return internal::size_esc_bin(std::size(value));
}

static zview
to_buf(char *begin, char *end, bytes const &value)
static zview to_buf(char *begin, char *end, bytes const &value)
{
return generic_to_buf(begin, end, value);
}

static char *
into_buf(char *begin, char *end, bytes const &value)
static char *into_buf(char *begin, char *end, bytes const &value)
{
auto const budget{size_buffer(value)};
if (internal::cmp_less(end - begin, budget))
Expand All @@ -964,16 +959,13 @@ template<> struct string_traits<bytes>
};


template<>
inline constexpr format param_format(bytes const &)
template<> inline constexpr format param_format(bytes const &)
{
return format::binary;
}


template<>
struct nullness<bytes_view>
: no_null<bytes_view>
template<> struct nullness<bytes_view> : no_null<bytes_view>
{};


Expand All @@ -982,20 +974,17 @@ template<> struct string_traits<bytes_view>
static constexpr bool converts_to_string{true};
static constexpr bool converts_from_string{false};

static std::size_t
size_buffer(bytes_view const &value) noexcept
static std::size_t size_buffer(bytes_view const &value) noexcept
{
return internal::size_esc_bin(std::size(value));
}

static zview to_buf(
char *begin, char *end, bytes_view const &value)
static zview to_buf(char *begin, char *end, bytes_view const &value)
{
return generic_to_buf(begin, end, value);
}

static char *into_buf(
char *begin, char *end, bytes_view const &value)
static char *into_buf(char *begin, char *end, bytes_view const &value)
{
auto const budget{size_buffer(value)};
if (internal::cmp_less(end - begin, budget))
Expand All @@ -1008,8 +997,7 @@ template<> struct string_traits<bytes_view>
// There's no from_string, because there's nobody to hold the data.
};

template<>
inline constexpr format param_format(bytes_view const &)
template<> inline constexpr format param_format(bytes_view const &)
{
return format::binary;
}
Expand Down
4 changes: 2 additions & 2 deletions include/pqxx/internal/stream_query_impl.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ public:
return not done();
}

stream_query_input_iterator &operator=(stream_query_input_iterator &&rhs)
noexcept
stream_query_input_iterator &
operator=(stream_query_input_iterator &&rhs) noexcept
{
if (&rhs != this)
{
Expand Down
4 changes: 1 addition & 3 deletions include/pqxx/result.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ public:
using reverse_iterator = const_reverse_iterator;

result() noexcept :
m_data{},
m_query{},
m_encoding{internal::encoding_group::MONOBYTE}
m_data{}, m_query{}, m_encoding{internal::encoding_group::MONOBYTE}
{}

result(result const &rhs) noexcept = default;
Expand Down
15 changes: 8 additions & 7 deletions include/pqxx/transaction_base.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,8 @@ public:
return exec_params(query, parms).iter<TYPE...>();
}

/// Perform query parameterised, expect given number of rows, iterate results.
/// Perform query parameterised, expect given number of rows, iterate
/// results.
/** Works like @ref query, but checks that the result has exactly the
* expected number of rows.
*
Expand All @@ -757,8 +758,8 @@ public:
* @return Something you can iterate using "range `for`" syntax. The actual
* type details may change.
*/
template<typename... TYPE> auto query_n(
result::size_type rows, zview query, params const &parms)
template<typename... TYPE>
auto query_n(result::size_type rows, zview query, params const &parms)
{
return exec_params_n(rows, query, parms).iter<TYPE...>();
}
Expand Down Expand Up @@ -803,8 +804,8 @@ public:
* the number of fields in the tuple.
*/
template<typename... TYPE>
[[nodiscard]] std::optional<std::tuple<TYPE...>> query01(
zview query, params const &parms)
[[nodiscard]] std::optional<std::tuple<TYPE...>>
query01(zview query, params const &parms)
{
result res{exec_params(query, parms)};
auto const rows{std::size(res)};
Expand All @@ -831,8 +832,8 @@ public:
* 2. The `exec` functions are faster for small results, but slower for large
* results.
*/
template<typename CALLABLE> void for_query(
zview query, CALLABLE &&func, params const &parms)
template<typename CALLABLE>
void for_query(zview query, CALLABLE &&func, params const &parms)
{
exec_params(query, parms).for_each(std::forward<CALLABLE>(func));
}
Expand Down
10 changes: 6 additions & 4 deletions include/pqxx/util.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -310,24 +310,26 @@ struct byte_char_traits : std::char_traits<char>
static const std::byte *
find(const std::byte *data, std::size_t size, const std::byte &value)
{
return static_cast<const std::byte*>(std::memchr(data, static_cast<int>(value), size));
return static_cast<const std::byte *>(
std::memchr(data, static_cast<int>(value), size));
}

static std::byte *
move(std::byte *dest, const std::byte *src, std::size_t size)
{
return static_cast<std::byte*>(std::memmove(dest, src, size));
return static_cast<std::byte *>(std::memmove(dest, src, size));
}

static std::byte *
copy(std::byte *dest, const std::byte *src, std::size_t size)
{
return static_cast<std::byte*>(std::memcpy(dest, src, size));
return static_cast<std::byte *>(std::memcpy(dest, src, size));
}

static std::byte *assign(std::byte *dest, std::size_t size, std::byte value)
{
return static_cast<std::byte*>(std::memset(dest, static_cast<int>(value), size));
return static_cast<std::byte *>(
std::memset(dest, static_cast<int>(value), size));
}

/// Declared but not defined: makes no sense for binary data.
Expand Down
52 changes: 24 additions & 28 deletions src/array.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ std::pair<array_parser::juncture, std::string> array_parser::parse_array_step()
if (m_pos >= std::size(m_input))
return std::make_pair(juncture::done, value);

auto [found, end] = [this, &value]{
auto [found, end] = [this, &value] {
if (scan_glyph<ENC>(m_pos) - m_pos > 1)
{
// Non-ASCII unquoted string.
Expand All @@ -114,35 +114,31 @@ std::pair<array_parser::juncture, std::string> array_parser::parse_array_step()
switch (m_input[m_pos])
{
case '\0': throw failure{"Unexpected zero byte in array."};
case '{':
return std::tuple{juncture::row_start, scan_glyph<ENC>(m_pos)};
case '}':
return std::tuple{juncture::row_end, scan_glyph<ENC>(m_pos)};
case '"':
case '{': return std::tuple{juncture::row_start, scan_glyph<ENC>(m_pos)};
case '}': return std::tuple{juncture::row_end, scan_glyph<ENC>(m_pos)};
case '"': {
auto const endpoint = scan_double_quoted_string<ENC>();
value = parse_double_quoted_string<ENC>(endpoint);
return std::tuple{juncture::string_value, endpoint};
}
default: {
auto const endpoint = scan_unquoted_string<ENC>();
value = parse_unquoted_string<ENC>(endpoint);
if (value == "NULL")
{
auto const endpoint = scan_double_quoted_string<ENC>();
value = parse_double_quoted_string<ENC>(endpoint);
return std::tuple{juncture::string_value, endpoint};
}
default:
// In this one situation, as a special case, NULL means a null
// field, not a string that happens to spell "NULL".
value.clear();
return std::tuple{juncture::null_value, endpoint};
}
else
{
auto const endpoint = scan_unquoted_string<ENC>();
value = parse_unquoted_string<ENC>(endpoint);
if (value == "NULL")
{
// In this one situation, as a special case, NULL means a null
// field, not a string that happens to spell "NULL".
value.clear();
return std::tuple{juncture::null_value, endpoint};
}
else
{
// The normal case: we just parsed an unquoted string. The value
// is what we need.
PQXX_LIKELY
return std::tuple{juncture::string_value, endpoint};
}
}
// The normal case: we just parsed an unquoted string. The value
// is what we need.
PQXX_LIKELY
return std::tuple{juncture::string_value, endpoint};
}
}
}
}();

Expand Down
6 changes: 3 additions & 3 deletions src/connection.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,7 @@ pqxx::result pqxx::connection::make_result(
throw broken_connection{"Lost connection to the database server."};
}
auto const enc{internal::enc_group(encoding_id())};
auto r{
pqxx::internal::gate::result_creation::create(smart, query, enc)};
auto r{pqxx::internal::gate::result_creation::create(smart, query, enc)};
pqxx::internal::gate::result_creation{r}.check_status(desc);
return r;
}
Expand Down Expand Up @@ -745,7 +744,8 @@ pqxx::result pqxx::connection::exec_prepared(
void pqxx::connection::close()
{
// Just in case PQfinish() doesn't handle nullptr nicely.
if (m_conn == nullptr) return;
if (m_conn == nullptr)
return;
try
{
if (m_trans)
Expand Down
4 changes: 1 addition & 3 deletions src/cursor.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,7 @@ pqxx::icursor_iterator &pqxx::icursor_iterator::operator+=(difference_type n)
pqxx::icursor_iterator &
pqxx::icursor_iterator::operator=(icursor_iterator const &rhs) noexcept
{
if (&rhs == this)
{
}
if (&rhs == this) {}
else if (rhs.m_stream == m_stream)
{
PQXX_UNLIKELY
Expand Down
5 changes: 4 additions & 1 deletion src/encodings.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pqxx::internal::encoding_group enc_group(std::string_view encoding_name)
private:
std::string_view m_name;
pqxx::internal::encoding_group m_group;

public:
constexpr mapping(std::string_view n, pqxx::internal::encoding_group g) :
m_name{n}, m_group{g}
Expand All @@ -49,7 +50,9 @@ pqxx::internal::encoding_group enc_group(std::string_view encoding_name)
}
[[nodiscard]] std::string_view get_name() const { return m_name; }
[[nodiscard]] pqxx::internal::encoding_group get_group() const
{ return m_group; }
{
return m_group;
}
};

// C++20: Once compilers are ready, go full constexpr, leave to the compiler.
Expand Down
4 changes: 2 additions & 2 deletions src/largeobject.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ constexpr int PQXX_COLD std_dir_to_pq_dir(std::ios::seekdir dir) noexcept


PQXX_COLD pqxx::largeobject::largeobject(dbtransaction &t) :
m_id{lo_creat(raw_connection(t), 0)}
m_id{lo_creat(raw_connection(t), 0)}
{
// (Mode is ignored as of postgres 8.1.)
if (m_id == oid_none)
Expand All @@ -84,7 +84,7 @@ PQXX_COLD pqxx::largeobject::largeobject(dbtransaction &t) :

PQXX_COLD
pqxx::largeobject::largeobject(dbtransaction &t, std::string_view file) :
m_id{lo_import(raw_connection(t), std::data(file))}
m_id{lo_import(raw_connection(t), std::data(file))}
{
if (m_id == oid_none)
{
Expand Down
3 changes: 1 addition & 2 deletions src/params.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ void PQXX_COLD pqxx::params::append(binarystring const &value) &
void pqxx::params::append(params &&value) &
{
this->reserve(std::size(value.m_params) + std::size(this->m_params));
for (auto const &param : value.m_params)
m_params.emplace_back(param);
for (auto const &param : value.m_params) m_params.emplace_back(param);
value.m_params.clear();
}

Expand Down
6 changes: 2 additions & 4 deletions src/pipeline.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@ using namespace std::literals::string_view_literals;

namespace
{
constexpr std::string_view
theSeparator{"; "sv},
theDummyValue{"1"sv},
theDummyQuery{"SELECT 1; "sv};
constexpr std::string_view theSeparator{"; "sv}, theDummyValue{"1"sv},
theDummyQuery{"SELECT 1; "sv};
} // namespace


Expand Down
9 changes: 4 additions & 5 deletions src/result.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,9 @@ std::string pqxx::result::status_error() const
case PGRES_EMPTY_QUERY: // The string sent to the backend was empty.
case PGRES_COMMAND_OK: // Successful completion, no result data.
case PGRES_TUPLES_OK: // The query successfully executed.
case PGRES_COPY_OUT: // Copy Out (from server) data transfer started.
case PGRES_COPY_IN: // Copy In (to server) data transfer started.
case PGRES_COPY_BOTH: // Copy In/Out. Used for streaming replication.
case PGRES_COPY_OUT: // Copy Out (from server) data transfer started.
case PGRES_COPY_IN: // Copy In (to server) data transfer started.
case PGRES_COPY_BOTH: // Copy In/Out. Used for streaming replication.
break;

#if defined(LIBPQ_HAS_PIPELINING)
Expand Down Expand Up @@ -466,8 +466,7 @@ int pqxx::result::errorposition() const
int pos{-1};
if (m_data.get())
{
auto const p{
PQresultErrorField(m_data.get(), PG_DIAG_STATEMENT_POSITION)};
auto const p{PQresultErrorField(m_data.get(), PG_DIAG_STATEMENT_POSITION)};
if (p)
pos = from_string<decltype(pos)>(p);
}
Expand Down

0 comments on commit c74d039

Please sign in to comment.