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-2005, 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/libcompiler.h"
00020 
00021 #include "pqxx/connection_base"
00022 
00023 
00024 /* Methods tested in eg. self-test program test001 are marked with "//[t1]"
00025  */
00026 
00027 namespace pqxx
00028 {
00029 
00031 
00047 class PQXX_LIBEXPORT connection : public connection_base
00048 {
00049 public:
00051 
00055   connection();                                                         //[t1]
00056 
00058 
00068   explicit connection(const PGSTD::string &ConnInfo);                   //[t2]
00069 
00071 
00079   explicit connection(const char ConnInfo[]);                           //[t3]
00080 
00081   virtual ~connection() throw ();
00082 
00083 private:
00084   virtual void startconnect() { do_startconnect(); }
00085   virtual void completeconnect() {}
00086 
00087   void do_startconnect()
00088         { if (!get_conn()) set_conn(PQXXPQ::PQconnectdb(options())); }
00089 };
00090 
00091 
00093 
00101 class PQXX_LIBEXPORT lazyconnection : public connection_base
00102 {
00103 public:
00105   lazyconnection() : connection_base(0) {}                              //[t23]
00106 
00108 
00116   explicit lazyconnection(const PGSTD::string &ConnInfo) :              //[t21]
00117         connection_base(ConnInfo) {}
00118 
00120 
00129   explicit lazyconnection(const char ConnInfo[]) :                      //[t22]
00130         connection_base(ConnInfo) {}
00131 
00132   virtual ~lazyconnection() throw ();
00133 
00134 private:
00135   virtual void startconnect() {}
00136   virtual void completeconnect()
00137         { if (!get_conn()) set_conn(PQXXPQ::PQconnectdb(options())); }
00138 };
00139 
00140 
00142 
00148 class PQXX_LIBEXPORT asyncconnection : public connection_base
00149 {
00150 public:
00152   asyncconnection();                                                    //[t63]
00153 
00155 
00163   explicit asyncconnection(const PGSTD::string &ConnInfo);              //[t65]
00164 
00166 
00175   explicit asyncconnection(const char ConnInfo[]);                      //[t64]
00176 
00177   virtual ~asyncconnection() throw ();
00178 
00179 private:
00180   virtual void startconnect() { do_startconnect(); }
00181   virtual void completeconnect();
00182   virtual void dropconnect() throw () { do_dropconnect(); }
00183 
00184   void do_startconnect();
00185   void do_dropconnect() throw () { m_connecting = false; }
00186 
00188   bool m_connecting;
00189 };
00190 
00191 
00193 
00198 class PQXX_LIBEXPORT nullconnection : public connection_base
00199 {
00200 public:
00202   nullconnection() : connection_base("") {}                             //[t0]
00204   explicit nullconnection(const PGSTD::string &c) :                     //[t0]
00205         connection_base(c) {}
00207   explicit nullconnection(const char c[]) :                             //[t0]
00208         connection_base(c) {}
00209 
00210   virtual ~nullconnection() throw ();
00211 
00212 private:
00213   virtual void startconnect() {}
00214   virtual void completeconnect() {}
00215 };
00216 
00217 }
00218 
00219 /* On Windows, any user-allocated notice processors, triggers etc. must be
00220  * deallocated in the user context.  Therefore we want these destructors to be
00221  * inlined.
00222  * On SUN's CC 5.1 compiler, on the other hand, there will be problems if we
00223  * don't have out-of-line virtual destructors in the leaf classes, so we must
00224  * not inline them.
00225  */
00226 #ifdef _WIN32
00227 inline pqxx::connection::~connection() throw () { close(); }
00228 inline pqxx::lazyconnection::~lazyconnection() throw () { close(); }
00229 inline pqxx::asyncconnection::~asyncconnection() throw () {do_dropconnect();close();}
00230 #endif
00231 

Generated on Mon Feb 28 10:24:56 2005 for libpqxx by  doxygen 1.4.1