]> git.saurik.com Git - wxWidgets.git/blame - include/wx/odbc.h
added missing DeleteItem(long itemId) function
[wxWidgets.git] / include / wx / odbc.h
CommitLineData
c801d85f
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: odbc.h
3// Purpose: ODBC classes
4// Author: Olaf Klein, Patrick Halke, Julian Smart
5// Modified by:
6// Created: 01/02/97
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart and Markus Holzem
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#include "wx/setup.h"
13
14#if USE_ODBC
15
0d3820b3
JS
16#ifdef __GNUG__
17#pragma interface "odbc.h"
18#endif
19
c801d85f
KB
20#ifndef __ODBCH__
21#define __ODBCH__
22
23#ifdef __WINDOWS__
24#include <windows.h>
25#endif
26
27#include <sqlext.h>
28
29#include "wx/defs.h"
30#include "wx/list.h"
31#include "wx/string.h"
32
33typedef RETCODE wxRETCODE;
34
35// Recordset open types
36#define wxOPEN_TYPE_DYNASET 1
37#define wxOPEN_TYPE_SNAPSHOT 2
38#define wxOPEN_TYPE_FORWARD_ONLY 3
39
40// Recordset open options
41#define wxOPTION_DEFAULT 1
42#define wxOPTION_APPEND_ONLY 2
43#define wxOPTION_READ_ONLY 3
44
45// Data types
46class WXDLLEXPORT wxRecordSet;
47
48class WXDLLEXPORT wxDatabase: public wxObject
49{
50 // JACS
51 DECLARE_DYNAMIC_CLASS(wxDatabase)
52 private:
53 protected:
54 static HENV hEnv;
55 static int refCount;
56
57 HDBC hDBC;
58 char* username;
59 char* password;
60 char* datasource;
61 char* dbname;
62 char* connectstring;
63 bool isOpen;
64
65 // error-handling variables
66 wxRETCODE retcode;
67 char sqlstate[SQL_SQLSTATE_SIZE+1]; // error class and subclass
68 char errmsg[SQL_MAX_MESSAGE_LENGTH]; // error message
69 long nat_err; // error number by ODBC driver
70 bool err_occured;
71
72 wxList recordSets; // Record sets: Added by JACS
73
74 public:
75 wxDatabase(void);
76 ~wxDatabase(void);
77
78 bool Open(char *, bool exclusive =FALSE, bool readOnly =TRUE, char *username ="ODBC", char *password ="");
79 bool Close(void);
80
81 // Cleanup operations, added by JACS
82 void DeleteRecordSets(void); // Called when the database is deleted
83 void ResetRecordSets(void); // Required if the database is closed
84 inline wxList& GetRecordSets(void) { return recordSets; }
85
86 inline char *GetUsername(void) { return username; }
87 inline char *GetPassword(void) { return password; }
88 inline char *GetDataSource(void) { return datasource; }
89 inline bool IsOpen(void) { return isOpen; }
90 inline wxRETCODE GetErrorCode(void) { return retcode; }
91 inline HDBC GetHDBC(void) { return hDBC; }
92 inline HENV GetHENV(void) { return hEnv; }
93
94 void SetPassword(char *s);
95 void SetUsername(char *s);
96 void SetDataSource(char *s);
97
98 // Database attributes
99 char *GetDatabaseName(void);
100 bool CanUpdate(void);
101 bool CanTransact(void);
102 bool InWaitForDataSource(void);
103 void SetLoginTimeout(long seconds);
104 void SetQueryTimeout(long seconds);
105 void SetSynchronousMode(bool synchronous);
106
107 // Database operations
108 bool BeginTrans(void);
109 bool CommitTrans(void);
110 bool RollbackTrans(void);
111 void Cancel(void);
112
113 // Error handling
114 bool ErrorOccured(void);
115 char* GetErrorMessage(void);
116 long GetErrorNumber(void);
117 char* GetErrorClass(void);
118 inline void ErrorSnapshot(HSTMT =SQL_NULL_HSTMT);
119
120 // Overridables
121 virtual void OnSetOptions(wxRecordSet *recordSet);
122 virtual void OnWaitForDataSource(bool stillExecuting);
123
124 bool GetInfo(long infoType, long *buf);
125 bool GetInfo(long infoType, char *buf, int bufSize = -1);
126
127 // implementation = TRUE means get the DLL version.
128 // Otherwise, returns header file version.
129 wxString GetODBCVersionString(bool implementation = TRUE);
130 float GetODBCVersionFloat(bool implementation = TRUE);
131};
132
133// Represents a data row
134class WXDLLEXPORT wxQueryField: public wxObject
135{
136 // JACS
137 DECLARE_DYNAMIC_CLASS(wxQueryField)
138 private:
139 void *data;
140 short type;
141 long size;
142 bool dirty;
143
144 bool AllocData(void);
145
146 public:
147 wxQueryField(void);
148 ~wxQueryField(void);
149
150 bool SetData(void*, long);
151 void SetDirty(bool =TRUE);
152 void ClearData(void);
153 void SetType(short);
154 void SetSize(long);
155
156 void* GetData(void);
157 short GetType(void);
158 long GetSize(void);
159
160 bool IsDirty(void);
161};
162
163// Represents a column description
164class WXDLLEXPORT wxQueryCol: public wxObject
165{
166 // JACS
167 DECLARE_DYNAMIC_CLASS(wxQueryCol)
168 private:
169 short type;
170 char *name;
171 bool nullable;
172 long varsize;
173 void* var;
174
175 public:
176 wxList fields;
177
178 wxQueryCol(void);
179 ~wxQueryCol(void);
180
181 void* BindVar(void*, long);
182 void FillVar(int);
183 void AppendField(void*, long);
184 bool SetData(int, void*, long);
185 void SetName(char*);
186 void SetNullable(bool);
187 void SetFieldDirty(int, bool =TRUE);
188 void SetType(short);
189
190 char* GetName(void);
191 short GetType(void);
192 bool IsNullable(void);
193 void* GetData(int);
194 long GetSize(int);
195
196 bool IsFieldDirty(int);
197};
198
199class WXDLLEXPORT wxRecordSet: public wxObject
200{
201 // JACS
202 DECLARE_DYNAMIC_CLASS(wxRecordSet)
203 private:
204 int cursor;
205 int type;
206 int options;
207
208 protected:
209 HSTMT hStmt;
210 int nFields;
211 int nParams;
212 int nRecords;
213 short nCols;
214 char *recordFilter;
215 char *sortString;
216 char *defaultSQL;
217 char* tablename;
218 wxDatabase *parentdb;
219 wxRETCODE retcode;
220 wxList cols;
221 wxList fetchbuf;
222
223 void FillVars(int);
224
225 public:
226 // JACS gave parent a default value for benefit of IMPLEMENT_DYNAMIC_CLASS
227 wxRecordSet(wxDatabase *parent = NULL, int =wxOPEN_TYPE_DYNASET, int =wxOPTION_DEFAULT);
228 ~wxRecordSet(void);
229
230 // My own, lower-level functions.
231 bool BeginQuery(int openType, char *sql = NULL, int options = wxOPTION_DEFAULT);
232 bool EndQuery(void);
233 bool Query(char* columns, char* table =NULL, char *filter =NULL);
234
235 // Attributes
236 inline int GetNumberFields(void) { return nFields; }
237 inline int GetNumberParams(void) { return nParams; }
238 long GetNumberRecords(void);
239 long GetNumberCols(void);
240 inline char *GetFilter(void) { return recordFilter; }
241 inline char *GetSortString(void) { return sortString; }
242 inline wxDatabase *GetDatabase(void) { return parentdb; }
243 inline wxRETCODE GetErrorCode(void) { return retcode; }
244 bool CanAppend(void);
245 bool CanRestart(void);
246 bool CanScroll(void);
247 bool CanTransact(void);
248 bool CanUpdate(void);
249 long GetCurrentRecord(void);
250 bool RecordCountFinal(void);
251 bool GetResultSet(void);
252 bool ExecuteSQL(char*);
253 bool GetTables(void);
254 bool GetColumns(char* =NULL);
255 bool GetPrimaryKeys(char* =NULL);
256 bool GetForeignKeys(char* , char * );
257 char *GetTableName(void);
258 void SetTableName(char*);
259 char *GetSQL(void);
260 bool IsOpen(void);
261 bool IsBOF(void);
262 bool IsEOF(void);
263 bool IsDeleted(void);
264
265 bool GetFieldData(int colPos, int dataType, void *dataPtr);
266 bool GetFieldData(const char*, int dataType, void *dataPtr);
267 void* GetFieldDataPtr(int, int);
268 void* GetFieldDataPtr(const char*, int);
269 char* GetColName(int);
270 short GetColType(int);
271 short GetColType(const char*);
272 void* BindVar(int, void*, long);
273 void* BindVar(const char*, void*, long);
274
275 void SetType(int);
276 int GetType(void);
277 void SetOptions(int);
278 int GetOptions(void);
279
280 // Update operations
281 void AddNew(void);
282 bool Delete(void);
283 void Edit(void);
284 bool Update(void);
285
286 // Record navigation
287 virtual bool Move(long rows);
288 virtual bool MoveFirst(void);
289 virtual bool MoveLast(void);
290 virtual bool MoveNext(void);
291 virtual bool MovePrev(void);
292 virtual bool GoTo(long);
293
294 // Others
295 bool GetDataSources(void);
296
297 // Associate a column name/position with a data location
298 // bool BindColumn(int colPos, int dataType, void *dataPtr);
299
300 void Cancel(void);
301 bool IsFieldDirty(int);
302 bool IsFieldDirty(const char*);
303 bool IsFieldNull(int);
304 bool IsFieldNull(const char*);
305 bool IsColNullable(int);
306 bool IsColNullable(const char*);
307 virtual bool Requery(void);
308 virtual void SetFieldDirty(int, bool dirty = TRUE);
309 virtual void SetFieldDirty(const char*, bool dirty = TRUE);
310 void SetFieldNull(void *p, bool isNull = TRUE);
311
312 // Overridables
313 virtual char *GetDefaultConnect(void);
314 virtual char *GetDefaultSQL(void);
315
316 // Internal
317
318 // Build SQL query from column specification
319 bool ConstructDefaultSQL(void);
320 void SetDefaultSQL(char *s);
321 bool ReleaseHandle(void); // Added JACS
322};
323
324#endif
325
326#endif // USE_ODBC