13 #ifndef PQXX_H_CONNECTION 14 #define PQXX_H_CONNECTION 16 #include "pqxx/compiler-public.hxx" 17 #include "pqxx/internal/compiler-internal-pre.hxx" 23 #include <string_view> 25 #include "pqxx/errorhandler.hxx" 26 #include "pqxx/except.hxx" 27 #include "pqxx/prepared_statement.hxx" 28 #include "pqxx/strconv.hxx" 29 #include "pqxx/util.hxx" 30 #include "pqxx/zview.hxx" 68 class connection_dbtransaction;
69 class connection_errorhandler;
70 class connection_largeobject;
71 class connection_notification_receiver;
72 class connection_pipeline;
73 class connection_sql_cursor;
74 class connection_stream_from;
75 class connection_stream_to;
76 class connection_transaction;
77 class const_connection_largeobject;
84 [[nodiscard]] std::string PQXX_LIBEXPORT
88 [[nodiscard]]
inline std::string
166 catch (std::exception
const &)
184 [[nodiscard]]
bool PQXX_PURE is_open()
const noexcept;
187 void process_notice(
char const[]) noexcept;
191 process_notice(
zview{msg});
197 void process_notice(
zview) noexcept;
200 void trace(std::FILE *) noexcept;
212 [[nodiscard]]
char const *dbname()
const;
216 [[nodiscard]]
char const *username()
const;
219 [[nodiscard]]
char const *hostname()
const;
222 [[nodiscard]]
char const *port()
const;
225 [[nodiscard]]
int PQXX_PURE backendpid()
const noexcept;
243 [[nodiscard]]
int PQXX_PURE sock()
const noexcept;
249 [[nodiscard]]
int PQXX_PURE protocol_version()
const noexcept;
264 [[nodiscard]]
int PQXX_PURE server_version()
const noexcept;
288 [[nodiscard]] std::string get_client_encoding()
const;
297 set_client_encoding(encoding.c_str());
304 void set_client_encoding(
char const encoding[]);
307 [[nodiscard]]
int PQXX_PRIVATE encoding_id()
const;
327 void set_variable(std::string_view var, std::string_view value);
333 std::string get_variable(std::string_view);
366 int await_notification();
378 int await_notification(
long seconds,
long microseconds);
409 char const user[],
char const password[],
char const *algorithm =
nullptr);
410 [[nodiscard]] std::string
466 void prepare(
char const name[],
char const definition[]);
468 void prepare(std::string
const &name, std::string
const &definition)
470 prepare(name.c_str(), definition.c_str());
486 void prepare(
char const definition[]);
490 void unprepare(std::string_view name);
500 [[nodiscard]] std::string adorn_name(std::string_view);
512 [[nodiscard]] std::string
esc(
char const text[], std::size_t maxlen)
const 514 return esc(std::string_view(text, maxlen));
518 [[nodiscard]] std::string
esc(
char const text[])
const 520 return esc(std::string_view(text));
527 [[nodiscard]] std::string esc(std::string_view text)
const;
530 [[nodiscard]] std::string
531 esc_raw(
unsigned char const bin[], std::size_t len)
const;
537 [[nodiscard]] std::string
unesc_raw(std::string
const &text)
const 539 return unesc_raw(text.c_str());
548 return unesc_raw(text.
c_str());
555 [[nodiscard]] std::string unesc_raw(
char const text[])
const;
558 [[nodiscard]] std::string
559 quote_raw(
unsigned char const bin[], std::size_t len)
const;
562 [[nodiscard]] std::string quote_name(std::string_view identifier)
const;
568 template<
typename T>[[nodiscard]]
inline std::string quote(T
const &t)
const;
570 [[nodiscard]] std::string quote(
binarystring const &)
const;
596 [[nodiscard]] std::string
597 esc_like(std::string_view text,
char escape_char =
'\\')
const;
632 [[nodiscard]] std::vector<errorhandler *> get_errorhandlers()
const;
641 [[nodiscard]] std::string connection_string()
const;
650 void init(
char const options[]);
654 void wait_read(
long seconds,
long microseconds)
const;
657 internal::pq::PGresult *pgr, std::shared_ptr<std::string>
const &query);
659 void PQXX_PRIVATE set_up_state();
661 int PQXX_PRIVATE PQXX_PURE status()
const noexcept;
668 std::size_t esc_to_buf(std::string_view text,
char *buf)
const;
670 friend class internal::gate::const_connection_largeobject;
671 char const *PQXX_PURE err_msg() const noexcept;
673 void PQXX_PRIVATE process_notice_raw(
char const msg[]) noexcept;
675 result exec_prepared(
std::string_view statement, internal::params const &);
678 void check_movable() const;
680 void check_overwritable() const;
682 friend class internal::gate::connection_errorhandler;
683 void PQXX_PRIVATE register_errorhandler(
errorhandler *);
684 void PQXX_PRIVATE unregister_errorhandler(errorhandler *) noexcept;
686 friend class internal::gate::connection_transaction;
687 result PQXX_PRIVATE exec(
std::string_view);
690 void PQXX_PRIVATE unregister_transaction(transaction_base *) noexcept;
692 friend class internal::gate::connection_stream_from;
693 std::pair<
std::unique_ptr<
char,
std::function<
void(
char *)>>,
std::
size_t>
694 PQXX_PRIVATE read_copy_line();
696 friend class internal::gate::connection_stream_to;
697 void PQXX_PRIVATE write_copy_line(
std::string_view);
698 void PQXX_PRIVATE end_copy_write();
700 friend class internal::gate::connection_largeobject;
701 internal::pq::PGconn *raw_connection()
const {
return m_conn; }
703 friend class internal::gate::connection_notification_receiver;
707 friend class internal::gate::connection_pipeline;
708 void PQXX_PRIVATE start_exec(
char const query[]);
709 bool PQXX_PRIVATE consume_input() noexcept;
710 bool PQXX_PRIVATE is_busy() const noexcept;
711 internal::pq::PGresult *get_result();
713 friend class internal::gate::connection_dbtransaction;
714 friend class internal::gate::connection_sql_cursor;
716 result exec_params(
std::string_view query, internal::params const &args);
719 internal::pq::PGconn *m_conn =
nullptr;
726 using receiver_list =
729 receiver_list m_receivers;
740 template<typename T> inline
std::
string connection::quote(T const &t)
const 750 std::string buf{
'\''};
751 buf.resize(2 + 2 * text.size() + 1);
752 auto const content_bytes{esc_to_buf(text, buf.data() + 1)};
753 auto const closing_quote{1 + content_bytes};
754 buf[closing_quote] =
'\'';
755 auto const end{closing_quote + 1};
764 PQXX_LIBEXPORT
void wait_read(internal::pq::PGconn
const *);
766 wait_read(internal::pq::PGconn
const *,
long seconds,
long microseconds);
767 PQXX_LIBEXPORT
void wait_write(internal::pq::PGconn
const *);
770 #include "pqxx/internal/compiler-internal-post.hxx" Private namespace for libpqxx's internal use; do not access.
Definition: connection.hxx:60
constexpr char const * c_str() const noexcept
Either a null pointer, or a zero-terminated text buffer.
Definition: zview.hxx:53
void prepare(std::string const &name, std::string const &definition)
Definition: connection.hxx:468
void wait_write(internal::pq::PGconn const *)
Definition: connection.cxx:931
connection(zview options)
Definition: connection.hxx:150
std::string encrypt_password(zview user, zview password, zview algorithm)
Definition: connection.hxx:411
std::string to_string(field const &value)
Convert a field to a string.
Definition: result.cxx:498
void set_client_encoding(std::string const &encoding)
Set client-side character encoding, by name.
Definition: connection.hxx:295
std::string unesc_raw(zview text) const
Unescape binary data, e.g. from a table field or notification payload.
Definition: connection.hxx:546
connection(char const options[])
Definition: connection.hxx:144
error_verbosity
Error verbosity levels.
Definition: connection.hxx:96
std::string esc(char const text[]) const
Escape string for use as SQL string literal on this connection.
Definition: connection.hxx:518
The home of all libpqxx classes, functions, templates, etc.
Definition: array.hxx:25
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:512
Connection to a database.
Definition: connection.hxx:136
void process_notice(std::string const &msg) noexcept
Invoke notice processor function. Newline at end is recommended.
Definition: connection.hxx:189
bool is_null(TYPE const &value) noexcept
Is value null?
Definition: strconv.hxx:307
Binary data corresponding to PostgreSQL's "BYTEA" binary-string type.
Definition: binarystring.hxx:53
~connection()
Definition: connection.hxx:160
void check_version()
Definition: util.hxx:143
connection(std::string const &options)
Definition: connection.hxx:141
Definition: connection.hxx:66
Result set containing data returned by a query or command.
Definition: result.hxx:70
void prepare(zview definition)
Definition: connection.hxx:487
Marker-type wrapper: zero-terminated std::string_view.
Definition: zview.hxx:32
Definition: notification.hxx:55
Base class for error-handler callbacks.
Definition: errorhandler.hxx:52
Interface definition (and common code) for "transaction" classes.
Definition: transaction_base.hxx:67
std::string encrypt_password(char const user[], char const password[])
Encrypt a password.
Definition: connection.cxx:93
void prepare(zview name, zview definition)
Definition: connection.hxx:473
void wait_read(internal::pq::PGconn const *)
Definition: connection.cxx:911
connection()
Definition: connection.hxx:139
std::string unesc_raw(std::string const &text) const
Unescape binary data, e.g. from a table field or notification payload.
Definition: connection.hxx:537