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