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