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();
377 int await_notification(
long seconds,
long microseconds);
408 char const user[],
char const password[],
char const *algorithm =
nullptr);
409 [[nodiscard]] std::string
465 void prepare(
char const name[],
char const definition[]);
467 void prepare(std::string
const &name, std::string
const &definition)
469 prepare(name.c_str(), definition.c_str());
485 void prepare(
char const definition[]);
489 void unprepare(std::string_view name);
499 [[nodiscard]] std::string adorn_name(std::string_view);
511 [[nodiscard]] std::string
esc(
char const text[], std::size_t maxlen)
const 513 return esc(std::string_view(text, maxlen));
517 [[nodiscard]] std::string
esc(
char const text[])
const 519 return esc(std::string_view(text));
526 [[nodiscard]] std::string esc(std::string_view text)
const;
529 [[nodiscard]] std::string
530 esc_raw(
unsigned char const bin[], std::size_t len)
const;
536 [[nodiscard]] std::string
unesc_raw(std::string
const &text)
const 538 return unesc_raw(text.c_str());
547 return unesc_raw(text.
c_str());
554 [[nodiscard]] std::string unesc_raw(
char const text[])
const;
557 [[nodiscard]] std::string
558 quote_raw(
unsigned char const bin[], std::size_t len)
const;
561 [[nodiscard]] std::string quote_name(std::string_view identifier)
const;
567 template<
typename T>[[nodiscard]]
inline std::string quote(T
const &t)
const;
569 [[nodiscard]] std::string quote(
binarystring const &)
const;
595 [[nodiscard]] std::string
596 esc_like(std::string_view text,
char escape_char =
'\\')
const;
631 [[nodiscard]] std::vector<errorhandler *> get_errorhandlers()
const;
640 [[nodiscard]] std::string connection_string()
const;
649 void init(
char const options[]);
652 void wait_read(
long seconds,
long microseconds)
const;
655 internal::pq::PGresult *pgr, std::shared_ptr<std::string>
const &query);
657 void PQXX_PRIVATE set_up_state();
659 int PQXX_PRIVATE PQXX_PURE status()
const noexcept;
666 std::size_t esc_to_buf(std::string_view text,
char *buf)
const;
668 friend class internal::gate::const_connection_largeobject;
669 char const *PQXX_PURE err_msg() const noexcept;
671 void PQXX_PRIVATE process_notice_raw(
char const msg[]) noexcept;
673 result exec_prepared(
std::string_view statement, internal::params const &);
676 void check_movable() const;
678 void check_overwritable() const;
680 friend class internal::gate::connection_errorhandler;
681 void PQXX_PRIVATE register_errorhandler(
errorhandler *);
682 void PQXX_PRIVATE unregister_errorhandler(errorhandler *) noexcept;
684 friend class internal::gate::connection_transaction;
685 result PQXX_PRIVATE exec(
std::string_view);
688 void PQXX_PRIVATE unregister_transaction(transaction_base *) noexcept;
690 friend class internal::gate::connection_stream_from;
691 std::pair<
std::unique_ptr<
char,
std::function<
void(
char *)>>,
std::
size_t>
692 PQXX_PRIVATE read_copy_line();
694 friend class internal::gate::connection_stream_to;
695 void PQXX_PRIVATE write_copy_line(
std::string_view);
696 void PQXX_PRIVATE end_copy_write();
698 friend class internal::gate::connection_largeobject;
699 internal::pq::PGconn *raw_connection()
const {
return m_conn; }
701 friend class internal::gate::connection_notification_receiver;
705 friend class internal::gate::connection_pipeline;
706 void PQXX_PRIVATE start_exec(
char const query[]);
707 bool PQXX_PRIVATE consume_input() noexcept;
708 bool PQXX_PRIVATE is_busy() const noexcept;
709 internal::pq::PGresult *get_result();
711 friend class internal::gate::connection_dbtransaction;
712 friend class internal::gate::connection_sql_cursor;
714 result exec_params(
std::string_view query, internal::params const &args);
717 internal::pq::PGconn *m_conn =
nullptr;
724 using receiver_list =
727 receiver_list m_receivers;
738 template<typename T> inline
std::
string connection::quote(T const &t)
const 748 std::string buf{
'\''};
749 buf.resize(2 + 2 * text.size() + 1);
750 auto const content_bytes{esc_to_buf(text, buf.data() + 1)};
751 auto const closing_quote{1 + content_bytes};
752 buf[closing_quote] =
'\'';
753 auto const end{closing_quote + 1};
762 PQXX_LIBEXPORT
void wait_read(internal::pq::PGconn
const *);
764 wait_read(internal::pq::PGconn
const *,
long seconds,
long microseconds);
765 PQXX_LIBEXPORT
void wait_write(internal::pq::PGconn
const *);
768 #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:467
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:410
std::string to_string(field const &value)
Convert a field to a string.
Definition: result.cxx:477
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:545
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:517
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:511
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:141
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:486
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:472
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:536