/*
This file is part of libodbc++.
Copyright (C) 1999-2000 Manush Dodunekov <manush@stendahls.net>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#ifndef __ODBCXX_RESULTSET_H
#define __ODBCXX_RESULTSET_H
#include <odbc++/setup.h>
#include <odbc++/types.h>
#include <odbc++/errorhandler.h>
#include <odbc++/statement.h>
namespace odbc {
class ResultSetMetaData;
class Statement;
class Rowset;
class ODBCXX_EXPORT ResultSet : public ErrorHandler {
friend class Statement;
friend class ResultSetMetaData;
private:
Statement* statement_;
SQLHSTMT hstmt_;
bool ownStatement_;
int currentFetchSize_;
int newFetchSize_;
Rowset* rowset_;
SQLUSMALLINT* rowStatus_;
SQLUINTEGER rowsInRowset_;
//tells us if the columns are bound right now
bool colsBound_;
bool streamedColsBound_;
//the position in the rowset last time we did a bind
unsigned int bindPos_;
//meta data - it's always there since we need info from it
ResultSetMetaData* metaData_;
int location_;
bool lastWasNull_;
int rowBeforeInsert_;
int locBeforeInsert_;
ResultSet(Statement* stmt,SQLHSTMT hstmt, bool ownStmt);
//driver info
const DriverInfo* _getDriverInfo() const {
return statement_->_getDriverInfo();
}
//private utils
void _applyFetchSize();
//this makes sure there is a rowset
void _resetRowset();
//this should be called before any call to SQLExtendedFetch
void _prepareForFetch();
//this performs a possibly scrolled fetch with fetchType to rownum
void _doFetch(int fetchType, int rowNum);
//this should be called after the position in the rowset changes
SQLRETURN _applyPosition(int mode =SQL_POSITION);
//these bind/unbind all non-streamed columns
void _bindCols();
void _unbindCols();
//these bind/unbind all streamed columns
void _bindStreamedCols();
void _unbindStreamedCols();
//this sends all needed data from streamed columns
//to be called from insertRow and updateRow
void _handleStreams(SQLRETURN r);
public:
virtual ~ResultSet();
//remember to update DatabaseMetaData when changing those values
enum {
CONCUR_READ_ONLY,
CONCUR_UPDATABLE
};
enum {
TYPE_FORWARD_ONLY,
TYPE_SCROLL_INSENSITIVE,
TYPE_SCROLL_SENSITIVE
};
bool absolute(int row);
bool relative(int rows);
void afterLast();
void beforeFirst();
bool isAfterLast();
bool isBeforeFirst();
bool isFirst();
bool isLast();
int getRow();
bool next();
bool previous();
bool first();
bool last();
void moveToInsertRow();
void moveToCurrentRow();
void refreshRow();
void deleteRow();
void insertRow();
void updateRow();
void cancelRowUpdates();
ResultSetMetaData* getMetaData() {
return metaData_;
}
int findColumn(const ODBCXX_STRING& colName);
bool rowDeleted();
bool rowInserted();
bool rowUpdated();
int getType();
int getConcurrency();
int getFetchSize() {
return newFetchSize_;
}
void setFetchSize(int fetchSize);
ODBCXX_STRING getCursorName();
Statement* getStatement() {
return statement_;
}
double getDouble(int idx);
bool getBoolean(int idx);
signed char getByte(int idx);
ODBCXX_BYTES getBytes(int idx);
Date getDate(int idx);
float getFloat(int idx);
int getInt(int idx);
Long getLong(int idx);
short getShort(int idx);
ODBCXX_STRING getString(int idx);
Time getTime(int idx);
Timestamp getTimestamp(int idx);
double getDouble(const ODBCXX_STRING& colName);
bool getBoolean(const ODBCXX_STRING& colName);
signed char getByte(const ODBCXX_STRING& colName);
ODBCXX_BYTES getBytes(const ODBCXX_STRING& colName);
Date getDate(const ODBCXX_STRING& colName);
float getFloat(const ODBCXX_STRING& colName);
int getInt(const ODBCXX_STRING& colName);
Long getLong(const ODBCXX_STRING& colName);
short getShort(const ODBCXX_STRING& colName);
ODBCXX_STRING getString(const ODBCXX_STRING& colName);
Time getTime(const ODBCXX_STRING& colName);
Timestamp getTimestamp(const ODBCXX_STRING& colName);
ODBCXX_STREAM* getAsciiStream(int idx);
ODBCXX_STREAM* getAsciiStream(const ODBCXX_STRING& colName);
ODBCXX_STREAM* getBinaryStream(int idx);
ODBCXX_STREAM* getBinaryStream(const ODBCXX_STRING& colName);
bool wasNull() {
return lastWasNull_;
}
void updateDouble(int idx, double val);
void updateBoolean(int idx, bool val);
void updateByte(int idx, signed char val);
void updateBytes(int idx, const ODBCXX_BYTES& val);
void updateDate(int idx, const Date& val);
void updateFloat(int idx, float val);
void updateInt(int idx, int val);
void updateLong(int idx, Long val);
void updateShort(int idx, short val);
void updateString(int idx, const ODBCXX_STRING& val);
void updateTime(int idx, const Time& val);
void updateTimestamp(int idx, const Timestamp& val);
void updateNull(int idx);
void updateDouble(const ODBCXX_STRING& colName, double val);
void updateBoolean(const ODBCXX_STRING& colName, bool val);
void updateByte(const ODBCXX_STRING& colName, signed char val);
void updateBytes(const ODBCXX_STRING& colName,
const ODBCXX_BYTES& val);
void updateDate(const ODBCXX_STRING& colName, const Date& val);
void updateFloat(const ODBCXX_STRING& colName, float val);
void updateInt(const ODBCXX_STRING& colName, int val);
void updateLong(const ODBCXX_STRING& colName, Long val);
void updateShort(const ODBCXX_STRING& colName, short val);
void updateString(const ODBCXX_STRING& colName, const ODBCXX_STRING& val);
void updateTime(const ODBCXX_STRING& colName, const Time& val);
void updateTimestamp(const ODBCXX_STRING& colName, const Timestamp& val);
void updateAsciiStream(int idx, ODBCXX_STREAM* s, int len);
void updateAsciiStream(const ODBCXX_STRING& colName, ODBCXX_STREAM* s, int len);
void updateBinaryStream(int idx, ODBCXX_STREAM* s, int len);
void updateBinaryStream(const ODBCXX_STRING& colName, ODBCXX_STREAM* s, int len);
void updateNull(const ODBCXX_STRING& colName);
};
}; // namespace odbc
#endif // __ODBCXX_RESULTSET_H