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 
00045     const DriverInfo* _getDriverInfo() const {
00046       return connection_->_getDriverInfo();
00047     }
00048 
00049   private:
00050     ResultSet* currentResultSet_;
00051 
00052     int fetchSize_;
00053     int resultSetType_;
00054     int resultSetConcurrency_;
00055     
00056     //used internally
00057     enum StatementState {
00058       STATE_CLOSED,
00059       STATE_OPEN
00060     };
00061 
00062     StatementState state_;
00063 
00064     std::vector<ODBCXX_STRING> batches_;
00065 
00066     void _registerResultSet(ResultSet* rs);
00067     void _unregisterResultSet(ResultSet* rs);
00068 
00069     void _applyResultSetType();
00070 
00071     ResultSet* _getTypeInfo();
00072     ResultSet* _getTables(const ODBCXX_STRING& catalog,
00073                           const ODBCXX_STRING& schema,
00074                           const ODBCXX_STRING& tableName,
00075                           const ODBCXX_STRING& types);
00076 
00077     ResultSet* _getTablePrivileges(const ODBCXX_STRING& catalog,
00078                                    const ODBCXX_STRING& schema,
00079                                    const ODBCXX_STRING& tableName);
00080 
00081     ResultSet* _getColumnPrivileges(const ODBCXX_STRING& catalog,
00082                                     const ODBCXX_STRING& schema,
00083                                     const ODBCXX_STRING& tableName,
00084                                     const ODBCXX_STRING& columnName);
00085 
00086     ResultSet* _getPrimaryKeys(const ODBCXX_STRING& catalog,
00087                                const ODBCXX_STRING& schema,
00088                                const ODBCXX_STRING& tableName);
00089 
00090     ResultSet* _getColumns(const ODBCXX_STRING& catalog,
00091                            const ODBCXX_STRING& schema,
00092                            const ODBCXX_STRING& tableName,
00093                            const ODBCXX_STRING& columnName);
00094 
00095     ResultSet* _getIndexInfo(const ODBCXX_STRING& catalog,
00096                              const ODBCXX_STRING& schema,
00097                              const ODBCXX_STRING& tableName,
00098                              bool unique, bool approximate);
00099     
00100     ResultSet* _getCrossReference(const ODBCXX_STRING& pc,
00101                                   const ODBCXX_STRING& ps,
00102                                   const ODBCXX_STRING& pt,
00103                                   const ODBCXX_STRING& fc,
00104                                   const ODBCXX_STRING& fs,
00105                                   const ODBCXX_STRING& ft);
00106 
00107     
00108     ResultSet* _getProcedures(const ODBCXX_STRING& catalog,
00109                               const ODBCXX_STRING& schema,
00110                               const ODBCXX_STRING& procName);
00111     
00112     ResultSet* _getProcedureColumns(const ODBCXX_STRING& catalog,
00113                                     const ODBCXX_STRING& schema,
00114                                     const ODBCXX_STRING& procName,
00115                                     const ODBCXX_STRING& colName);
00116 
00117     ResultSet* _getSpecialColumns(const ODBCXX_STRING& catalog,
00118                                   const ODBCXX_STRING& schema,
00119                                   const ODBCXX_STRING& table,
00120                                   int what,int scope,int nullable);
00121       
00122   protected:
00123     Statement(Connection* con, SQLHSTMT hstmt, 
00124               int resultSetType, int resultSetConcurrency);
00125     
00126     //utilities
00127     SQLUINTEGER _getNumericOption(SQLINTEGER optnum);
00128     ODBCXX_STRING _getStringOption(SQLINTEGER optnum);
00129     
00130     void _setNumericOption(SQLINTEGER optnum, SQLUINTEGER value);
00131     void _setStringOption(SQLINTEGER optnum, const ODBCXX_STRING& value);
00132 
00133 #if ODBCVER >= 0x0300
00134     SQLPOINTER _getPointerOption(SQLINTEGER optnum);
00135     void _setPointerOption(SQLINTEGER optnum, SQLPOINTER value);
00136 #endif
00137 
00138     //this returns true if we have a result set pending
00139     bool _checkForResults();
00140 
00141     //this _always_ returns a ResultSet. If hideMe is true, this statement
00142     //becomes 'owned' by the ResultSet
00143     ResultSet* _getResultSet(bool hideMe =false);
00144 
00145     //this is called before a Statement (or any of the derived classes)
00146     //is executed
00147     void _beforeExecute();
00148 
00149     //this is called after a successeful execution
00150     void _afterExecute();
00151     
00152 
00153   public:
00157     virtual ~Statement();
00158 
00160     Connection* getConnection();
00161     
00162 
00164     void cancel();
00165 
00173     virtual bool execute(const ODBCXX_STRING& sql);
00174     
00179     virtual ResultSet* executeQuery(const ODBCXX_STRING& sql);
00180 
00184     virtual int executeUpdate(const ODBCXX_STRING& sql);
00185     
00191     int getUpdateCount();
00192     
00194     ResultSet* getResultSet();
00195 
00200     bool getMoreResults();
00201 
00203     void setCursorName(const ODBCXX_STRING& name);
00204     
00208     int getFetchSize() {
00209       return fetchSize_;
00210     }
00211 
00213     void setFetchSize(int size);
00214 
00216     int getResultSetConcurrency() {
00217       return resultSetConcurrency_;
00218     }
00219 
00221     int getResultSetType() {
00222       return resultSetType_;
00223     }
00224     
00226     int getQueryTimeout();
00228     void setQueryTimeout(int seconds);
00229 
00231     int getMaxRows();
00233     void setMaxRows(int maxRows);
00234 
00236     int getMaxFieldSize();
00238     void setMaxFieldSize(int maxFieldSize);
00239 
00245     void setEscapeProcessing(bool on);
00246 
00251     bool getEscapeProcessing();
00252   };
00253   
00254 
00255 
00256 }; // namespace odbc
00257 
00258 
00259 #endif // __ODBCXX_STATEMENT_H

Go back to the freeodbc++ homepage