14#if !defined(PQXX_HEADER_PRE)
15# error "Include libpqxx headers as <pqxx/header>, not <pqxx/header.hxx>."
35#include "pqxx/except.hxx"
36#include "pqxx/types.hxx"
37#include "pqxx/version.hxx"
44#include <pqxx/internal/libpq-forward.hxx>
49#if !defined(__cpp_lib_unreachable)
50# define PQXX_UNREACHABLE while (false)
51#elif !__cpp_lib_unreachable
52# define PQXX_UNREACHABLE while (false)
54# define PQXX_UNREACHABLE std::unreachable()
64template<
typename LEFT,
typename RIGHT>
67#if defined(PQXX_HAVE_CMP)
68 return std::cmp_less(
lhs,
rhs);
74 if constexpr (
left_signed == std::is_signed_v<RIGHT>)
76 else if constexpr (std::is_signed_v<LEFT>)
77 return (
lhs <= 0) ?
true : (std::make_unsigned_t<LEFT>(
lhs) <
rhs);
86template<
typename LEFT,
typename RIGHT>
89#if defined(PQXX_HAVE_CMP)
90 return std::cmp_greater(
lhs,
rhs);
99template<
typename LEFT,
typename RIGHT>
102#if defined(PQXX_HAVE_CMP)
103 return std::cmp_less_equal(
lhs,
rhs);
112template<
typename LEFT,
typename RIGHT>
115#if defined(PQXX_HAVE_CMP)
116 return std::cmp_greater_equal(
lhs,
rhs);
130 auto const xs{std::size(
x)},
ys{std::size(
y)};
132 x.copy(std::data(
buf),
xs);
141using namespace std::literals;
152template<
typename TO,
typename FROM>
155 static_assert(std::is_arithmetic_v<FROM>);
156 static_assert(std::is_arithmetic_v<TO>);
157 static_assert(std::is_integral_v<FROM> == std::is_integral_v<TO>);
161 if constexpr (std::is_same_v<FROM, bool>)
162 return static_cast<TO>(value);
168 using from_limits = std::numeric_limits<
decltype(value)>;
169 using to_limits = std::numeric_limits<TO>;
170 if constexpr (std::is_signed_v<FROM>)
172 if constexpr (std::is_signed_v<TO>)
174 if (value < to_limits::lowest())
184 "Casting negative value to unsigned type: "sv, description)};
193 if constexpr (std::is_integral_v<FROM>)
205 else if constexpr ((from_limits::max)() > (to_limits::max)())
207 if (value > (to_limits::max)())
211 return static_cast<TO>(value);
248 static auto const version_ok{internal::PQXX_VERSION_CHECK()};
259 bool safe_libpq =
false;
268 bool safe_kerberos =
false;
279#if defined(PQXX_HAVE_CONCEPTS)
280# define PQXX_POTENTIAL_BINARY_ARG pqxx::potential_binary
282# define PQXX_POTENTIAL_BINARY_ARG typename
292 using char_type = std::byte;
294 static void assign(std::byte &
a,
const std::byte &
b)
noexcept {
a =
b; }
295 static bool eq(std::byte
a, std::byte
b) {
return a ==
b; }
296 static bool lt(std::byte
a, std::byte
b) {
return a <
b; }
298 static int compare(
const std::byte *
a,
const std::byte *
b, std::size_t size)
300 return std::memcmp(
a,
b, size);
310 static size_t length(
const std::byte *data);
312 static const std::byte *
313 find(
const std::byte *data, std::size_t size,
const std::byte &value)
315 return static_cast<const std::byte *
>(
316 std::memchr(data,
static_cast<int>(value), size));
320 move(std::byte *
dest,
const std::byte *
src, std::size_t size)
322 return static_cast<std::byte *
>(std::memmove(
dest,
src, size));
326 copy(std::byte *
dest,
const std::byte *
src, std::size_t size)
328 return static_cast<std::byte *
>(std::memcpy(
dest,
src, size));
331 static std::byte *assign(std::byte *
dest, std::size_t size, std::byte value)
333 return static_cast<std::byte *
>(
334 std::memset(
dest,
static_cast<int>(value), size));
340 static std::byte to_char_type(int_type value) {
return std::byte(value); }
342 static int_type to_int_type(std::byte value) {
return int_type(value); }
344 static bool eq_int_type(int_type
a, int_type
b) {
return a ==
b; }
350template<
typename TYPE,
typename =
void>
354template<
typename TYPE>
356 TYPE, std::
void_t<decltype(std::char_traits<TYPE>::eof)>> : std::true_type
359inline constexpr bool has_generic_bytes_char_traits =
365#include "pqxx/internal/ignore-deprecated-pre.hxx"
374 has_generic_bytes_char_traits, std::basic_string<std::byte>,
375 std::basic_string<std::byte, byte_char_traits>>
::type;
384 has_generic_bytes_char_traits, std::basic_string_view<std::byte>,
385 std::basic_string_view<std::byte, byte_char_traits>>
::type;
387#include "pqxx/internal/ignore-deprecated-post.hxx"
408template<PQXX_POTENTIAL_BINARY_ARG TYPE>
414 reinterpret_cast<std::byte
const *
>(
421#if defined(PQXX_HAVE_CONCEPTS)
422template<
typename CHAR>
424# define PQXX_CHAR_SIZED_ARG char_sized
426# define PQXX_CHAR_SIZED_ARG typename
436template<PQXX_CHAR_SIZED_ARG CHAR,
typename SIZE>
439 static_assert(
sizeof(
CHAR) == 1);
441 reinterpret_cast<std::byte
const *
>(data),
463using namespace std::literals;
473 return (
c >=
'0')
and (
c <=
'9');
557#if defined(PQXX_HAVE_SSIZE)
558 return std::ssize(
c);
560 using signed_t = std::make_signed_t<
decltype(std::size(
c))>;
561 return static_cast<signed_t>(std::size(
c));
609template<
typename CALLABLE>
615template<
typename CALLABLE>
623template<
typename...
TYPES>
624std::tuple<strip_t<TYPES>...>
strip_types(std::tuple<TYPES...>
const &);
628template<
typename...
TYPES>
638 PQXX_UNLIKELY
return '\b';
640 PQXX_UNLIKELY
return '\f';
658template<std::
size_t BYTES>
665#if defined(PQXX_HAVE_STERROR_S) || defined(PQXX_HAVE_STRERROR_R)
666# if defined(PQXX_HAVE_STRERROR_S)
685 return "Compound errors.";
691 return "(No error information available.)";
700PQXX_LIBEXPORT
void pqfreemem(
void const *)
noexcept;
Something is out of range, similar to std::out_of_range.
Definition except.hxx:326
Forward declarations of libpq types as needed in libpqxx headers.
Definition util.cxx:204
void pqfreemem(void const *ptr) noexcept
Wrapper for PQfreemem(), with C++ linkage.
Definition util.cxx:205
Internal items for libpqxx' own use. Do not use these yourself.
Definition encodings.cxx:33
void PQXX_LIBEXPORT unesc_bin(std::string_view escaped_data, std::byte buffer[])
Reconstitute binary data from its escaped version.
Definition util.cxx:165
char const *PQXX_COLD error_string(int err_num, std::array< char, BYTES > &buffer)
Get error string for a given errno value.
Definition util.hxx:660
constexpr std::size_t size_esc_bin(std::size_t binary_bytes) noexcept
Compute buffer size needed to escape binary data for use as a BYTEA.
Definition util.hxx:516
decltype(args_f(std::declval< CALLABLE >())) args_t
A callable's parameter types, as a tuple.
Definition util.hxx:616
std::tuple< ARGS... > member_args_f(RETURN(CLASS::*)(ARGS...))
Helper for determining a member function's parameter types.
constexpr bool cmp_less(LEFT lhs, RIGHT rhs) noexcept
Same as std::cmp_less, or a workaround where that's not available.
Definition util.hxx:65
void check_unique_unregister(void const *old_guest, std::string_view old_class, std::string_view old_name, void const *new_guest, std::string_view new_class, std::string_view new_name)
Like check_unique_register, but for un-registering a guest.
Definition util.cxx:80
void PQXX_LIBEXPORT esc_bin(bytes_view binary_data, char buffer[]) noexcept
Hex-escape binary data into a buffer.
Definition util.cxx:133
void check_unique_register(void const *old_guest, std::string_view old_class, std::string_view old_name, void const *new_guest, std::string_view new_class, std::string_view new_name)
Check validity of registering a new "guest" in a "host.".
Definition util.cxx:63
std::tuple< strip_t< TYPES >... > strip_types(std::tuple< TYPES... > const &)
Helper: Apply strip_t to each of a tuple type's component types.
std::string describe_object(std::string_view class_name, std::string_view name)
Describe an object for humans, based on class name and optional name.
Definition util.cxx:53
std::tuple< ARGS... > args_f(RETURN(&func)(ARGS...))
Helper for determining a function's parameter types.
constexpr bool cmp_greater(LEFT lhs, RIGHT rhs) noexcept
C++20 std::cmp_greater, or workaround if not available.
Definition util.hxx:87
constexpr bool is_digit(CHAR c) noexcept
A safer and more generic replacement for std::isdigit.
Definition util.hxx:471
constexpr char unescape_char(char escaped) noexcept
Return original byte for escaped character.
Definition util.hxx:633
decltype(strip_types(std::declval< TYPES... >())) strip_types_t
Take a tuple type and apply strip_t to its component types.
Definition util.hxx:629
constexpr bool cmp_greater_equal(LEFT lhs, RIGHT rhs) noexcept
C++20 std::cmp_greater_equal, or workaround if not available.
Definition util.hxx:113
std::string cat2(std::string_view x, std::string_view y)
Efficiently concatenate two strings.
Definition util.hxx:127
constexpr bool cmp_less_equal(LEFT lhs, RIGHT rhs) noexcept
C++20 std::cmp_less_equal, or workaround if not available.
Definition util.hxx:100
auto ssize(T const &c)
Transitional: std::ssize(), or custom implementation if not available.
Definition util.hxx:555
constexpr std::size_t size_unesc_bin(std::size_t escaped_bytes) noexcept
Compute binary size from the size of its escaped version.
Definition util.hxx:525
The home of all libpqxx classes, functions, templates, etc.
Definition array.cxx:27
unsigned int oid
PostgreSQL database row identifier.
Definition libpq-forward.hxx:33
constexpr char array_separator
Element separator between SQL array elements of this type.
Definition strconv.hxx:559
PQXX_PRIVATE void check_version() noexcept
Definition util.hxx:236
std::conditional< has_generic_bytes_char_traits, std::basic_string_view< std::byte >, std::basic_string_view< std::byte, byte_char_traits > >::type bytes_view
Type alias for a view of bytes.
Definition util.hxx:383
std::conditional< has_generic_bytes_char_traits, std::basic_string< std::byte >, std::basic_string< std::byte, byte_char_traits > >::type bytes
Type alias for a container containing bytes.
Definition util.hxx:373
bytes_view binary_cast(TYPE const &data)
Cast binary data to a type that libpqxx will recognise as binary.
Definition util.hxx:409
strip_t< decltype(*std::begin(std::declval< CONTAINER >()))> value_type
The type of a container's elements.
Definition types.hxx:96
std::remove_cv_t< std::remove_reference_t< TYPE > > strip_t
Remove any constness, volatile, and reference-ness from a type.
Definition types.hxx:80
constexpr void ignore_unused(T &&...) noexcept
Suppress compiler warning about an unused item.
Definition util.hxx:144
PQXX_LIBEXPORT thread_safety_model describe_thread_safety()
Describe thread safety available in this build.
Definition util.cxx:35
std::string description
A human-readable description of any thread-safety issues.
Definition util.hxx:271
constexpr oid oid_none
The "null" oid.
Definition util.hxx:447
TO check_cast(FROM value, std::string_view description)
Cast a numeric value to another type, or throw if it underflows/overflows.
Definition util.hxx:153
Descriptor of library's thread-safety model.
Definition util.hxx:257
Custom std::char_trast if the compiler does not provide one.
Definition util.hxx:291
static size_t length(const std::byte *data)
Deliberately undefined: "guess" the length of an array of bytes.
static int_type not_eof(int_type value)
Declared but not defined: makes no sense for binary data.
static int_type eof()
Declared but not defined: makes no sense for binary data.