libpqxx  7.7.2
connection.hxx
1 /* Definition of the connection class.
2  *
3  * pqxx::connection encapsulates a connection to a database.
4  *
5  * DO NOT INCLUDE THIS FILE DIRECTLY; include pqxx/connection instead.
6  *
7  * Copyright (c) 2000-2022, Jeroen T. Vermeulen.
8  *
9  * See COPYING for copyright license. If you did not receive a file called
10  * COPYING with this source code, please notify the distributor of this
11  * mistake, or contact the author.
12  */
13 #ifndef PQXX_H_CONNECTION
14 #define PQXX_H_CONNECTION
15 
16 #if !defined(PQXX_HEADER_PRE)
17 # error "Include libpqxx headers as <pqxx/header>, not <pqxx/header.hxx>."
18 #endif
19 
20 #include <cstddef>
21 #include <ctime>
22 #include <functional>
23 #include <initializer_list>
24 #include <list>
25 #include <map>
26 #include <memory>
27 #include <string_view>
28 #include <tuple>
29 #include <utility>
30 
31 // Double-check in order to suppress an overzealous Visual C++ warning (#418).
32 #if defined(PQXX_HAVE_CONCEPTS) && __has_include(<ranges>)
33 # include <ranges>
34 #endif
35 
36 #include "pqxx/errorhandler.hxx"
37 #include "pqxx/except.hxx"
38 #include "pqxx/internal/concat.hxx"
39 #include "pqxx/params.hxx"
40 #include "pqxx/separated_list.hxx"
41 #include "pqxx/strconv.hxx"
42 #include "pqxx/types.hxx"
43 #include "pqxx/util.hxx"
44 #include "pqxx/zview.hxx"
45 
46 
77 namespace pqxx::internal
78 {
79 class sql_cursor;
80 
81 #if defined(PQXX_HAVE_CONCEPTS)
82 template<typename T>
84 concept ZKey_ZValues = std::ranges::input_range<T> and requires(T t)
85 {
86  {std::cbegin(t)};
87  {
88  std::get<0>(*std::cbegin(t))
89  } -> ZString;
90  {
91  std::get<1>(*std::cbegin(t))
92  } -> ZString;
93 } and std::tuple_size_v<typename std::ranges::iterator_t<T>::value_type>
94 == 2;
95 #endif // PQXX_HAVE_CONCEPTS
96 } // namespace pqxx::internal
97 
98 
100 {
101 class connection_dbtransaction;
102 class connection_errorhandler;
103 class connection_largeobject;
104 class connection_notification_receiver;
105 class connection_pipeline;
106 class connection_sql_cursor;
107 class connection_stream_from;
108 class connection_stream_to;
109 class connection_transaction;
110 class const_connection_largeobject;
111 } // namespace pqxx::internal::gate
112 
113 
114 namespace pqxx
115 {
117 
124 using table_path = std::initializer_list<std::string_view>;
125 
126 
128 [[nodiscard,
129  deprecated("Use connection::encrypt_password instead.")]] std::string
130  PQXX_LIBEXPORT
131  encrypt_password(char const user[], char const password[]);
132 
134 [[nodiscard,
135  deprecated("Use connection::encrypt_password instead.")]] inline std::string
136 encrypt_password(zview user, zview password)
137 {
138 #include "pqxx/internal/ignore-deprecated-pre.hxx"
139  return encrypt_password(user.c_str(), password.c_str());
140 #include "pqxx/internal/ignore-deprecated-post.hxx"
141 }
142 
143 
145 enum class error_verbosity : int
146 {
147  // These values must match those in libpq's PGVerbosity enum.
148  terse = 0,
149  normal = 1,
150  verbose = 2
151 };
152 
153 
155 
185 class PQXX_LIBEXPORT connection
186 {
187 public:
189 
191  explicit connection(char const options[])
192  {
193  check_version();
194  init(options);
195  }
196 
198  explicit connection(zview options) : connection{options.c_str()}
199  {
200  // (Delegates to other constructor which calls check_version for us.)
201  }
202 
204 
209  connection(connection &&rhs);
210 
211 #if defined(PQXX_HAVE_CONCEPTS)
212 
228  template<internal::ZKey_ZValues MAPPING>
229  inline connection(MAPPING const &params);
230 #endif // PQXX_HAVE_CONCEPTS
231 
233  {
234  try
235  {
236  close();
237  }
238  catch (std::exception const &)
239  {}
240  }
241 
243 
246  connection &operator=(connection &&rhs);
247 
248  connection(connection const &) = delete;
249  connection &operator=(connection const &) = delete;
250 
252 
257  [[nodiscard]] bool PQXX_PURE is_open() const noexcept;
258 
260  void process_notice(char const[]) noexcept;
262 
265  void process_notice(zview) noexcept;
266 
268  void trace(std::FILE *) noexcept;
269 
280  [[nodiscard]] char const *dbname() const;
282 
284  [[nodiscard]] char const *username() const;
285 
287  [[nodiscard]] char const *hostname() const;
288 
290  [[nodiscard]] char const *port() const;
291 
293  [[nodiscard]] int PQXX_PURE backendpid() const &noexcept;
294 
296 
306  [[nodiscard]] int PQXX_PURE sock() const &noexcept;
307 
309 
312  [[nodiscard]] int PQXX_PURE protocol_version() const noexcept;
313 
315 
327  [[nodiscard]] int PQXX_PURE server_version() const noexcept;
329 
331 
351  [[nodiscard]] std::string get_client_encoding() const;
353 
355 
358  void set_client_encoding(zview encoding) &
359  {
360  set_client_encoding(encoding.c_str());
361  }
362 
364 
367  void set_client_encoding(char const encoding[]) &;
368 
370  [[nodiscard]] int PQXX_PRIVATE encoding_id() const;
371 
373 
375 
388  [[deprecated("To set session variables, use set_session_var.")]] void
389  set_variable(std::string_view var, std::string_view value) &;
390 
392 
413  template<typename TYPE>
414  void set_session_var(std::string_view var, TYPE const &value) &
415  {
416  if constexpr (nullness<TYPE>::has_null)
417  {
418  if (nullness<TYPE>::is_null(value))
419  throw variable_set_to_null{
420  internal::concat("Attempted to set variable ", var, " to null.")};
421  }
422  exec(internal::concat("SET ", quote_name(var), "=", quote(value)));
423  }
424 
426 
429  [[deprecated("Use get_var instead.")]] std::string
430  get_variable(std::string_view);
431 
433 
439  std::string get_var(std::string_view var);
440 
442 
448  template<typename TYPE> TYPE get_var_as(std::string_view var)
449  {
450  return from_string<TYPE>(get_var(var));
451  }
452 
457 
475  int get_notifs();
476 
478 
490  int await_notification();
491 
493 
505  int await_notification(std::time_t seconds, long microseconds);
507 
538  [[nodiscard]] std::string
540  encrypt_password(zview user, zview password, zview algorithm)
541  {
542  return encrypt_password(user.c_str(), password.c_str(), algorithm.c_str());
543  }
545  [[nodiscard]] std::string encrypt_password(
546  char const user[], char const password[], char const *algorithm = nullptr);
548 
591 
593 
597  void prepare(zview name, zview definition) &
598  {
599  prepare(name.c_str(), definition.c_str());
600  }
601 
606  void prepare(char const name[], char const definition[]) &;
607 
609 
616  void prepare(char const definition[]) &;
617  void prepare(zview definition) & { return prepare(definition.c_str()); }
618 
620  void unprepare(std::string_view name);
621 
623 
624  // C++20: constexpr. Breaks ABI.
626 
629  [[nodiscard]] std::string adorn_name(std::string_view);
630 
635 
637 
641  [[deprecated("Use std::string_view or pqxx:zview.")]] std::string
642  esc(char const text[], std::size_t maxlen) const
643  {
644  return esc(std::string_view{text, maxlen});
645  }
646 
648  [[nodiscard]] std::string esc(char const text[]) const
649  {
650  return esc(std::string_view{text});
651  }
652 
653 #if defined(PQXX_HAVE_SPAN)
654 
666  [[nodiscard]] std::string_view
667  esc(std::string_view text, std::span<char> buffer)
668  {
669  auto const size{std::size(text)}, space{std::size(buffer)};
670  auto const needed{2 * size + 1};
671  if (space < needed)
672  throw range_error{internal::concat(
673  "Not enough room to escape string of ", size, " byte(s): need ",
674  needed, " bytes of buffer space, but buffer size is ", space, ".")};
675  auto const data{buffer.data()};
676  return {data, esc_to_buf(text, data)};
677  }
678 #endif
679 
681 
684  [[nodiscard]] std::string esc(std::string_view text) const;
685 
686 #if defined(PQXX_HAVE_CONCEPTS)
687 
689  template<binary DATA> [[nodiscard]] std::string esc(DATA const &data) const
690  {
691  return esc_raw(data);
692  }
693 #endif
694 
695 #if defined(PQXX_HAVE_CONCEPTS) && defined(PQXX_HAVE_SPAN)
696 
708  template<binary DATA>
709  [[nodiscard]] zview esc(DATA const &data, std::span<char> buffer) const
710  {
711  auto const size{std::size(data)}, space{std::size(buffer)};
712  auto const needed{internal::size_esc_bin(std::size(data))};
713  if (space < needed)
714  throw range_error{internal::concat(
715  "Not enough room to escape binary string of ", size, " byte(s): need ",
716  needed, " bytes of buffer space, but buffer size is ", space, ".")};
717 
718  std::basic_string_view<std::byte> view{std::data(data), std::size(data)};
719  auto const out{std::data(buffer)};
720  // Actually, in the modern format, we know beforehand exactly how many
721  // bytes we're going to fill. Just leave out the trailing zero.
722  internal::esc_bin(view, out);
723  return zview{out, needed - 1};
724  }
725 #endif
726 
728  [[deprecated("Use std::byte for binary data.")]] std::string
729  esc_raw(unsigned char const bin[], std::size_t len) const;
730 
732 
733  [[nodiscard]] std::string esc_raw(std::basic_string_view<std::byte>) const;
734 
735 #if defined(PQXX_HAVE_SPAN)
736 
738  [[nodiscard]] std::string
739  esc_raw(std::basic_string_view<std::byte>, std::span<char> buffer) const;
740 #endif
741 
742 #if defined(PQXX_HAVE_CONCEPTS)
743 
745  template<binary DATA>
746  [[nodiscard]] std::string esc_raw(DATA const &data) const
747  {
748  return esc_raw(
749  std::basic_string_view<std::byte>{std::data(data), std::size(data)});
750  }
751 #endif
752 
753 #if defined(PQXX_HAVE_CONCEPTS) && defined(PQXX_HAVE_SPAN)
754  template<binary DATA>
756  [[nodiscard]] zview esc_raw(DATA const &data, std::span<char> buffer) const
757  {
758  return this->esc(binary_cast(data), buffer);
759  }
760 #endif
761 
763 
766  [[nodiscard, deprecated("Use unesc_bin() instead.")]] std::string
767  unesc_raw(zview text) const
768  {
769 #include "pqxx/internal/ignore-deprecated-pre.hxx"
770  return unesc_raw(text.c_str());
771 #include "pqxx/internal/ignore-deprecated-post.hxx"
772  }
773 
775 
778  [[nodiscard, deprecated("Use unesc_bin() instead.")]] std::string
779  unesc_raw(char const text[]) const;
780 
781  // TODO: Make "into buffer" variant to eliminate a string allocation.
783 
790  [[nodiscard]] std::basic_string<std::byte>
791  unesc_bin(std::string_view text) const
792  {
793  std::basic_string<std::byte> buf;
794  buf.resize(pqxx::internal::size_unesc_bin(std::size(text)));
795  pqxx::internal::unesc_bin(text, buf.data());
796  return buf;
797  }
798 
800  [[deprecated("Use quote(std::basic_string_view<std::byte>).")]] std::string
801  quote_raw(unsigned char const bin[], std::size_t len) const;
802 
804  std::string quote_raw(std::basic_string_view<std::byte>) const;
805 
806 #if defined(PQXX_HAVE_CONCEPTS)
807 
809  template<binary DATA>
810  [[nodiscard]] std::string quote_raw(DATA const &data) const
811  {
812  return quote_raw(
813  std::basic_string_view<std::byte>{std::data(data), std::size(data)});
814  }
815 #endif
816 
817  // TODO: Make "into buffer" variant to eliminate a string allocation.
819  [[nodiscard]] std::string quote_name(std::string_view identifier) const;
820 
821  // TODO: Make "into buffer" variant to eliminate a string allocation.
823 
826  [[nodiscard]] std::string quote_table(std::string_view name) const;
827 
828  // TODO: Make "into buffer" variant to eliminate a string allocation.
830 
838  [[nodiscard]] std::string quote_table(table_path) const;
839 
840  // TODO: Make "into buffer" variant to eliminate a string allocation.
842 
849  template<PQXX_CHAR_STRINGS_ARG STRINGS>
850  inline std::string quote_columns(STRINGS const &columns) const;
851 
852  // TODO: Make "into buffer" variant to eliminate a string allocation.
854 
857  template<typename T>
858  [[nodiscard]] inline std::string quote(T const &t) const;
859 
860  [[deprecated("Use std::byte for binary data.")]] std::string
861  quote(binarystring const &) const;
862 
863  // TODO: Make "into buffer" variant to eliminate a string allocation.
865  [[nodiscard]] std::string
866  quote(std::basic_string_view<std::byte> bytes) const;
867 
868  // TODO: Make "into buffer" variant to eliminate a string allocation.
870 
895  [[nodiscard]] std::string
896  esc_like(std::string_view text, char escape_char = '\\') const;
898 
900 
904  void cancel_query();
905 
906 #if defined(_WIN32) || __has_include(<fcntl.h>)
907  void set_blocking(bool block) &;
909 #endif // defined(_WIN32) || __has_include(<fcntl.h>)
910 
912 
921  void set_verbosity(error_verbosity verbosity) &noexcept;
922 
924 
936  [[nodiscard]] std::vector<errorhandler *> get_errorhandlers() const;
937 
939 
945  [[nodiscard]] std::string connection_string() const;
946 
948 
956  void close();
957 
959 
965  static connection seize_raw_connection(internal::pq::PGconn *raw_conn)
966  {
967  return connection{raw_conn};
968  }
969 
971 
976  internal::pq::PGconn *release_raw_connection() &&
977  {
978  return std::exchange(m_conn, nullptr);
979  }
980 
981 private:
982  friend class connecting;
983  enum connect_mode
984  {
985  connect_nonblocking
986  };
987  connection(connect_mode, zview connection_string);
988 
990  explicit connection(internal::pq::PGconn *raw_conn) : m_conn{raw_conn} {}
991 
993 
998  std::pair<bool, bool> poll_connect();
999 
1000  // Initialise based on connection string.
1001  void init(char const options[]);
1002  // Initialise based on parameter names and values.
1003  void init(char const *params[], char const *values[]);
1004  void complete_init();
1005 
1006  result make_result(
1007  internal::pq::PGresult *pgr, std::shared_ptr<std::string> const &query,
1008  std::string_view desc = ""sv);
1009 
1010  void PQXX_PRIVATE set_up_state();
1011 
1012  int PQXX_PRIVATE PQXX_PURE status() const noexcept;
1013 
1015 
1019  std::size_t esc_to_buf(std::string_view text, char *buf) const;
1020 
1021  friend class internal::gate::const_connection_largeobject;
1022  char const *PQXX_PURE err_msg() const noexcept;
1023 
1024  void PQXX_PRIVATE process_notice_raw(char const msg[]) noexcept;
1025 
1026  result exec_prepared(std::string_view statement, internal::c_params const &);
1027 
1029  void check_movable() const;
1031  void check_overwritable() const;
1032 
1033  friend class internal::gate::connection_errorhandler;
1034  void PQXX_PRIVATE register_errorhandler(errorhandler *);
1035  void PQXX_PRIVATE unregister_errorhandler(errorhandler *) noexcept;
1036 
1037  friend class internal::gate::connection_transaction;
1038  result exec(std::string_view, std::string_view = ""sv);
1039  result
1040  PQXX_PRIVATE exec(std::shared_ptr<std::string>, std::string_view = ""sv);
1041  void PQXX_PRIVATE register_transaction(transaction_base *);
1042  void PQXX_PRIVATE unregister_transaction(transaction_base *) noexcept;
1043 
1044  friend class internal::gate::connection_stream_from;
1045  std::pair<std::unique_ptr<char, std::function<void(char *)>>, std::size_t>
1046  PQXX_PRIVATE read_copy_line();
1047 
1048  friend class internal::gate::connection_stream_to;
1049  void PQXX_PRIVATE write_copy_line(std::string_view);
1050  void PQXX_PRIVATE end_copy_write();
1051 
1052  friend class internal::gate::connection_largeobject;
1053  internal::pq::PGconn *raw_connection() const { return m_conn; }
1054 
1055  friend class internal::gate::connection_notification_receiver;
1056  void add_receiver(notification_receiver *);
1057  void remove_receiver(notification_receiver *) noexcept;
1058 
1059  friend class internal::gate::connection_pipeline;
1060  void PQXX_PRIVATE start_exec(char const query[]);
1061  bool PQXX_PRIVATE consume_input() noexcept;
1062  bool PQXX_PRIVATE is_busy() const noexcept;
1063  internal::pq::PGresult *get_result();
1064 
1065  friend class internal::gate::connection_dbtransaction;
1066  friend class internal::gate::connection_sql_cursor;
1067 
1068  result exec_params(std::string_view query, internal::c_params const &args);
1069 
1071  internal::pq::PGconn *m_conn = nullptr;
1072 
1074 
1081  transaction_base const *m_trans = nullptr;
1082 
1083  std::list<errorhandler *> m_errorhandlers;
1084 
1085  using receiver_list =
1086  std::multimap<std::string, pqxx::notification_receiver *>;
1088  receiver_list m_receivers;
1089 
1091  int m_unique_id = 0;
1092 };
1093 
1094 
1096 using connection_base = connection;
1097 
1098 
1100 
1143 class PQXX_LIBEXPORT connecting
1144 {
1145 public:
1147  connecting(zview connection_string = ""_zv);
1148 
1149  connecting(connecting const &) = delete;
1150  connecting(connecting &&) = default;
1151  connecting &operator=(connecting const &) = delete;
1152  connecting &operator=(connecting &&) = default;
1153 
1155  [[nodiscard]] int sock() const &noexcept { return m_conn.sock(); }
1156 
1158  [[nodiscard]] constexpr bool wait_to_read() const &noexcept
1159  {
1160  return m_reading;
1161  }
1162 
1164  [[nodiscard]] constexpr bool wait_to_write() const &noexcept
1165  {
1166  return m_writing;
1167  }
1168 
1170  void process() &;
1171 
1173  [[nodiscard]] constexpr bool done() const &noexcept
1174  {
1175  return not m_reading and not m_writing;
1176  }
1177 
1179 
1187  [[nodiscard]] connection produce() &&;
1188 
1189 private:
1190  connection m_conn;
1191  bool m_reading{false};
1192  bool m_writing{true};
1193 };
1194 
1195 
1196 template<typename T> inline std::string connection::quote(T const &t) const
1197 {
1198  if constexpr (nullness<T>::always_null)
1199  {
1200  return "NULL";
1201  }
1202  else
1203  {
1204  if (is_null(t))
1205  return "NULL";
1206  auto const text{to_string(t)};
1207 
1208  // Okay, there's an easy way to do this and there's a hard way. The easy
1209  // way was "quote, esc(to_string(t)), quote". I'm going with the hard way
1210  // because it's going to save some string manipulation that will probably
1211  // incur some unnecessary memory allocations and deallocations.
1212  std::string buf{'\''};
1213  buf.resize(2 + 2 * std::size(text) + 1);
1214  auto const content_bytes{esc_to_buf(text, buf.data() + 1)};
1215  auto const closing_quote{1 + content_bytes};
1216  buf[closing_quote] = '\'';
1217  auto const end{closing_quote + 1};
1218  buf.resize(end);
1219  return buf;
1220  }
1221 }
1222 
1223 
1224 template<PQXX_CHAR_STRINGS_ARG STRINGS>
1225 inline std::string connection::quote_columns(STRINGS const &columns) const
1226 {
1227  return separated_list(
1228  ","sv, std::cbegin(columns), std::cend(columns),
1229  [this](auto col) { return this->quote_name(*col); });
1230 }
1231 
1232 
1233 #if defined(PQXX_HAVE_CONCEPTS)
1234 template<internal::ZKey_ZValues MAPPING>
1235 inline connection::connection(MAPPING const &params)
1236 {
1237  check_version();
1238 
1239  std::vector<char const *> keys, values;
1240  if constexpr (std::ranges::sized_range<MAPPING>)
1241  {
1242  auto const size{std::ranges::size(params) + 1};
1243  keys.reserve(size);
1244  values.reserve(size);
1245  }
1246  for (auto const &[key, value] : params)
1247  {
1248  keys.push_back(internal::as_c_string(key));
1249  values.push_back(internal::as_c_string(value));
1250  }
1251  keys.push_back(nullptr);
1252  values.push_back(nullptr);
1253  init(std::data(keys), std::data(values));
1254 }
1255 #endif // PQXX_HAVE_CONCEPTS
1256 } // namespace pqxx
1257 #endif
Something is out of range, similar to std::out_of_range.
Definition: except.hxx:201
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:404
std::string esc(char const text[]) const
Escape string for use as SQL string literal on this connection.
Definition: connection.hxx:648
The home of all libpqxx classes, functions, templates, etc.
Definition: array.hxx:26
std::string quote_columns(STRINGS const &columns) const
Quote and comma-separate a series of column names.
Definition: connection.hxx:1225
TYPE get_var_as(std::string_view var)
Read currently applicable value of a variable.
Definition: connection.hxx:448
static connection seize_raw_connection(internal::pq::PGconn *raw_conn)
Seize control of a raw libpq connection.
Definition: connection.hxx:965
Connection to a database.
Definition: connection.hxx:185
void prepare(zview name, zview definition) &
Define a prepared statement.
Definition: connection.hxx:597
constexpr bool wait_to_read() const &noexcept
Should we currently wait to be able to read from the socket?
Definition: connection.hxx:1158
std::string encrypt_password(char const user[], char const password[])
Encrypt a password.
Definition: connection.cxx:81
The caller attempted to set a variable to null, which is not allowed.
Definition: except.hxx:76
connection(zview options)
Connect to a database, using options string.
Definition: connection.hxx:198
std::string encrypt_password(zview user, zview password, zview algorithm)
Encrypt a password for a given user.
Definition: connection.hxx:540
~connection()
Definition: connection.hxx:232
std::string to_string(field const &value)
Convert a field to a string.
Definition: result.cxx:533
STL namespace.
void set_session_var(std::string_view var, TYPE const &value) &
Set one of the session variables to a new value.
Definition: connection.hxx:414
void check_version() noexcept
Definition: util.hxx:228
error_verbosity
Error verbosity levels.
Definition: connection.hxx:145
void esc_bin(std::basic_string_view< std::byte > binary_data, char buffer[]) noexcept
Hex-escape binary data into a buffer.
Definition: util.cxx:126
internal::pq::PGconn * release_raw_connection() &&
Release the raw connection without closing it.
Definition: connection.hxx:976
Definition: notification.hxx:56
constexpr bool done() const &noexcept
Is our connection finished?
Definition: connection.hxx:1173
Definition: connection.hxx:99
constexpr char const * as_c_string(char const str[]) noexcept
Get a raw C string pointer.
Definition: zview.hxx:141
constexpr bool wait_to_write() const &noexcept
Should we currently wait to be able to write to the socket?
Definition: connection.hxx:1164
Interface definition (and common code) for "transaction" classes.
Definition: transaction_base.hxx:76
connection()
Definition: connection.hxx:188
Result set containing data returned by a query or command.
Definition: result.hxx:72
Marker-type wrapper: zero-terminated std::string_view.
Definition: zview.hxx:37
Internal items for libpqxx&#39; own use. Do not use these yourself.
Definition: composite.hxx:82
std::string quote(T const &t) const
Represent object as SQL string, including quoting & escaping.
Definition: connection.hxx:1196
void set_client_encoding(zview encoding) &
Set client-side character encoding, by name.
Definition: connection.hxx:358
Base class for error-handler callbacks.
Definition: errorhandler.hxx:53
std::basic_string< std::byte > unesc_bin(std::string_view text) const
Unescape binary data, e.g. from a table field or notification payload.
Definition: connection.hxx:791
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:413
constexpr char const * c_str() const &noexcept
Either a null pointer, or a zero-terminated text buffer.
Definition: zview.hxx:92
std::string unesc_raw(zview text) const
Unescape binary data, e.g. from a table field or notification payload.
Definition: connection.hxx:767
void unesc_bin(std::string_view escaped_data, std::byte buffer[])
Reconstitute binary data from its escaped version.
Definition: util.cxx:158
Binary data corresponding to PostgreSQL&#39;s "BYTEA" binary-string type.
Definition: binarystring.hxx:58
void prepare(zview definition) &
Definition: connection.hxx:617
std::string esc(char const text[], std::size_t maxlen) const
Escape string for use as SQL string literal on this connection.
Definition: connection.hxx:642
Traits describing a type&#39;s "null value," if any.
Definition: strconv.hxx:92
std::basic_string_view< std::byte > binary_cast(TYPE const &data)
Cast binary data to a type that libpqxx will recognise as binary.
Definition: util.hxx:297
std::string separated_list(std::string_view sep, ITER begin, ITER end, ACCESS access)
Represent sequence of values as a string, joined by a given separator.
Definition: separated_list.hxx:43
connection(char const options[])
Connect to a database, using options string.
Definition: connection.hxx:191
std::initializer_list< std::string_view > table_path
Representation of a PostgreSQL table path.
Definition: connection.hxx:124
constexpr bool is_null(TYPE const &value) noexcept
Is value null?
Definition: strconv.hxx:367
An ongoing, non-blocking stepping stone to a connection.
Definition: connection.hxx:1143
Build a parameter list for a parameterised or prepared statement.
Definition: params.hxx:219
int sock() const &noexcept
Get the socket. The socket may change during the connection process.
Definition: connection.hxx:1155