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

psqlstatement.h

Go to the documentation of this file.
00001 /*
00002  *   P::Classes - Portable C++ Application Framework
00003  *   Copyright (C) 2000-2004  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 _psqlstatement_h_
00021 #define _psqlstatement_h_
00022 
00023 #include <pclasses/pexport.h>
00024 #include <pclasses/psqldriver.h>
00025 #include <pclasses/psqlconnection.h>
00026 #include <pclasses/psqlvalue.h>
00027 #include <memory>
00028 #include <map>
00029 #include <string>
00030 #include <sstream>
00031 
00032 namespace P {
00033 
00034 class SQLStatement;
00035 
00037 
00040 class PSQL_EXPORT SQLResult {
00041   friend class SQLStatement;
00042 
00043   public:
00044     SQLResult(SQLStatement& stmt);
00045     virtual ~SQLResult();
00046     
00048     unsigned int columnCount() const throw();
00049 
00051     std::string columnName(unsigned int pos) const;
00052         
00054     bool fetch();
00055     
00057     const SQLValue& operator[](const std::string& fieldName);
00058     
00060     const SQLValue& operator[](unsigned int fieldPos);
00061     
00062   protected:
00063     SQLResult(std::auto_ptr<SQLDriver::ResultHandle> handle);
00064     
00065   private:
00066     std::auto_ptr<SQLDriver::
00067       ResultHandle> m_handle;
00068 };
00069 
00071 
00074 class PSQL_EXPORT SQLStatement {
00075   friend class SQLResult;
00076 
00077   public:
00078     enum state_t {
00079       Initial,
00080       Prepared,
00081       Executed
00082     };
00083 
00084     SQLStatement(SQLConnection& conn, const std::string& stmt = "");
00085     virtual ~SQLStatement();
00086 
00088     void prepare() throw(SQLError);
00089 
00091     void exec() throw(SQLError);
00092 
00094     std::auto_ptr<SQLResult> result() throw(SQLError);
00095 
00097     sqlcount_t affectedRows() const throw();
00098 
00099     void format(const std::string& fmt, const std::map<std::string,const SQLValue*>& vals);
00100 
00101     inline state_t state() const throw()
00102     { return m_state; }
00103 
00104     inline SQLConnection& conn() const throw()
00105     { return m_conn; }
00106 
00107     SQLStatement& operator<<(char ch);
00108     SQLStatement& operator<<(const char* str);
00109     SQLStatement& operator<<(const std::string& str);
00110     SQLStatement& operator<<(const SQLValue& val);
00111 
00112   protected:
00113     const std::auto_ptr<SQLDriver::
00114       StatementHandle>& handle() const throw()
00115     { return m_handle; }
00116 
00117   private:
00118     state_t             m_state;
00119     SQLConnection&      m_conn;
00120     std::auto_ptr<SQLDriver::
00121       StatementHandle>  m_handle;
00122     std::ostringstream  m_stmt;
00123 };
00124 
00125 }
00126 
00127 #endif

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