Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

connection.hxx

Go to the documentation of this file.
00001 /*-------------------------------------------------------------------------
00002  *
00003  *   FILE
00004  *      pqxx/connection.hxx
00005  *
00006  *   DESCRIPTION
00007  *      definition of the pqxx::connection and pqxx::lazyconnection classes.
00008  *   Different ways of setting up a backend connection.  
00009  *   DO NOT INCLUDE THIS FILE DIRECTLY; include pqxx/connection instead.
00010  *
00011  * Copyright (c) 2001-2004, Jeroen T. Vermeulen <jtv@xs4all.nl>
00012  *
00013  * See COPYING for copyright license.  If you did not receive a file called
00014  * COPYING with this source code, please notify the distributor of this mistake,
00015  * or contact the author.
00016  *
00017  *-------------------------------------------------------------------------
00018  */
00019 #include "pqxx/connection_base"
00020 
00021 
00022 /* Methods tested in eg. self-test program test001 are marked with "//[t1]"
00023  */
00024 
00025 namespace pqxx
00026 {
00027 
00029 
00045 class PQXX_LIBEXPORT connection : public connection_base
00046 {
00047 public:
00049 
00053   connection();                                                         //[t1]
00054 
00056 
00066   explicit connection(const PGSTD::string &ConnInfo);                   //[t2]
00067 
00069 
00077   explicit connection(const char ConnInfo[]);                           //[t3]
00078 
00079   virtual ~connection() throw ();
00080 
00081 private:
00082   virtual void startconnect() { do_startconnect(); }
00083   virtual void completeconnect() {}
00084 
00085   void do_startconnect() 
00086         { if (!get_conn()) set_conn(PQXXPQ::PQconnectdb(options())); }
00087 };
00088 
00089 
00091 
00099 class PQXX_LIBEXPORT lazyconnection : public connection_base
00100 {
00101 public:
00103   lazyconnection() : connection_base(0) {}                              //[t23]
00104 
00106 
00114   explicit lazyconnection(const PGSTD::string &ConnInfo) :              //[t21]
00115         connection_base(ConnInfo) {}
00116 
00118 
00127   explicit lazyconnection(const char ConnInfo[]) :                      //[t22]
00128         connection_base(ConnInfo) {}
00129 
00130   virtual ~lazyconnection() throw ();
00131 
00132 private:
00133   virtual void startconnect() {}
00134   virtual void completeconnect() 
00135         { if (!get_conn()) set_conn(PQXXPQ::PQconnectdb(options())); }
00136 };
00137 
00138 
00140 
00146 class PQXX_LIBEXPORT asyncconnection : public connection_base
00147 {
00148 public:
00150   asyncconnection();                                                    //[t63]
00151 
00153 
00161   explicit asyncconnection(const PGSTD::string &ConnInfo);              //[t65]
00162 
00164 
00173   explicit asyncconnection(const char ConnInfo[]);                      //[t64]
00174 
00175   virtual ~asyncconnection() throw ();
00176 
00177 private:
00178   virtual void startconnect() { do_startconnect(); }
00179   virtual void completeconnect();
00180   virtual void dropconnect() throw () { do_dropconnect(); }
00181 
00182   void do_startconnect();
00183   void do_dropconnect() throw () { m_connecting = false; }
00184 
00186   bool m_connecting;
00187 };
00188 
00189 
00191 
00196 class PQXX_LIBEXPORT nullconnection : public connection_base
00197 {
00198 public:
00200   nullconnection() : connection_base("") {}                             //[t0]
00202   explicit nullconnection(const PGSTD::string &c) :                     //[t0]
00203         connection_base(c) {}
00205   explicit nullconnection(const char c[]) :                             //[t0]
00206         connection_base(c) {}
00207 
00208   virtual ~nullconnection() throw ();
00209 
00210 private:
00211   virtual void startconnect() {}
00212   virtual void completeconnect() {}
00213 };
00214 
00215 }
00216 
00217 /* On Windows, any user-allocated notice processors, triggers etc. must be
00218  * deallocated in the user context.  Therefore we want these destructors to be
00219  * inlined.
00220  * On SUN's CC 5.1 compiler, on the other hand, there will be problems if we
00221  * don't have out-of-line virtual destructors in the leaf classes, so we must
00222  * not inline them.
00223  */
00224 #ifdef _WIN32
00225 inline pqxx::connection::~connection() throw () { close(); }
00226 inline pqxx::lazyconnection::~lazyconnection() throw () { close(); }
00227 inline pqxx::asyncconnection::~asyncconnection() throw () {do_dropconnect();close();}
00228 #endif
00229 

Generated on Mon Nov 15 11:27:59 2004 for libpqxx by  doxygen 1.3.9.1