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

odbc++/resultset.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_RESULTSET_H
00023 #define __ODBCXX_RESULTSET_H
00024 
00025 #include <odbc++/setup.h>
00026 #include <odbc++/types.h>
00027 #include <odbc++/errorhandler.h>
00028 #include <odbc++/statement.h>
00029 
00030 
00031 namespace odbc {
00032 
00033   class ResultSetMetaData;
00034   class Statement;
00035   class Rowset;
00036 
00038   class ODBCXX_EXPORT ResultSet : public ErrorHandler {
00039     friend class Statement;
00040     friend class ResultSetMetaData;
00041     
00042   private:
00043     Statement* statement_;
00044     SQLHSTMT hstmt_;
00045     bool ownStatement_;
00046 
00047 
00048     int currentFetchSize_;
00049     int newFetchSize_;
00050 
00051     Rowset* rowset_;
00052     SQLUSMALLINT* rowStatus_;
00053     SQLUINTEGER rowsInRowset_;
00054 
00055     //tells us if the columns are bound right now
00056     bool colsBound_;
00057     bool streamedColsBound_;
00058 
00059     //the position in the rowset last time we did a bind
00060     unsigned int bindPos_;
00061 
00062     //meta data - it's always there since we need info from it
00063     ResultSetMetaData* metaData_;
00064 
00065     int location_;
00066     
00067     bool lastWasNull_;
00068 
00069     int rowBeforeInsert_;
00070     int locBeforeInsert_;
00071 
00072     ResultSet(Statement* stmt,SQLHSTMT hstmt, bool ownStmt);
00073     
00074     //driver info
00075     const DriverInfo* _getDriverInfo() const {
00076       return statement_->_getDriverInfo();
00077     }
00078 
00079     //private utils
00080     void _applyFetchSize();
00081     //this makes sure there is a rowset 
00082     void _resetRowset();
00083 
00084     //this should be called before any call to SQLExtendedFetch
00085     void _prepareForFetch();
00086     //this performs a possibly scrolled fetch with fetchType to rownum
00087     void _doFetch(int fetchType, int rowNum);
00088 
00089     //this should be called after the position in the rowset changes
00090     SQLRETURN _applyPosition(int mode =SQL_POSITION);
00091 
00092     //these bind/unbind all non-streamed columns
00093     void _bindCols();
00094     void _unbindCols();
00095 
00096     //these bind/unbind all streamed columns
00097     void _bindStreamedCols();
00098     void _unbindStreamedCols();
00099     
00100     //this sends all needed data from streamed columns
00101     //to be called from insertRow and updateRow
00102     void _handleStreams(SQLRETURN r);
00103     
00104 
00105   public:
00107     virtual ~ResultSet();
00108     
00109     //remember to update DatabaseMetaData when changing those values
00110 
00113     enum {
00115       CONCUR_READ_ONLY,
00117       CONCUR_UPDATABLE
00118     };
00119 
00120 
00123     enum {
00125       TYPE_FORWARD_ONLY,
00129       TYPE_SCROLL_INSENSITIVE,
00131       TYPE_SCROLL_SENSITIVE
00132     };
00133 
00140     bool absolute(int row);
00141 
00147     bool relative(int rows);
00148 
00150     void afterLast();
00151 
00153     void beforeFirst();
00154 
00156     bool isAfterLast();
00157 
00159     bool isBeforeFirst();
00160 
00162     bool isFirst();
00163 
00166     bool isLast();
00167 
00172     int getRow();
00173 
00177     bool next();
00178 
00182     bool previous();
00183 
00187     bool first();
00188 
00192     bool last();
00193 
00199     void moveToInsertRow();
00200     
00204     void moveToCurrentRow();
00205 
00207     void refreshRow();
00208 
00210     void deleteRow();
00211 
00216     void insertRow();
00217 
00219     void updateRow();
00220 
00222     void cancelRowUpdates();
00223 
00227     ResultSetMetaData* getMetaData() {
00228       return metaData_;
00229     }
00230 
00232     int findColumn(const ODBCXX_STRING& colName);
00233 
00235     bool rowDeleted();
00236 
00238     bool rowInserted();
00239 
00241     bool rowUpdated();
00242 
00244     int getType();
00245 
00247     int getConcurrency();
00248     
00249     
00251     int getFetchSize() {
00252       return newFetchSize_;
00253     }
00254 
00256     void setFetchSize(int fetchSize);
00257 
00259     ODBCXX_STRING getCursorName();
00260 
00262     Statement* getStatement() {
00263       return statement_;
00264     }
00265 
00269     double getDouble(int idx);
00270 
00274     bool getBoolean(int idx);
00275 
00279     signed char getByte(int idx);
00280 
00285     ODBCXX_BYTES getBytes(int idx);
00286 
00290     Date getDate(int idx);
00291 
00295     float getFloat(int idx);
00296 
00300     int getInt(int idx);
00301 
00305     Long getLong(int idx);
00306 
00310     short getShort(int idx);
00311 
00315     ODBCXX_STRING getString(int idx);
00316 
00320     Time getTime(int idx);
00321 
00325     Timestamp getTimestamp(int idx);
00326 
00330     double getDouble(const ODBCXX_STRING& colName);
00331     
00335     bool getBoolean(const ODBCXX_STRING& colName);
00336 
00340     signed char getByte(const ODBCXX_STRING& colName);
00341 
00342 
00346     ODBCXX_BYTES getBytes(const ODBCXX_STRING& colName);
00347 
00351     Date getDate(const ODBCXX_STRING& colName);
00352 
00356     float getFloat(const ODBCXX_STRING& colName);
00357 
00361     int getInt(const ODBCXX_STRING& colName);
00362 
00366     Long getLong(const ODBCXX_STRING& colName);
00367 
00371     short getShort(const ODBCXX_STRING& colName);
00372 
00376     ODBCXX_STRING getString(const ODBCXX_STRING& colName);
00377 
00381     Time getTime(const ODBCXX_STRING& colName);
00382 
00386     Timestamp getTimestamp(const ODBCXX_STRING& colName);
00387 
00388 
00396     ODBCXX_STREAM* getAsciiStream(int idx);
00397 
00405     ODBCXX_STREAM* getAsciiStream(const ODBCXX_STRING& colName);
00406 
00414     ODBCXX_STREAM* getBinaryStream(int idx);
00415 
00423     ODBCXX_STREAM* getBinaryStream(const ODBCXX_STRING& colName);
00424     
00428     bool wasNull() {
00429       return lastWasNull_;
00430     }
00431 
00436     void updateDouble(int idx, double val);
00437 
00442     void updateBoolean(int idx, bool val);
00443 
00448     void updateByte(int idx, signed char val);
00449 
00450 
00455     void updateBytes(int idx, const ODBCXX_BYTES& val);
00456 
00461     void updateDate(int idx, const Date& val);
00462 
00467     void updateFloat(int idx, float val);
00468 
00473     void updateInt(int idx, int val);
00474 
00479     void updateLong(int idx, Long val);
00480 
00485     void updateShort(int idx, short val);
00486 
00491     void updateString(int idx, const ODBCXX_STRING& val);
00492 
00497     void updateTime(int idx, const Time& val);
00498 
00503     void updateTimestamp(int idx, const Timestamp& val);
00504 
00508     void updateNull(int idx);
00509 
00510 
00515     void updateDouble(const ODBCXX_STRING& colName, double val);
00516 
00521     void updateBoolean(const ODBCXX_STRING& colName, bool val);
00522 
00527     void updateByte(const ODBCXX_STRING& colName, signed char val);
00528 
00533     void updateBytes(const ODBCXX_STRING& colName, 
00534                      const ODBCXX_BYTES& val);
00535 
00536 
00541     void updateDate(const ODBCXX_STRING& colName, const Date& val);
00542 
00547     void updateFloat(const ODBCXX_STRING& colName, float val);
00548 
00553     void updateInt(const ODBCXX_STRING& colName, int val);
00554 
00559     void updateLong(const ODBCXX_STRING& colName, Long val);
00560 
00565     void updateShort(const ODBCXX_STRING& colName, short val);
00566 
00571     void updateString(const ODBCXX_STRING& colName, const ODBCXX_STRING& val);
00572 
00577     void updateTime(const ODBCXX_STRING& colName, const Time& val);
00578 
00583     void updateTimestamp(const ODBCXX_STRING& colName, const Timestamp& val);
00584 
00590     void updateAsciiStream(int idx, ODBCXX_STREAM* s, int len);
00591 
00597     void updateAsciiStream(const ODBCXX_STRING& colName, ODBCXX_STREAM* s, int len);
00598 
00599 
00605     void updateBinaryStream(int idx, ODBCXX_STREAM* s, int len);
00606 
00612     void updateBinaryStream(const ODBCXX_STRING& colName, ODBCXX_STREAM* s, int len);
00613 
00617     void updateNull(const ODBCXX_STRING& colName);
00618   };
00619 
00620   
00621 
00622 }; // namespace odbc
00623 
00624 
00625 #endif // __ODBCXX_RESULTSET_H

Go back to the freeodbc++ homepage