libodbc++  0.2.5
statement.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_STATEMENT_H
23 #define __ODBCXX_STATEMENT_H
24 
25 #include <odbc++/setup.h>
26 #include <odbc++/types.h>
27 #include <odbc++/errorhandler.h>
28 #include <odbc++/connection.h>
29 
30 namespace odbc {
31 
32  class ResultSet;
33  class DriverInfo;
34 
36  class ODBCXX_EXPORT Statement : public ErrorHandler {
37  friend class Connection;
38  friend class ResultSet;
39  friend class DatabaseMetaData;
40 
41  protected:
42  Connection* connection_;
43  SQLHSTMT hstmt_;
44  int lastExecute_;
45 
46  const DriverInfo* _getDriverInfo() const {
47  return connection_->_getDriverInfo();
48  }
49 
50  private:
51  ResultSet* currentResultSet_;
52 
53  int fetchSize_;
54  int resultSetType_;
55  int resultSetConcurrency_;
56 
57  //used internally
58  enum StatementState {
59  STATE_CLOSED,
60  STATE_OPEN
61  };
62 
63  StatementState state_;
64 
65  std::vector<ODBCXX_STRING> batches_;
66 
67  void _registerResultSet(ResultSet* rs);
68  void _unregisterResultSet(ResultSet* rs);
69 
70  void _applyResultSetType();
71 
72  ResultSet* _getTypeInfo();
73  ResultSet* _getTables(const ODBCXX_STRING& catalog,
74  const ODBCXX_STRING& schema,
75  const ODBCXX_STRING& tableName,
76  const ODBCXX_STRING& types);
77 
78  ResultSet* _getTablePrivileges(const ODBCXX_STRING& catalog,
79  const ODBCXX_STRING& schema,
80  const ODBCXX_STRING& tableName);
81 
82  ResultSet* _getColumnPrivileges(const ODBCXX_STRING& catalog,
83  const ODBCXX_STRING& schema,
84  const ODBCXX_STRING& tableName,
85  const ODBCXX_STRING& columnName);
86 
87  ResultSet* _getPrimaryKeys(const ODBCXX_STRING& catalog,
88  const ODBCXX_STRING& schema,
89  const ODBCXX_STRING& tableName);
90 
91  ResultSet* _getColumns(const ODBCXX_STRING& catalog,
92  const ODBCXX_STRING& schema,
93  const ODBCXX_STRING& tableName,
94  const ODBCXX_STRING& columnName);
95 
96  ResultSet* _getIndexInfo(const ODBCXX_STRING& catalog,
97  const ODBCXX_STRING& schema,
98  const ODBCXX_STRING& tableName,
99  bool unique, bool approximate);
100 
101  ResultSet* _getCrossReference(const ODBCXX_STRING& pc,
102  const ODBCXX_STRING& ps,
103  const ODBCXX_STRING& pt,
104  const ODBCXX_STRING& fc,
105  const ODBCXX_STRING& fs,
106  const ODBCXX_STRING& ft);
107 
108 
109  ResultSet* _getProcedures(const ODBCXX_STRING& catalog,
110  const ODBCXX_STRING& schema,
111  const ODBCXX_STRING& procName);
112 
113  ResultSet* _getProcedureColumns(const ODBCXX_STRING& catalog,
114  const ODBCXX_STRING& schema,
115  const ODBCXX_STRING& procName,
116  const ODBCXX_STRING& colName);
117 
118  ResultSet* _getSpecialColumns(const ODBCXX_STRING& catalog,
119  const ODBCXX_STRING& schema,
120  const ODBCXX_STRING& table,
121  int what,int scope,int nullable);
122 
123  protected:
124  Statement(Connection* con, SQLHSTMT hstmt,
125  int resultSetType, int resultSetConcurrency);
126 
127  //utilities
128  SQLUINTEGER _getUIntegerOption(SQLINTEGER optnum);
129  ODBCXX_STRING _getStringOption(SQLINTEGER optnum);
130 
131  void _setUIntegerOption(SQLINTEGER optnum, SQLUINTEGER value);
132  void _setStringOption(SQLINTEGER optnum, const ODBCXX_STRING& value);
133 
134 #if ODBCVER >= 0x0300
135  SQLPOINTER _getPointerOption(SQLINTEGER optnum);
136  void _setPointerOption(SQLINTEGER optnum, SQLPOINTER value);
137 #endif
138 
139  //this returns true if we have a result set pending
140  bool _checkForResults();
141 
142  //this _always_ returns a ResultSet. If hideMe is true, this statement
143  //becomes 'owned' by the ResultSet
144  ResultSet* _getResultSet(bool hideMe =false);
145 
146  //this is called before a Statement (or any of the derived classes)
147  //is executed
148  void _beforeExecute();
149 
150  //this is called after a successeful execution
151  void _afterExecute();
152 
153 
154  public:
158  virtual ~Statement();
159 
161  Connection* getConnection();
162 
163 
165  void cancel();
166 
174  virtual bool execute(const ODBCXX_STRING& sql);
175 
184  virtual ResultSet* executeQuery(const ODBCXX_STRING& sql);
185 
189  virtual int executeUpdate(const ODBCXX_STRING& sql);
190 
196  int getUpdateCount();
197 
199  ResultSet* getResultSet();
200 
205  bool getMoreResults();
206 
208  void setCursorName(const ODBCXX_STRING& name);
209 
213  int getFetchSize() {
214  return fetchSize_;
215  }
216 
218  void setFetchSize(int size);
219 
222  return resultSetConcurrency_;
223  }
224 
227  return resultSetType_;
228  }
229 
231  int getQueryTimeout();
233  void setQueryTimeout(int seconds);
234 
236  int getMaxRows();
238  void setMaxRows(int maxRows);
239 
241  int getMaxFieldSize();
243  void setMaxFieldSize(int maxFieldSize);
244 
250  void setEscapeProcessing(bool on);
251 
256  bool getEscapeProcessing();
257 
261  void close();
262 
263  };
264 
265 
266 
267 } // namespace odbc
268 
269 
270 #endif // __ODBCXX_STATEMENT_H
int getResultSetConcurrency()
Get the concurrency type for resultsets created by this statement.
Definition: statement.h:221
int getResultSetType()
Get the type for resultsets created by this statement.
Definition: statement.h:226
int getFetchSize()
Fetch the current fetch size (also called rowset size) for resultsets created by this statement...
Definition: statement.h:213
A simple non-prepared statement.
Definition: statement.h:36
Base class for everything that might contain warnings.
Definition: errorhandler.h:32
A database connection.
Definition: connection.h:38
A result set.
Definition: resultset.h:38
Provides several tons of information about a data source.
Definition: databasemetadata.h:43

Go back to the libodbc++ homepage