Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members  

odbc++/statement.h

00001 /* 
00002    This file is part of libodbc++.
00003    
00004    Copyright (C) 1999-2000 Manush Dodunekov <manush@stendahls.net>
00005    
00006    This library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Library General Public
00008    License as published by the Free Software Foundation; either
00009    version 2 of the License, or (at your option) any later version.
00010    
00011    This library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Library General Public License for more details.
00015    
00016    You should have received a copy of the GNU Library General Public License
00017    along with this library; see the file COPYING.  If not, write to
00018    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00019    Boston, MA 02111-1307, USA.
00020 */
00021 
00022 #ifndef __ODBCXX_STATEMENT_H
00023 #define __ODBCXX_STATEMENT_H
00024 
00025 #include <odbc++/setup.h>
00026 #include <odbc++/types.h>
00027 #include <odbc++/errorhandler.h>
00028 #include <odbc++/connection.h>
00029 
00030 namespace odbc {
00031 
00032   class ResultSet;
00033   class DriverInfo;
00034 
00036   class ODBCXX_EXPORT Statement : public ErrorHandler {
00037     friend class Connection;
00038     friend class ResultSet;
00039     friend class DatabaseMetaData;
00040 
00041   protected:
00042     Connection* connection_;
00043     SQLHSTMT hstmt_;
00044     int lastExecute_;
00045 
00046     const DriverInfo* _getDriverInfo() const {
00047       return connection_->_getDriverInfo();
00048     }
00049 
00050   private:
00051     ResultSet* currentResultSet_;
00052 
00053     int fetchSize_;
00054     int resultSetType_;
00055     int resultSetConcurrency_;
00056     
00057     //used internally
00058     enum StatementState {
00059       STATE_CLOSED,
00060       STATE_OPEN
00061     };
00062 
00063     StatementState state_;
00064 
00065     std::vector<ODBCXX_STRING> batches_;
00066 
00067     void _registerResultSet(ResultSet* rs);
00068     void _unregisterResultSet(ResultSet* rs);
00069 
00070     void _applyResultSetType();
00071 
00072     ResultSet* _getTypeInfo();
00073     ResultSet* _getTables(const ODBCXX_STRING& catalog,
00074                           const ODBCXX_STRING& schema,
00075                           const ODBCXX_STRING& tableName,
00076                           const ODBCXX_STRING& types);
00077 
00078     ResultSet* _getTablePrivileges(const ODBCXX_STRING& catalog,
00079                                    const ODBCXX_STRING& schema,
00080                                    const ODBCXX_STRING& tableName);
00081 
00082     ResultSet* _getColumnPrivileges(const ODBCXX_STRING& catalog,
00083                                     const ODBCXX_STRING& schema,
00084                                     const ODBCXX_STRING& tableName,
00085                                     const ODBCXX_STRING& columnName);
00086 
00087     ResultSet* _getPrimaryKeys(const ODBCXX_STRING& catalog,
00088                                const ODBCXX_STRING& schema,
00089                                const ODBCXX_STRING& tableName);
00090 
00091     ResultSet* _getColumns(const ODBCXX_STRING& catalog,
00092                            const ODBCXX_STRING& schema,
00093                            const ODBCXX_STRING& tableName,
00094                            const ODBCXX_STRING& columnName);
00095 
00096     ResultSet* _getIndexInfo(const ODBCXX_STRING& catalog,
00097                              const ODBCXX_STRING& schema,
00098                              const ODBCXX_STRING& tableName,
00099                              bool unique, bool approximate);
00100     
00101     ResultSet* _getCrossReference(const ODBCXX_STRING& pc,
00102                                   const ODBCXX_STRING& ps,
00103                                   const ODBCXX_STRING& pt,
00104                                   const ODBCXX_STRING& fc,
00105                                   const ODBCXX_STRING& fs,
00106                                   const ODBCXX_STRING& ft);
00107 
00108     
00109     ResultSet* _getProcedures(const ODBCXX_STRING& catalog,
00110                               const ODBCXX_STRING& schema,
00111                               const ODBCXX_STRING& procName);
00112     
00113     ResultSet* _getProcedureColumns(const ODBCXX_STRING& catalog,
00114                                     const ODBCXX_STRING& schema,
00115                                     const ODBCXX_STRING& procName,
00116                                     const ODBCXX_STRING& colName);
00117 
00118     ResultSet* _getSpecialColumns(const ODBCXX_STRING& catalog,
00119                                   const ODBCXX_STRING& schema,
00120                                   const ODBCXX_STRING& table,
00121                                   int what,int scope,int nullable);
00122       
00123   protected:
00124     Statement(Connection* con, SQLHSTMT hstmt, 
00125               int resultSetType, int resultSetConcurrency);
00126     
00127     //utilities
00128     SQLUINTEGER _getNumericOption(SQLINTEGER optnum);
00129     ODBCXX_STRING _getStringOption(SQLINTEGER optnum);
00130     
00131     void _setNumericOption(SQLINTEGER optnum, SQLUINTEGER value);
00132     void _setStringOption(SQLINTEGER optnum, const ODBCXX_STRING& value);
00133 
00134 #if ODBCVER >= 0x0300
00135     SQLPOINTER _getPointerOption(SQLINTEGER optnum);
00136     void _setPointerOption(SQLINTEGER optnum, SQLPOINTER value);
00137 #endif
00138 
00139     //this returns true if we have a result set pending
00140     bool _checkForResults();
00141 
00142     //this _always_ returns a ResultSet. If hideMe is true, this statement
00143     //becomes 'owned' by the ResultSet
00144     ResultSet* _getResultSet(bool hideMe =false);
00145 
00146     //this is called before a Statement (or any of the derived classes)
00147     //is executed
00148     void _beforeExecute();
00149 
00150     //this is called after a successeful execution
00151     void _afterExecute();
00152     
00153 
00154   public:
00158     virtual ~Statement();
00159 
00161     Connection* getConnection();
00162     
00163 
00165     void cancel();
00166 
00174     virtual bool execute(const ODBCXX_STRING& sql);
00175     
00180     virtual ResultSet* executeQuery(const ODBCXX_STRING& sql);
00181 
00185     virtual int executeUpdate(const ODBCXX_STRING& sql);
00186     
00192     int getUpdateCount();
00193     
00195     ResultSet* getResultSet();
00196 
00201     bool getMoreResults();
00202 
00204     void setCursorName(const ODBCXX_STRING& name);
00205     
00209     int getFetchSize() {
00210       return fetchSize_;
00211     }
00212 
00214     void setFetchSize(int size);
00215 
00217     int getResultSetConcurrency() {
00218       return resultSetConcurrency_;
00219     }
00220 
00222     int getResultSetType() {
00223       return resultSetType_;
00224     }
00225     
00227     int getQueryTimeout();
00229     void setQueryTimeout(int seconds);
00230 
00232     int getMaxRows();
00234     void setMaxRows(int maxRows);
00235 
00237     int getMaxFieldSize();
00239     void setMaxFieldSize(int maxFieldSize);
00240 
00246     void setEscapeProcessing(bool on);
00247 
00252     bool getEscapeProcessing();
00253   };
00254   
00255 
00256 
00257 }; // namespace odbc
00258 
00259 
00260 #endif // __ODBCXX_STATEMENT_H

Go back to the freeodbc++ homepage