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 ();
243 void inhibit_reactivation(
bool inhibit)
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 ();
436 void set_client_encoding(const PGSTD::
string &Encoding)
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 &);
735 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);
755 PGSTD::string quote(
const T &t)
758 return "'" + this->esc(
to_string(t)) +
"'";
785 void set_verbosity(error_verbosity verbosity)
throw();
802 PGSTD::vector<errorhandler *> get_errorhandlers()
const;
808 void close() throw ();
809 void wait_read() const;
810 void wait_read(
long seconds,
long microseconds) const;
811 void wait_write() 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 ();
831 prepare::internal::prepared_def &find_prepared(const PGSTD::
string &);
833 prepare::internal::prepared_def ®ister_prepared(const PGSTD::
string &);
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;
854 PGSTD::FILE *m_Trace;
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;
873 internal::reactivation_avoidance_counter m_reactivation_avoidance;
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);
897 void PQXX_PRIVATE UnregisterTransaction(transaction_base *) throw ();
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
943 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 () {}
955 class PQXX_LIBEXPORT scoped_noticer : errorhandler
958 scoped_noticer(connection_base &c, PGSTD::auto_ptr<noticer> t)
throw () :
959 errorhandler(c), m_noticer(t.release()) {}
961 scoped_noticer(connection_base &c, noticer *t)
throw () :
962 errorhandler(c), m_noticer(t) {}
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"