Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members | Related Pages | Examples

psqldriver.h

Go to the documentation of this file.
00001 /*
00002  *   P::Classes - Portable C++ Application Framework
00003  *   Copyright (C) 2000-2002  Christian Prochnow <cproch@seculogix.de>
00004  *
00005  *   This library is free software; you can redistribute it and/or
00006  *   modify it under the terms of the GNU Lesser General Public
00007  *   License as published by the Free Software Foundation; either
00008  *   version 2 of the License, or (at your option) any later version.
00009  *
00010  *   This library is distributed in the hope that it will be useful,
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  *   Lesser General Public License for more details.
00014  *
00015  *   You should have received a copy of the GNU Lesser General Public
00016  *   License along with this library; if not, write to the Free Software
00017  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018  */
00019 
00020 #ifndef _psqldriver_h_
00021 #define _psqldriver_h_
00022 
00023 #include <pclasses/ptypes.h>
00024 #include <pclasses/pexport.h>
00025 #include <pclasses/psqlerror.h>
00026 #include <pclasses/psqlvalue.h>
00027 #include <memory>
00028 #include <string>
00029 
00034 namespace P {
00035 
00036 #ifdef HAVE_64BIT_INT
00037 typedef uint64_t sqlcount_t;
00038 #else
00039 typedef uint32_t sqlcount_t;
00040 #endif
00041 
00043 
00047 class PSQL_EXPORT SQLDriver {
00048   public:
00049   
00051 
00055     class PSQL_EXPORT ResultHandle {
00056       public:
00057         ResultHandle();
00058         virtual ~ResultHandle();
00059         
00060         virtual unsigned int columnCount() const throw() = 0;
00061         virtual std::string columnName(unsigned int pos) const = 0;
00062         
00063         virtual bool fetch() = 0;
00064         
00065         virtual const SQLValue& value(const std::string& name) = 0;
00066         virtual const SQLValue& value(unsigned int pos) = 0;
00067     };
00068   
00070 
00074     class PSQL_EXPORT StatementHandle {
00075       public:
00076         StatementHandle();
00077         virtual ~StatementHandle();
00078     
00079         virtual void prepare(const std::string& stmt) = 0;
00080         virtual void exec() = 0;
00081 
00082         virtual std::auto_ptr<ResultHandle> result() = 0;
00083 
00084         virtual sqlcount_t affectedRows() const throw() = 0;
00085 
00086         virtual std::string sqlstr(const SQLValue& val) const throw() = 0;
00087     };
00088         
00090 
00094     class PSQL_EXPORT ConnectionHandle {
00095       public:
00096         enum state_t {
00097           Disconnected,
00098           Connected
00099         };
00100       
00101         ConnectionHandle();
00102         virtual ~ConnectionHandle();
00103         
00104         inline state_t state() const throw()
00105         { return m_state; }
00106         
00107         virtual std::auto_ptr<StatementHandle> createStmt() = 0;
00108         
00109         virtual void commit() = 0;
00110         virtual void rollback() = 0;
00111         
00112       protected:
00113         inline void setState(state_t st) throw()
00114         { m_state = st; }
00115         
00116       private:
00117         state_t m_state;
00118     };
00119   
00120     SQLDriver();
00121     virtual ~SQLDriver();
00122     
00123     virtual ConnectionHandle* connect(const std::string& user, const std::string& passwd, 
00124                                       const std::string& db, const std::string& host) throw(SQLError) = 0;
00125                                       
00126     virtual void close(ConnectionHandle* handle) throw() = 0;
00127 
00128 };
00129 
00130 }
00131 
00132 #endif

Generated on Fri Mar 12 21:08:31 2004 for P::Classes by doxygen 1.3.3