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" 52 void add(
int n) noexcept { m_counter += n; }
53 void clear() noexcept { m_counter = 0; }
54 int get()
const noexcept {
return m_counter; }
81 const std::string &user,
82 const std::string &password);
89 class connection_dbtransaction;
90 class connection_errorhandler;
91 class connection_largeobject;
92 class connection_notification_receiver;
93 class connection_parameterized_invocation;
94 class connection_pipeline;
95 class connection_prepare_invocation;
96 class connection_reactivation_avoidance_exemption;
97 class connection_sql_cursor;
98 class connection_transaction;
99 class const_connection_largeobject;
142 void disconnect() noexcept;
149 bool PQXX_PURE is_open()
const noexcept;
231 { m_inhibit_reactivation=inhibit; }
239 void simulate_failure();
243 void process_notice(
const char[]) noexcept;
245 void process_notice(
const std::string &) noexcept;
248 void trace(std::FILE *) noexcept;
262 const char *dbname();
268 const char *username();
274 const char *hostname();
292 int PQXX_PURE backendpid()
const noexcept;
310 int PQXX_PURE sock()
const noexcept;
350 {
return m_caps.test(c); }
361 int PQXX_PURE protocol_version()
const noexcept;
376 int PQXX_PURE server_version()
const noexcept;
387 { set_variable(
"CLIENT_ENCODING", Encoding); }
407 const std::string &Var,
408 const std::string &Value);
418 std::string get_variable(
const std::string &);
449 int await_notification();
458 int await_notification(
long seconds,
long microseconds);
520 void prepare(
const std::string &name,
const std::string &definition);
529 void prepare(
const std::string &definition);
532 void unprepare(
const std::string &name);
545 void prepare_now(
const std::string &name);
563 template<
typename TRANSACTOR>
564 void perform(
const TRANSACTOR &T,
int Attempts);
573 template<
typename TRANSACTOR>
580 std::string adorn_name(
const std::string &);
586 std::string esc(
const char str[]);
590 std::string esc(
const char str[],
size_t maxlen);
593 std::string esc(
const std::string &str);
596 std::string esc_raw(
const unsigned char str[],
size_t len);
603 {
return unesc_raw(text.c_str()); }
609 std::string unesc_raw(
const char *text);
612 std::string quote_raw(
const unsigned char str[],
size_t len);
615 std::string quote_name(
const std::string &identifier);
623 return "'" + this->esc(
to_string(t)) +
"'";
667 std::vector<errorhandler *> get_errorhandlers()
const;
673 void close() noexcept;
675 void wait_read(
long seconds,
long microseconds)
const;
680 result make_result(internal::pq::PGresult *rhs,
const std::string &query);
682 void PQXX_PRIVATE clearcaps() noexcept;
683 void PQXX_PRIVATE set_up_state();
684 void PQXX_PRIVATE check_result(
const result &);
686 void PQXX_PRIVATE internal_set_trace() noexcept;
687 int PQXX_PRIVATE PQXX_PURE status()
const noexcept;
689 friend class internal::gate::const_connection_largeobject;
690 const char * PQXX_PURE err_msg() const noexcept;
692 void PQXX_PRIVATE reset();
693 std::
string PQXX_PRIVATE raw_get_var(const
std::
string &);
694 void PQXX_PRIVATE process_notice_raw(const
char msg[]) noexcept;
696 void read_capabilities();
698 prepare::internal::prepared_def &find_prepared(const
std::
string &);
700 prepare::internal::prepared_def ®ister_prepared(const
std::
string &);
702 friend class internal::gate::connection_prepare_invocation;
710 result exec_prepared(const
std::
string &statement, const internal::params &);
711 bool prepared_exists(const
std::
string &) const;
714 internal::pq::PGconn *m_conn =
nullptr;
724 std::FILE *m_trace =
nullptr;
726 using receiver_list =
729 receiver_list m_receivers;
732 std::map<
std::
string,
std::
string> m_vars;
734 using PSMap =
std::map<
std::
string, prepare::internal::prepared_def>;
739 int m_serverversion = 0;
748 bool m_completed = false;
751 bool m_inhibit_reactivation = false;
754 std::bitset<cap_end> m_caps;
759 friend class internal::gate::connection_errorhandler;
760 void PQXX_PRIVATE register_errorhandler(
errorhandler *);
761 void PQXX_PRIVATE unregister_errorhandler(errorhandler *) noexcept;
763 friend class internal::gate::connection_transaction;
764 result PQXX_PRIVATE exec(const
char[],
int Retries);
766 void PQXX_PRIVATE unregister_transaction(transaction_base *) noexcept;
767 bool PQXX_PRIVATE read_copy_line(
std::
string &);
768 void PQXX_PRIVATE write_copy_line(const
std::
string &);
769 void PQXX_PRIVATE end_copy_write();
770 void PQXX_PRIVATE raw_set_var(const
std::
string &, const
std::
string &);
771 void PQXX_PRIVATE add_variables(const
std::map<
std::
string,
std::
string> &);
773 friend class internal::gate::connection_largeobject;
774 internal::pq::PGconn *raw_connection()
const {
return m_conn; }
776 friend class internal::gate::connection_notification_receiver;
780 friend class internal::gate::connection_pipeline;
781 void PQXX_PRIVATE start_exec(
const std::string &);
782 bool PQXX_PRIVATE consume_input() noexcept;
783 bool PQXX_PRIVATE is_busy() const noexcept;
784 int PQXX_PRIVATE encoding_code();
785 internal::pq::PGresult *get_result();
787 friend class internal::gate::connection_dbtransaction;
789 friend class internal::gate::connection_sql_cursor;
790 void add_reactivation_avoidance_count(
int);
792 friend class internal::gate::connection_reactivation_avoidance_exemption;
794 friend class internal::gate::connection_parameterized_invocation;
796 result parameterized_exec(
797 const
std::
string &query,
798 const
char *const params[],
799 const
int paramlengths[],
800 const
int binaries[],
804 const
std::
string &query,
805 const internal::params &args);
831 void wait_read(
const internal::pq::PGconn *);
832 void wait_read(
const internal::pq::PGconn *,
long seconds,
long microseconds);
833 void wait_write(
const internal::pq::PGconn *);
838 #include "pqxx/compiler-internal-post.hxx" Binary data corresponding to PostgreSQL's "BYTEA" binary-string type.
Definition: binarystring.hxx:53
Definition: connectionpolicy.hxx:31
Definition: connection_base.hxx:47
reactivation_avoidance_counter()=default
void perform(const TRANSACTOR &T)
Definition: connection_base.hxx:574
void add(int n) noexcept
Definition: connection_base.hxx:52
Cursor with SQL positioning semantics.
Definition: cursor.hxx:164
The home of all libpqxx classes, functions, templates, etc.
Definition: array.hxx:22
Scoped exemption to reactivation avoidance.
Definition: connection_base.hxx:816
capability
Session capabilities.
Definition: connection_base.hxx:325
void wait_read(const internal::pq::PGconn *)
Base class for error-handler callbacks.
Definition: errorhandler.hxx:49
auto perform(const TRANSACTION_CALLBACK &callback, int attempts=3) -> decltype(callback())
Simple way to execute a transaction with automatic retry.
Definition: transactor.hxx:100
error_verbosity
Error verbosity levels.
Definition: connection_base.hxx:633
void wait_write(const internal::pq::PGconn *)
Result set containing data returned by a query or command.
Definition: result.hxx:67
Interface definition (and common code) for "transaction" classes.
Definition: transaction_base.hxx:130
Definition: notification.hxx:53
error_verbosity get_verbosity() const noexcept
Retrieve current error verbosity.
Definition: connection_base.hxx:652
void set_client_encoding(const std::string &Encoding)
Set client-side character encoding.
Definition: connection_base.hxx:386
std::string quote(const T &t)
Represent object as SQL string, including quoting & escaping.
Definition: connection_base.hxx:620
std::string unesc_raw(const std::string &text)
Unescape binary data, e.g. from a table field or notification payload.
Definition: connection_base.hxx:602
std::string to_string(const field &Obj)
Convert a field to a string.
Definition: result.cxx:434
std::string encrypt_password(const std::string &user, const std::string &password)
Encrypt password for given user.
Definition: connection_base.cxx:82
connection_base abstract base class; represents a connection to a database.
Definition: connection_base.hxx:138
void clear() noexcept
Definition: connection_base.hxx:53
Not a capability value; end-of-enumeration marker.
Definition: connection_base.hxx:328
bool supports(capability c) const noexcept
Does this connection seem to support the given capability?
Definition: connection_base.hxx:349
void inhibit_reactivation(bool inhibit)
Disallow (or permit) connection recovery.
Definition: connection_base.hxx:230
Traits class for use in string conversions.
Definition: strconv.hxx:39
void close_connection() noexcept
Definition: connection_base.hxx:822