19 #ifndef PQXX_H_CONNECTION_BASE 20 #define PQXX_H_CONNECTION_BASE 22 #include "pqxx/compiler-public.hxx" 23 #include "pqxx/compiler-internal-pre.hxx" 30 #include "pqxx/errorhandler" 31 #include "pqxx/except" 32 #include "pqxx/prepared_statement" 33 #include "pqxx/strconv" 49 class connectionpolicy;
50 class notification_receiver;
52 class transaction_base;
64 void add(
int n)
throw () { m_counter += n; }
65 void clear() throw () { m_counter = 0; }
66 int get()
const throw () {
return m_counter; }
95 const PGSTD::string &user,
96 const PGSTD::string &password);
103 class connection_dbtransaction;
104 class connection_errorhandler;
105 class connection_largeobject;
106 class connection_notification_receiver;
107 class connection_parameterized_invocation;
108 class connection_pipeline;
109 class connection_prepare_invocation;
110 class connection_reactivation_avoidance_exemption;
111 class connection_sql_cursor;
112 class connection_transaction;
155 void disconnect()
throw ();
162 bool PQXX_PURE is_open()
const throw ();
244 { m_inhibit_reactivation=inhibit; }
252 void simulate_failure();
256 void process_notice(
const char[])
throw ();
258 void process_notice(
const PGSTD::string &)
throw ();
261 void trace(PGSTD::FILE *)
throw ();
275 const char *dbname();
281 const char *username();
287 const char *hostname();
305 int PQXX_PURE backendpid()
const throw ();
322 int PQXX_PURE sock()
const throw ();
411 int PQXX_PURE protocol_version()
const throw ();
426 int PQXX_PURE server_version()
const throw ();
437 { set_variable(
"CLIENT_ENCODING", Encoding); }
456 void set_variable(
const PGSTD::string &Var,
457 const PGSTD::string &Value);
467 PGSTD::string get_variable(
const PGSTD::string &);
498 int await_notification();
507 int await_notification(
long seconds,
long microseconds);
581 void prepare(
const PGSTD::string &name,
const PGSTD::string &definition);
590 void prepare(
const PGSTD::string &definition);
593 void unprepare(
const PGSTD::string &name);
606 void prepare_now(
const PGSTD::string &name);
646 template<
typename TRANSACTOR>
647 void perform(
const TRANSACTOR &T,
int Attempts);
653 template<
typename TRANSACTOR>
664 PGSTD::string adorn_name(
const PGSTD::string &);
734 PGSTD::string esc(
const char str[]);
738 PGSTD::string esc(
const char str[],
size_t maxlen);
741 PGSTD::string esc(
const PGSTD::string &str);
744 PGSTD::string esc_raw(
const unsigned char str[],
size_t len);
747 PGSTD::string quote_raw(
const unsigned char str[],
size_t len);
750 PGSTD::string quote_name(
const PGSTD::string &identifier);
758 return "'" + this->esc(
to_string(t)) +
"'";
802 PGSTD::vector<errorhandler *> get_errorhandlers()
const;
808 void close()
throw ();
810 void wait_read(
long seconds,
long microseconds)
const;
815 result make_result(internal::pq::PGresult *rhs,
const PGSTD::string &query);
817 void PQXX_PRIVATE clearcaps()
throw ();
818 void PQXX_PRIVATE SetupState();
819 void PQXX_PRIVATE check_result(
const result &);
821 void PQXX_PRIVATE InternalSetTrace()
throw ();
822 int PQXX_PRIVATE PQXX_PURE Status()
const throw ();
823 const char * PQXX_PURE ErrMsg()
const throw ();
824 void PQXX_PRIVATE Reset();
825 void PQXX_PRIVATE RestoreVars();
826 PGSTD::string PQXX_PRIVATE RawGetVar(
const PGSTD::string &);
827 void PQXX_PRIVATE process_notice_raw(
const char msg[])
throw ();
829 void read_capabilities()
throw ();
835 friend class internal::gate::connection_prepare_invocation;
836 result prepared_exec(
const PGSTD::string &,
841 bool prepared_exists(
const PGSTD::string &)
const;
844 internal::pq::PGconn *m_Conn;
851 PGSTD::list<errorhandler *> m_errorhandlers;
854 PGSTD::FILE *m_Trace;
856 typedef PGSTD::multimap<PGSTD::string, pqxx::notification_receiver *>
859 receiver_list m_receivers;
862 PGSTD::map<PGSTD::string, PGSTD::string> m_Vars;
864 typedef PGSTD::map<PGSTD::string, prepare::internal::prepared_def> PSMap;
882 bool m_inhibit_reactivation;
885 PGSTD::bitset<cap_end> m_caps;
890 friend class internal::gate::connection_errorhandler;
891 void PQXX_PRIVATE register_errorhandler(
errorhandler *);
892 void PQXX_PRIVATE unregister_errorhandler(
errorhandler *)
throw ();
894 friend class internal::gate::connection_transaction;
895 result PQXX_PRIVATE Exec(
const char[],
int Retries);
898 bool PQXX_PRIVATE ReadCopyLine(PGSTD::string &);
899 void PQXX_PRIVATE WriteCopyLine(
const PGSTD::string &);
900 void PQXX_PRIVATE EndCopyWrite();
901 void PQXX_PRIVATE RawSetVar(
const PGSTD::string &,
const PGSTD::string &);
902 void PQXX_PRIVATE AddVariables(
const PGSTD::map<PGSTD::string,
905 friend class internal::gate::connection_largeobject;
906 internal::pq::PGconn *RawConnection()
const {
return m_Conn; }
908 friend class internal::gate::connection_notification_receiver;
912 friend class internal::gate::connection_pipeline;
913 void PQXX_PRIVATE start_exec(
const PGSTD::string &);
914 bool PQXX_PRIVATE consume_input() throw ();
915 bool PQXX_PRIVATE is_busy() const throw ();
916 int PQXX_PRIVATE encoding_code();
917 internal::pq::PGresult *get_result();
919 friend class internal::gate::connection_dbtransaction;
921 friend class internal::gate::connection_sql_cursor;
922 void add_reactivation_avoidance_count(
int);
924 friend class internal::gate::connection_reactivation_avoidance_exemption;
926 friend class internal::gate::connection_parameterized_invocation;
927 result parameterized_exec(
928 const PGSTD::
string &query,
929 const
char *const params[],
930 const
int paramlengths[],
931 const
int binaries[],
936 connection_base &operator=(const connection_base &);
941 #ifdef PQXX_HAVE_AUTO_PTR 942 struct PQXX_LIBEXPORT PQXX_NOVTABLE noticer :
944 PGSTD::unary_function<const char[], void>
946 virtual ~noticer()
throw () {}
947 virtual void operator()(
const char[])
throw () =0;
950 struct PQXX_LIBEXPORT nonnoticer : noticer
952 virtual void operator()(
const char[])
throw () {}
958 scoped_noticer(connection_base &c, PGSTD::auto_ptr<noticer> t)
throw () :
961 scoped_noticer(connection_base &c, noticer *t)
throw () :
963 virtual bool operator()(
const char msg[])
throw ()
969 PGSTD::auto_ptr<noticer> m_noticer;
972 class PQXX_LIBEXPORT disable_noticer : scoped_noticer
975 explicit disable_noticer(connection_base &c) :
976 scoped_noticer(c,
new nonnoticer) {}
994 connection_base &m_home;
1000 void wait_read(
const internal::pq::PGconn *);
1001 void wait_read(
const internal::pq::PGconn *,
long seconds,
long microseconds);
1002 void wait_write(
const internal::pq::PGconn *);
1008 #include "pqxx/compiler-internal-post.hxx" Result set containing data returned by a query or command.
Definition: result.hxx:81
connection_base abstract base class; represents a connection to a database.
Definition: connection_base.hxx:151
bool supports(capability c) const
Does this connection seem to support the given capability?
Definition: connection_base.hxx:396
Definition: notification.hxx:59
void clear()
Definition: connection_base.hxx:65
Ensure proper opening/closing of GUEST objects related to a "host" object.
Definition: util.hxx:699
void set_client_encoding(const std::string &Encoding)
Set client-side character encoding.
Definition: connection_base.hxx:436
Can transactions be nested in other transactions?
Definition: connection_base.hxx:345
Do prepared statements support varargs?
Definition: connection_base.hxx:363
std::string encrypt_password(const std::string &user, const std::string &password)
Encrypt password for given user. Requires libpq 8.2 or better.
void close_connection()
Definition: connection_base.hxx:991
Internal representation of a prepared statement definition.
Definition: prepared_statement.hxx:214
Definition: binarystring.hxx:59
Can we specify WITH OIDS with CREATE TABLE?
Definition: connection_base.hxx:342
reactivation_avoidance_counter()
Definition: connection_base.hxx:62
Can cursors be declared WITH HOLD?
Definition: connection_base.hxx:350
Can transactions be READ ONLY?
Definition: connection_base.hxx:360
void inhibit_reactivation(bool inhibit)
Disallow (or permit) connection recovery.
Definition: connection_base.hxx:243
void add(int n)
Definition: connection_base.hxx:64
Definition: connectionpolicy.hxx:39
Can cursors fetch zero elements? (Used to trigger a "fetch all")
Definition: connection_base.hxx:354
Definition: connection_base.hxx:59
Can we ask what table column a result column came from?
Definition: connection_base.hxx:357
Traits class for use in string conversions.
Definition: strconv.hxx:46
std::string to_string(const field &Obj)
Convert a field to a string.
Definition: result.hxx:467
Cursor with SQL positioning semantics.
Definition: cursor.hxx:194
Can notifications carry payloads?
Definition: connection_base.hxx:372
void wait_read(const internal::pq::PGconn *)
void perform(const TRANSACTOR &T)
Perform the transaction defined by a transactor-based object.
Definition: connection_base.hxx:654
error_verbosity get_verbosity() const
Retrieve current error verbosity.
Definition: connection_base.hxx:787
Base class for error-handler callbacks.
Definition: errorhandler.hxx:57
capability
Session capabilities.
Definition: connection_base.hxx:336
std::string quote(const T &t)
Represent object as SQL string, including quoting & escaping.
Definition: connection_base.hxx:755
Can cursors be declared SCROLL?
Definition: connection_base.hxx:348
Does the backend support prepared statements? (If not, we emulate them)
Definition: connection_base.hxx:339
void wait_write(const internal::pq::PGconn *)
Scoped exemption to reactivation avoidance.
Definition: connection_base.hxx:985
Can this connection execute parameterized statements?
Definition: connection_base.hxx:369
Can cursors be updateable?
Definition: connection_base.hxx:352
The home of all libpqxx classes, functions, templates, etc.
Definition: basic_connection.hxx:35
Definition: transaction_base.hxx:133
error_verbosity
Error verbosity levels.
Definition: connection_base.hxx:768
Is the unnamed prepared statement supported?
Definition: connection_base.hxx:366