Skip to content

Commit

Permalink
Retire more deprecated quoting/escaping.
Browse files Browse the repository at this point in the history
  • Loading branch information
jtv committed Jan 2, 2025
1 parent 2a31544 commit 19f5a9a
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 76 deletions.
38 changes: 0 additions & 38 deletions include/pqxx/connection.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -909,10 +909,6 @@ public:
}
#endif

/// Escape binary string for use as SQL string literal on this connection.
[[deprecated("Use std::byte for binary data.")]] std::string
esc_raw(unsigned char const bin[], std::size_t len) const;

/// Escape binary string for use as SQL string literal on this connection.
/** You can also just use @ref esc with a binary string. */
[[nodiscard]] std::string esc_raw(bytes_view) const;
Expand Down Expand Up @@ -1046,40 +1042,6 @@ public:
*/
[[nodiscard]] std::string
esc_like(std::string_view text, char escape_char = '\\') const;

/// Escape string for use as SQL string literal on this connection.
/** @warning This accepts a length, and it does not require a terminating
* zero byte. But if there is a zero byte, escaping stops there even if
* it's not at the end of the string!
*/
[[deprecated("Use std::string_view or pqxx:zview.")]] std::string
esc(char const text[], std::size_t maxlen) const
{
return esc(std::string_view{text, maxlen});
}

/// Unescape binary data, e.g. from a `bytea` field.
/** Takes a binary string as escaped by PostgreSQL, and returns a restored
* copy of the original binary data.
*/
[[nodiscard, deprecated("Use unesc_bin() instead.")]] std::string
unesc_raw(zview text) const
{
#include "pqxx/internal/ignore-deprecated-pre.hxx"
return unesc_raw(text.c_str());
#include "pqxx/internal/ignore-deprecated-post.hxx"
}

/// Unescape binary data, e.g. from a `bytea` field.
/** Takes a binary string as escaped by PostgreSQL, and returns a restored
* copy of the original binary data.
*/
[[nodiscard, deprecated("Use unesc_bin() instead.")]] std::string
unesc_raw(char const text[]) const;

/// Escape and quote a string of binary data.
[[deprecated("Use quote(bytes_view).")]] std::string
quote_raw(unsigned char const bin[], std::size_t len) const;
//@}

/// Attempt to cancel the ongoing query, if any.
Expand Down
38 changes: 0 additions & 38 deletions src/connection.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -963,50 +963,12 @@ std::string pqxx::connection::esc(std::string_view text) const
}


std::string PQXX_COLD
pqxx::connection::esc_raw(unsigned char const bin[], std::size_t len) const
{
return pqxx::internal::esc_bin(binary_cast(bin, len));
}


std::string pqxx::connection::esc_raw(bytes_view bin) const
{
return pqxx::internal::esc_bin(bin);
}


std::string PQXX_COLD pqxx::connection::unesc_raw(char const text[]) const
{
if (text[0] == '\\' and text[1] == 'x')
{
// Hex-escaped format.
std::string buf;
buf.resize(pqxx::internal::size_unesc_bin(std::strlen(text)));
pqxx::internal::unesc_bin(
std::string_view{text}, reinterpret_cast<std::byte *>(buf.data()));
return buf;
}
else
{
// Legacy escape format.
// TODO: Remove legacy support.
std::size_t len{};
auto bytes{reinterpret_cast<unsigned char const *>(text)};
std::unique_ptr<unsigned char, void (*)(void const *)> const ptr{
PQunescapeBytea(bytes, &len), pqxx::internal::pq::pqfreemem};
return std::string{ptr.get(), ptr.get() + len};
}
}


std::string PQXX_COLD
pqxx::connection::quote_raw(unsigned char const bin[], std::size_t len) const
{
return internal::concat("'", esc_raw(binary_cast(bin, len)), "'::bytea");
}


std::string pqxx::connection::quote_raw(bytes_view bytes) const
{
return internal::concat("'", esc_raw(bytes), "'::bytea");
Expand Down

0 comments on commit 19f5a9a

Please sign in to comment.