libodbc++  0.2.5
resultset.h
1 /*
2  This file is part of libodbc++.
3 
4  Copyright (C) 1999-2000 Manush Dodunekov <manush@stendahls.net>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License as published by the Free Software Foundation; either
9  version 2 of the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Library General Public License for more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  along with this library; see the file COPYING. If not, write to
18  the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  Boston, MA 02111-1307, USA.
20 */
21 
22 #ifndef __ODBCXX_RESULTSET_H
23 #define __ODBCXX_RESULTSET_H
24 
25 #include <odbc++/setup.h>
26 #include <odbc++/types.h>
27 #include <odbc++/errorhandler.h>
28 #include <odbc++/statement.h>
29 
30 
31 namespace odbc {
32 
33  class ResultSetMetaData;
34  class Statement;
35  class Rowset;
36 
38  class ODBCXX_EXPORT ResultSet : public ErrorHandler {
39  friend class Statement;
40  friend class ResultSetMetaData;
41 
42  private:
43  Statement* statement_;
44  SQLHSTMT hstmt_;
45  bool ownStatement_;
46 
47 
48  int currentFetchSize_;
49  int newFetchSize_;
50 
51  Rowset* rowset_;
52  SQLUSMALLINT* rowStatus_;
53  SQLUINTEGER rowsInRowset_;
54 
55  //tells us if the columns are bound right now
56  bool colsBound_;
57  bool streamedColsBound_;
58 
59  //the position in the rowset last time we did a bind
60  unsigned int bindPos_;
61 
62  //meta data - it's always there since we need info from it
63  ResultSetMetaData* metaData_;
64 
65  int location_;
66 
67  bool lastWasNull_;
68 
69  int rowBeforeInsert_;
70  int locBeforeInsert_;
71 
72  // Flag to determine if we can lazyfetch data
73  bool supportsGetDataAnyOrder_;
74 
75  ResultSet(Statement* stmt,SQLHSTMT hstmt, bool ownStmt);
76 
77  //driver info
78  const DriverInfo* _getDriverInfo() const {
79  return statement_->_getDriverInfo();
80  }
81 
82  //private utils
83  void _applyFetchSize();
84  //this makes sure there is a rowset
85  void _resetRowset();
86 
87  //this should be called before any call to SQLExtendedFetch
88  void _prepareForFetch();
89  //this performs a possibly scrolled fetch with fetchType to rownum
90  void _doFetch(int fetchType, int rowNum);
91 
92  //this should be called after the position in the rowset changes
93  SQLRETURN _applyPosition(int mode =SQL_POSITION);
94 
95  //these bind/unbind all non-streamed columns
96  void _bindCols();
97  void _unbindCols();
98 
99  //these bind/unbind all streamed columns
100  void _bindStreamedCols();
101  void _unbindStreamedCols();
102 
103  //this sends all needed data from streamed columns
104  //to be called from insertRow and updateRow
105  void _handleStreams(SQLRETURN r);
106 
107 
108  public:
110  virtual ~ResultSet();
111 
112  //remember to update DatabaseMetaData when changing those values
113 
116  enum {
120  CONCUR_UPDATABLE
121  };
122 
123 
126  enum {
134  TYPE_SCROLL_SENSITIVE
135  };
136 
143  bool absolute(int row);
144 
150  bool relative(int rows);
151 
153  void afterLast();
154 
156  void beforeFirst();
157 
159  bool isAfterLast();
160 
162  bool isBeforeFirst();
163 
165  bool isFirst();
166 
169  bool isLast();
170 
175  int getRow();
176 
180  bool next();
181 
185  bool previous();
186 
190  bool first();
191 
195  bool last();
196 
202  void moveToInsertRow();
203 
207  void moveToCurrentRow();
208 
210  void refreshRow();
211 
213  void deleteRow();
214 
219  void insertRow();
220 
222  void updateRow();
223 
225  void cancelRowUpdates();
226 
231  return metaData_;
232  }
233 
235  int findColumn(const ODBCXX_STRING& colName);
236 
238  bool rowDeleted();
239 
241  bool rowInserted();
242 
244  bool rowUpdated();
245 
247  int getType();
248 
250  int getConcurrency();
251 
252 
254  int getFetchSize() {
255  return newFetchSize_;
256  }
257 
259  void setFetchSize(int fetchSize);
260 
262  ODBCXX_STRING getCursorName();
263 
266  return statement_;
267  }
268 
272  double getDouble(int idx);
273 
277  bool getBoolean(int idx);
278 
282  signed char getByte(int idx);
283 
288  ODBCXX_BYTES getBytes(int idx);
289 
293  Date getDate(int idx);
294 
298  float getFloat(int idx);
299 
303  int getInt(int idx);
304 
308  Long getLong(int idx);
309 
313  short getShort(int idx);
314 
318  ODBCXX_STRING getString(int idx);
319 
323  Time getTime(int idx);
324 
328  Timestamp getTimestamp(int idx);
329 
333  double getDouble(const ODBCXX_STRING& colName);
334 
338  bool getBoolean(const ODBCXX_STRING& colName);
339 
343  signed char getByte(const ODBCXX_STRING& colName);
344 
345 
349  ODBCXX_BYTES getBytes(const ODBCXX_STRING& colName);
350 
354  Date getDate(const ODBCXX_STRING& colName);
355 
359  float getFloat(const ODBCXX_STRING& colName);
360 
364  int getInt(const ODBCXX_STRING& colName);
365 
369  Long getLong(const ODBCXX_STRING& colName);
370 
374  short getShort(const ODBCXX_STRING& colName);
375 
379  ODBCXX_STRING getString(const ODBCXX_STRING& colName);
380 
384  Time getTime(const ODBCXX_STRING& colName);
385 
389  Timestamp getTimestamp(const ODBCXX_STRING& colName);
390 
391 
399  ODBCXX_STREAM* getAsciiStream(int idx);
400 
408  ODBCXX_STREAM* getAsciiStream(const ODBCXX_STRING& colName);
409 
417  ODBCXX_STREAM* getBinaryStream(int idx);
418 
426  ODBCXX_STREAM* getBinaryStream(const ODBCXX_STRING& colName);
427 
431  bool wasNull() {
432  return lastWasNull_;
433  }
434 
439  void updateDouble(int idx, double val);
440 
445  void updateBoolean(int idx, bool val);
446 
451  void updateByte(int idx, signed char val);
452 
453 
458  void updateBytes(int idx, const ODBCXX_BYTES& val);
459 
464  void updateDate(int idx, const Date& val);
465 
470  void updateFloat(int idx, float val);
471 
472 #ifdef ODBCXX_HAVE_STRUCT_GUID
473 
477  Guid ResultSet::getGuid(int idx);
478 #endif
479 
483  void updateInt(int idx, int val);
484 
489  void updateLong(int idx, Long val);
490 
495  void updateShort(int idx, short val);
496 
501  void updateString(int idx, const ODBCXX_STRING& val);
502 
507  void updateTime(int idx, const Time& val);
508 
513  void updateTimestamp(int idx, const Timestamp& val);
514 
518  void updateNull(int idx);
519 
524  void updateDouble(const ODBCXX_STRING& colName, double val);
525 
530  void updateBoolean(const ODBCXX_STRING& colName, bool val);
531 
536  void updateByte(const ODBCXX_STRING& colName, signed char val);
537 
542  void updateBytes(const ODBCXX_STRING& colName, const ODBCXX_BYTES& val);
543 
548  void updateDate(const ODBCXX_STRING& colName, const Date& val);
549 
554  void updateFloat(const ODBCXX_STRING& colName, float val);
555 
560  void updateInt(const ODBCXX_STRING& colName, int val);
561 
566  void updateLong(const ODBCXX_STRING& colName, Long val);
567 
572  void updateShort(const ODBCXX_STRING& colName, short val);
573 
578  void updateString(const ODBCXX_STRING& colName, const ODBCXX_STRING& val);
579 
584  void updateTime(const ODBCXX_STRING& colName, const Time& val);
585 
590  void updateTimestamp(const ODBCXX_STRING& colName, const Timestamp& val);
591 
597  void updateAsciiStream(int idx, ODBCXX_STREAM* s, int len);
598 
604  void updateAsciiStream(const ODBCXX_STRING& colName, ODBCXX_STREAM* s, int len);
605 
611  void updateBinaryStream(int idx, ODBCXX_STREAM* s, int len);
612 
618  void updateBinaryStream(const ODBCXX_STRING& colName, ODBCXX_STREAM* s, int len);
619 
623  void updateNull(const ODBCXX_STRING& colName);
624  };
625 
626 } // namespace odbc
627 
628 
629 #endif // __ODBCXX_RESULTSET_H
The result set is scrollable, but the data in it is not affected by changes in the database...
Definition: resultset.h:132
The ResultSet is read only.
Definition: resultset.h:118
The result set only goes forward.
Definition: resultset.h:128
Provides meta data about a result set.
Definition: resultsetmetadata.h:41
Statement * getStatement()
Gets the Statement that created this result set.
Definition: resultset.h:265
An SQL DATE.
Definition: types.h:457
bool wasNull()
Checks if the last fetched column value was NULL.
Definition: resultset.h:431
An SQL TIME.
Definition: types.h:575
An SQL TIMESTAMP.
Definition: types.h:696
A simple non-prepared statement.
Definition: statement.h:36
int getFetchSize()
Gets this result set's current fetch size.
Definition: resultset.h:254
Base class for everything that might contain warnings.
Definition: errorhandler.h:32
A result set.
Definition: resultset.h:38
ResultSetMetaData * getMetaData()
Returns meta data about this result set.
Definition: resultset.h:230

Go back to the libodbc++ homepage