13 #ifndef PQXX_H_CONNECTION_BASE 14 #define PQXX_H_CONNECTION_BASE 16 #include "pqxx/compiler-public.hxx" 17 #include "pqxx/compiler-internal-pre.hxx" 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/version.hxx" 53 void add(
int n) noexcept { m_counter += n; }
54 void clear() noexcept { m_counter = 0; }
55 int get()
const noexcept {
return m_counter; }
82 const std::string &user,
83 const std::string &password);
90 class connection_dbtransaction;
91 class connection_errorhandler;
92 class connection_largeobject;
93 class connection_notification_receiver;
94 class connection_parameterized_invocation;
95 class connection_pipeline;
96 class connection_prepare_invocation;
97 class connection_reactivation_avoidance_exemption;
98 class connection_sql_cursor;
99 class connection_transaction;
100 class const_connection_largeobject;
143 void disconnect() noexcept;
150 bool PQXX_PURE is_open()
const noexcept;
232 { m_inhibit_reactivation=inhibit; }
240 void simulate_failure();
244 void process_notice(
const char[]) noexcept;
246 void process_notice(
const std::string &) noexcept;
249 void trace(std::FILE *) noexcept;
263 const char *dbname();
269 const char *username();
275 const char *hostname();
293 int PQXX_PURE backendpid()
const noexcept;
311 int PQXX_PURE sock()
const noexcept;
351 {
return m_caps.test(c); }
362 int PQXX_PURE protocol_version()
const noexcept;
377 int PQXX_PURE server_version()
const noexcept;
388 { set_variable(
"CLIENT_ENCODING", Encoding); }
408 const std::string &Var,
409 const std::string &Value);
419 std::string get_variable(
const std::string &);
450 int await_notification();
459 int await_notification(
long seconds,
long microseconds);
521 void prepare(
const std::string &name,
const std::string &definition);
530 void prepare(
const std::string &definition);
533 void unprepare(
const std::string &name);
546 void prepare_now(
const std::string &name);
564 template<
typename TRANSACTOR>
565 void perform(
const TRANSACTOR &T,
int Attempts);
574 template<
typename TRANSACTOR>
581 std::string adorn_name(
const std::string &);
587 std::string esc(
const char str[]);
591 std::string esc(
const char str[],
size_t maxlen);
594 std::string esc(
const std::string &str);
597 std::string esc_raw(
const unsigned char str[],
size_t len);
604 {
return unesc_raw(text.c_str()); }
610 std::string unesc_raw(
const char *text);
613 std::string quote_raw(
const unsigned char str[],
size_t len);
616 std::string quote_name(
const std::string &identifier);
624 return "'" + this->esc(
to_string(t)) +
"'";
668 std::vector<errorhandler *> get_errorhandlers()
const;
694 static const auto version_ok =
702 void close() noexcept;
704 void wait_read(
long seconds,
long microseconds)
const;
709 result make_result(internal::pq::PGresult *rhs,
const std::string &query);
711 void clearcaps() noexcept;
712 void PQXX_PRIVATE set_up_state();
713 void PQXX_PRIVATE check_result(
const result &);
715 void PQXX_PRIVATE internal_set_trace() noexcept;
716 int PQXX_PRIVATE PQXX_PURE status()
const noexcept;
718 friend class internal::gate::const_connection_largeobject;
719 const char * PQXX_PURE err_msg() const noexcept;
721 void PQXX_PRIVATE reset();
722 std::
string PQXX_PRIVATE raw_get_var(const
std::
string &);
723 void PQXX_PRIVATE process_notice_raw(const
char msg[]) noexcept;
725 void read_capabilities();
727 prepare::internal::prepared_def &find_prepared(const
std::
string &);
729 prepare::internal::prepared_def ®ister_prepared(const
std::
string &);
731 friend class internal::gate::connection_prepare_invocation;
739 result exec_prepared(const
std::
string &statement, const internal::params &);
740 bool prepared_exists(const
std::
string &) const;
743 internal::pq::PGconn *m_conn =
nullptr;
753 std::FILE *m_trace =
nullptr;
755 using receiver_list =
758 receiver_list m_receivers;
761 std::map<
std::
string,
std::
string> m_vars;
763 using PSMap =
std::map<
std::
string, prepare::internal::prepared_def>;
768 int m_serverversion = 0;
777 bool m_completed = false;
780 bool m_inhibit_reactivation = false;
783 std::bitset<cap_end> m_caps;
788 friend class internal::gate::connection_errorhandler;
789 void PQXX_PRIVATE register_errorhandler(
errorhandler *);
790 void PQXX_PRIVATE unregister_errorhandler(errorhandler *) noexcept;
792 friend class internal::gate::connection_transaction;
793 result PQXX_PRIVATE exec(const
char[],
int Retries);
795 void PQXX_PRIVATE unregister_transaction(transaction_base *) noexcept;
796 bool PQXX_PRIVATE read_copy_line(
std::
string &);
797 void PQXX_PRIVATE write_copy_line(const
std::
string &);
798 void PQXX_PRIVATE end_copy_write();
799 void PQXX_PRIVATE raw_set_var(const
std::
string &, const
std::
string &);
800 void PQXX_PRIVATE add_variables(const
std::map<
std::
string,
std::
string> &);
802 friend class internal::gate::connection_largeobject;
803 internal::pq::PGconn *raw_connection()
const {
return m_conn; }
805 friend class internal::gate::connection_notification_receiver;
809 friend class internal::gate::connection_pipeline;
810 void PQXX_PRIVATE start_exec(
const std::string &);
811 bool PQXX_PRIVATE consume_input() noexcept;
812 bool PQXX_PRIVATE is_busy() const noexcept;
813 int PQXX_PRIVATE encoding_code();
814 internal::pq::PGresult *get_result();
816 friend class internal::gate::connection_dbtransaction;
818 friend class internal::gate::connection_sql_cursor;
819 void add_reactivation_avoidance_count(
int);
821 friend class internal::gate::connection_reactivation_avoidance_exemption;
823 friend class internal::gate::connection_parameterized_invocation;
825 result parameterized_exec(
826 const
std::
string &query,
827 const
char *const params[],
828 const
int paramlengths[],
829 const
int binaries[],
833 const
std::
string &query,
834 const internal::params &args);
860 void wait_read(
const internal::pq::PGconn *);
861 void wait_read(
const internal::pq::PGconn *,
long seconds,
long microseconds);
862 void wait_write(
const internal::pq::PGconn *);
867 #include "pqxx/compiler-internal-post.hxx" void wait_write(const internal::pq::PGconn *)
Definition: connection_base.cxx:1201
Binary data corresponding to PostgreSQL's "BYTEA" binary-string type.
Definition: binarystring.hxx:53
Result set containing data returned by a query or command.
Definition: result.hxx:65
std::string unesc_raw(const std::string &text)
Unescape binary data, e.g. from a table field or notification payload.
Definition: connection_base.hxx:603
Definition: connectionpolicy.hxx:31
std::string quote(const T &t)
Represent object as SQL string, including quoting & escaping.
Definition: connection_base.hxx:621
std::string to_string(const field &Obj)
Convert a field to a string.
Definition: result.cxx:434
Definition: connection_base.hxx:48
void add(int n) noexcept
Definition: connection_base.hxx:53
void wait_read(const internal::pq::PGconn *)
Definition: connection_base.cxx:1181
bool supports(capability c) const noexcept
Does this connection seem to support the given capability?
Definition: connection_base.hxx:350
Cursor with SQL positioning semantics.
Definition: cursor.hxx:164
error_verbosity
Error verbosity levels.
Definition: connection_base.hxx:634
Not a capability value; end-of-enumeration marker.
Definition: connection_base.hxx:329
Base class for error-handler callbacks.
Definition: errorhandler.hxx:49
std::string encrypt_password(const std::string &user, const std::string &password)
Encrypt password for given user.
Definition: connection_base.cxx:83
void perform(const TRANSACTOR &T)
Definition: connection_base.hxx:575
connection_base(connectionpolicy &pol)
Definition: connection_base.hxx:671
The home of all libpqxx classes, functions, templates, etc.
Definition: array.hxx:22
Scoped exemption to reactivation avoidance.
Definition: connection_base.hxx:845
int check_library_version< PQXX_VERSION_MAJOR, PQXX_VERSION_MINOR >() noexcept
Definition: version.cxx:13
Interface definition (and common code) for "transaction" classes.
Definition: transaction_base.hxx:130
void clear() noexcept
Definition: connection_base.hxx:54
void close_connection() noexcept
Definition: connection_base.hxx:851
connection_base abstract base class; represents a connection to a database.
Definition: connection_base.hxx:139
void inhibit_reactivation(bool inhibit)
Disallow (or permit) connection recovery.
Definition: connection_base.hxx:231
reactivation_avoidance_counter()=default
Traits class for use in string conversions.
Definition: strconv.hxx:52
void set_client_encoding(const std::string &Encoding)
Set client-side character encoding.
Definition: connection_base.hxx:387
Definition: notification.hxx:55
capability
Session capabilities.
Definition: connection_base.hxx:326
error_verbosity get_verbosity() const noexcept
Retrieve current error verbosity.
Definition: connection_base.hxx:653
auto perform(const TRANSACTION_CALLBACK &callback, int attempts=3) -> decltype(callback())
Simple way to execute a transaction with automatic retry.
Definition: transactor.hxx:100
void ignore_unused(T)
Suppress compiler warning about an unused item.
Definition: util.hxx:37