/* 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_STATEMENT_H #define __ODBCXX_STATEMENT_H #include <odbc++/setup.h> #include <odbc++/types.h> #include <odbc++/errorhandler.h> #include <odbc++/connection.h> namespace odbc { class ResultSet; class DriverInfo; class ODBCXX_EXPORT Statement : public ErrorHandler { friend class Connection; friend class ResultSet; friend class DatabaseMetaData; protected: Connection* connection_; SQLHSTMT hstmt_; const DriverInfo* _getDriverInfo() const { return connection_->_getDriverInfo(); } private: ResultSet* currentResultSet_; int fetchSize_; int resultSetType_; int resultSetConcurrency_; //used internally enum StatementState { STATE_CLOSED, STATE_OPEN }; StatementState state_; std::vector<ODBCXX_STRING> batches_; void _registerResultSet(ResultSet* rs); void _unregisterResultSet(ResultSet* rs); void _applyResultSetType(); ResultSet* _getTypeInfo(); ResultSet* _getTables(const ODBCXX_STRING& catalog, const ODBCXX_STRING& schema, const ODBCXX_STRING& tableName, const ODBCXX_STRING& types); ResultSet* _getTablePrivileges(const ODBCXX_STRING& catalog, const ODBCXX_STRING& schema, const ODBCXX_STRING& tableName); ResultSet* _getColumnPrivileges(const ODBCXX_STRING& catalog, const ODBCXX_STRING& schema, const ODBCXX_STRING& tableName, const ODBCXX_STRING& columnName); ResultSet* _getPrimaryKeys(const ODBCXX_STRING& catalog, const ODBCXX_STRING& schema, const ODBCXX_STRING& tableName); ResultSet* _getColumns(const ODBCXX_STRING& catalog, const ODBCXX_STRING& schema, const ODBCXX_STRING& tableName, const ODBCXX_STRING& columnName); ResultSet* _getIndexInfo(const ODBCXX_STRING& catalog, const ODBCXX_STRING& schema, const ODBCXX_STRING& tableName, bool unique, bool approximate); ResultSet* _getCrossReference(const ODBCXX_STRING& pc, const ODBCXX_STRING& ps, const ODBCXX_STRING& pt, const ODBCXX_STRING& fc, const ODBCXX_STRING& fs, const ODBCXX_STRING& ft); ResultSet* _getProcedures(const ODBCXX_STRING& catalog, const ODBCXX_STRING& schema, const ODBCXX_STRING& procName); ResultSet* _getProcedureColumns(const ODBCXX_STRING& catalog, const ODBCXX_STRING& schema, const ODBCXX_STRING& procName, const ODBCXX_STRING& colName); ResultSet* _getSpecialColumns(const ODBCXX_STRING& catalog, const ODBCXX_STRING& schema, const ODBCXX_STRING& table, int what,int scope,int nullable); protected: Statement(Connection* con, SQLHSTMT hstmt, int resultSetType, int resultSetConcurrency); //utilities SQLUINTEGER _getNumericOption(SQLINTEGER optnum); ODBCXX_STRING _getStringOption(SQLINTEGER optnum); void _setNumericOption(SQLINTEGER optnum, SQLUINTEGER value); void _setStringOption(SQLINTEGER optnum, const ODBCXX_STRING& value); #if ODBCVER >= 0x0300 SQLPOINTER _getPointerOption(SQLINTEGER optnum); void _setPointerOption(SQLINTEGER optnum, SQLPOINTER value); #endif //this returns true if we have a result set pending bool _checkForResults(); //this _always_ returns a ResultSet. If hideMe is true, this statement //becomes 'owned' by the ResultSet ResultSet* _getResultSet(bool hideMe =false); //this is called before a Statement (or any of the derived classes) //is executed void _beforeExecute(); //this is called after a successeful execution void _afterExecute(); public: virtual ~Statement(); Connection* getConnection(); void cancel(); virtual bool execute(const ODBCXX_STRING& sql); virtual ResultSet* executeQuery(const ODBCXX_STRING& sql); virtual int executeUpdate(const ODBCXX_STRING& sql); int getUpdateCount(); ResultSet* getResultSet(); bool getMoreResults(); void setCursorName(const ODBCXX_STRING& name); int getFetchSize() { return fetchSize_; } void setFetchSize(int size); int getResultSetConcurrency() { return resultSetConcurrency_; } int getResultSetType() { return resultSetType_; } int getQueryTimeout(); void setQueryTimeout(int seconds); int getMaxRows(); void setMaxRows(int maxRows); int getMaxFieldSize(); void setMaxFieldSize(int maxFieldSize); void setEscapeProcessing(bool on); bool getEscapeProcessing(); }; }; // namespace odbc #endif // __ODBCXX_STATEMENT_H