13 #ifndef PQXX_H_CONNECTION 14 #define PQXX_H_CONNECTION 16 #include "pqxx/compiler-public.hxx" 17 #include "pqxx/internal/compiler-internal-pre.hxx" 22 #include <string_view> 24 #include "pqxx/errorhandler.hxx" 25 #include "pqxx/except.hxx" 26 #include "pqxx/prepared_statement.hxx" 27 #include "pqxx/strconv.hxx" 28 #include "pqxx/util.hxx" 29 #include "pqxx/zview.hxx" 67 class connection_dbtransaction;
68 class connection_errorhandler;
69 class connection_largeobject;
70 class connection_notification_receiver;
71 class connection_pipeline;
72 class connection_sql_cursor;
73 class connection_stream_from;
74 class connection_stream_to;
75 class connection_transaction;
76 class const_connection_largeobject;
83 [[nodiscard]] std::string PQXX_LIBEXPORT
87 [[nodiscard]]
inline std::string
165 catch (std::exception
const &)
183 [[nodiscard]]
bool PQXX_PURE is_open()
const noexcept;
186 void process_notice(
char const[]) noexcept;
190 process_notice(
zview{msg});
196 void process_notice(
zview) noexcept;
199 void trace(std::FILE *) noexcept;
211 [[nodiscard]]
char const *dbname()
const;
215 [[nodiscard]]
char const *username()
const;
218 [[nodiscard]]
char const *hostname()
const;
221 [[nodiscard]]
char const *port()
const;
224 [[nodiscard]]
int PQXX_PURE backendpid()
const noexcept;
242 [[nodiscard]]
int PQXX_PURE sock()
const noexcept;
248 [[nodiscard]]
int PQXX_PURE protocol_version()
const noexcept;
263 [[nodiscard]]
int PQXX_PURE server_version()
const noexcept;
287 [[nodiscard]] std::string get_client_encoding()
const;
296 set_client_encoding(encoding.c_str());
303 void set_client_encoding(
char const encoding[]);
306 [[nodiscard]]
int PQXX_PRIVATE encoding_id()
const;
326 void set_variable(std::string_view var, std::string_view value);
332 std::string get_variable(std::string_view);
365 int await_notification();
376 int await_notification(
long seconds,
long microseconds);
407 char const user[],
char const password[],
char const *algorithm =
nullptr);
408 [[nodiscard]] std::string
464 void prepare(
char const name[],
char const definition[]);
466 void prepare(std::string
const &name, std::string
const &definition)
468 prepare(name.c_str(), definition.c_str());
484 void prepare(
char const definition[]);
488 void unprepare(std::string_view name);
498 [[nodiscard]] std::string adorn_name(std::string_view);
510 [[nodiscard]] std::string
esc(
char const text[],
size_t maxlen)
const 512 return esc(std::string_view(text, maxlen));
516 [[nodiscard]] std::string
esc(
char const text[])
const 518 return esc(std::string_view(text));
525 [[nodiscard]] std::string esc(std::string_view text)
const;
528 [[nodiscard]] std::string
529 esc_raw(
unsigned char const bin[],
size_t len)
const;
535 [[nodiscard]] std::string
unesc_raw(std::string
const &text)
const 537 return unesc_raw(text.c_str());
546 return unesc_raw(text.
c_str());
553 [[nodiscard]] std::string unesc_raw(
char const text[])
const;
556 [[nodiscard]] std::string
557 quote_raw(
unsigned char const bin[],
size_t len)
const;
560 [[nodiscard]] std::string quote_name(std::string_view identifier)
const;
566 template<
typename T>[[nodiscard]]
inline std::string quote(T
const &t)
const;
568 [[nodiscard]] std::string quote(
binarystring const &)
const;
594 [[nodiscard]] std::string
595 esc_like(std::string_view text,
char escape_char =
'\\')
const;
630 [[nodiscard]] std::vector<errorhandler *> get_errorhandlers()
const;
639 [[nodiscard]] std::string connection_string()
const;
648 void init(
char const options[]);
651 void wait_read(
long seconds,
long microseconds)
const;
654 internal::pq::PGresult *rhs, std::shared_ptr<std::string>
const &query);
656 void PQXX_PRIVATE set_up_state();
657 void PQXX_PRIVATE check_result(
result const &);
659 int PQXX_PRIVATE PQXX_PURE status()
const noexcept;
666 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 bool PQXX_PRIVATE read_copy_line(
std::
string &);
693 friend class internal::gate::connection_stream_to;
694 void PQXX_PRIVATE write_copy_line(
std::string_view);
695 void PQXX_PRIVATE end_copy_write();
697 friend class internal::gate::connection_largeobject;
698 internal::pq::PGconn *raw_connection()
const {
return m_conn; }
700 friend class internal::gate::connection_notification_receiver;
704 friend class internal::gate::connection_pipeline;
705 void PQXX_PRIVATE start_exec(
char const query[]);
706 bool PQXX_PRIVATE consume_input() noexcept;
707 bool PQXX_PRIVATE is_busy() const noexcept;
708 internal::pq::PGresult *get_result();
710 friend class internal::gate::connection_dbtransaction;
711 friend class internal::gate::connection_sql_cursor;
713 result exec_params(
std::string_view query, internal::params const &args);
716 internal::pq::PGconn *m_conn =
nullptr;
723 using receiver_list =
726 receiver_list m_receivers;
737 template<typename T> inline
std::
string connection::quote(T const &t)
const 747 std::string buf{
'\''};
748 buf.resize(2 + 2 * text.size() + 1);
749 auto const content_bytes{esc_to_buf(text, buf.data() + 1)};
750 auto const closing_quote{1 + content_bytes};
751 buf[closing_quote] =
'\'';
752 auto const end{closing_quote + 1};
761 PQXX_LIBEXPORT
void wait_read(internal::pq::PGconn
const *);
763 wait_read(internal::pq::PGconn
const *,
long seconds,
long microseconds);
764 PQXX_LIBEXPORT
void wait_write(internal::pq::PGconn
const *);
767 #include "pqxx/internal/compiler-internal-post.hxx" Private namespace for libpqxx's internal use; do not access.
Definition: connection.hxx:59
bool is_null(TYPE const &value)
Is value null?
Definition: strconv.hxx:286
void prepare(std::string const &name, std::string const &definition)
Definition: connection.hxx:466
void wait_write(internal::pq::PGconn const *)
Definition: connection.cxx:939
connection(zview options)
Definition: connection.hxx:149
std::string encrypt_password(zview user, zview password, zview algorithm)
Definition: connection.hxx:409
std::string to_string(field const &value)
Convert a field to a string.
Definition: result.cxx:478
void set_client_encoding(std::string const &encoding)
Set client-side character encoding, by name.
Definition: connection.hxx:294
std::string unesc_raw(zview text) const
Unescape binary data, e.g. from a table field or notification payload.
Definition: connection.hxx:544
connection(char const options[])
Definition: connection.hxx:143
error_verbosity
Error verbosity levels.
Definition: connection.hxx:95
std::string esc(char const text[]) const
Escape string for use as SQL string literal on this connection.
Definition: connection.hxx:516
The home of all libpqxx classes, functions, templates, etc.
Definition: array.hxx:25
Connection to a database.
Definition: connection.hxx:135
constexpr char const * c_str() const noexcept
Either a null pointer, or a zero-terminated text buffer.
Definition: zview.hxx:41
std::string esc(char const text[], size_t maxlen) const
Escape string for use as SQL string literal on this connection.
Definition: connection.hxx:510
void process_notice(std::string const &msg) noexcept
Invoke notice processor function. Newline at end is recommended.
Definition: connection.hxx:188
Binary data corresponding to PostgreSQL's "BYTEA" binary-string type.
Definition: binarystring.hxx:53
Interface definition (and common code) for "transaction" classes.
Definition: transaction_base.hxx:97
~connection()
Definition: connection.hxx:159
void check_version()
Definition: util.hxx:135
connection(std::string const &options)
Definition: connection.hxx:140
Definition: connection.hxx:65
Result set containing data returned by a query or command.
Definition: result.hxx:70
void prepare(zview definition)
Definition: connection.hxx:485
Definition: notification.hxx:55
Base class for error-handler callbacks.
Definition: errorhandler.hxx:52
std::string encrypt_password(char const user[], char const password[])
Encrypt a password.
Definition: connection.cxx:93
Marker-type wrapper: zero-terminated std::string_view.
Definition: zview.hxx:32
void prepare(zview name, zview definition)
Definition: connection.hxx:471
void wait_read(internal::pq::PGconn const *)
Definition: connection.cxx:919
connection()
Definition: connection.hxx:138
std::string unesc_raw(std::string const &text) const
Unescape binary data, e.g. from a table field or notification payload.
Definition: connection.hxx:535