]> git.saurik.com Git - wxWidgets.git/blame - include/wx/odbc.h
improved dialup manager, added wxALL_FILES define
[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
2049ba38 23#ifdef __WXMSW__
c801d85f
KB
24#include <windows.h>
25#endif
26
06cfab17 27
5b7f1aab
VZ
28#ifdef __UNIX__
29extern "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
0d73e5a1 40}
5b7f1aab
VZ
41#else // !Unix
42 #include <sqlext.h>
43#endif // Unix/!Unix
c801d85f
KB
44
45#include "wx/defs.h"
46#include "wx/list.h"
47#include "wx/string.h"
48
49typedef 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
62class WXDLLEXPORT wxRecordSet;
63
64class WXDLLEXPORT wxDatabase: public wxObject
65{
c801d85f 66 DECLARE_DYNAMIC_CLASS(wxDatabase)
c801d85f
KB
67 protected:
68 static HENV hEnv;
69 static int refCount;
5b7f1aab 70
c801d85f
KB
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
5b7f1aab 87
c801d85f 88 public:
5b7f1aab
VZ
89 wxDatabase();
90 ~wxDatabase();
91
c801d85f 92 bool Open(char *, bool exclusive =FALSE, bool readOnly =TRUE, char *username ="ODBC", char *password ="");
5b7f1aab 93 bool Close();
c801d85f
KB
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; }
5b7f1aab 99
c801d85f
KB
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; }
5b7f1aab 107
c801d85f
KB
108 void SetPassword(char *s);
109 void SetUsername(char *s);
110 void SetDataSource(char *s);
5b7f1aab 111
c801d85f 112 // Database attributes
5b7f1aab
VZ
113 char *GetDatabaseName();
114 bool CanUpdate();
115 bool CanTransact();
116 bool InWaitForDataSource();
c801d85f
KB
117 void SetLoginTimeout(long seconds);
118 void SetQueryTimeout(long seconds);
119 void SetSynchronousMode(bool synchronous);
120
121 // Database operations
5b7f1aab
VZ
122 bool BeginTrans();
123 bool CommitTrans();
124 bool RollbackTrans();
125 void Cancel();
c801d85f
KB
126
127 // Error handling
5b7f1aab
VZ
128 bool ErrorOccured();
129 char* GetErrorMessage();
130 long GetErrorNumber();
131 char* GetErrorClass();
c801d85f
KB
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
148class 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
5b7f1aab 158 bool AllocData();
c801d85f
KB
159
160 public:
5b7f1aab
VZ
161 wxQueryField();
162 ~wxQueryField();
163
c801d85f
KB
164 bool SetData(void*, long);
165 void SetDirty(bool =TRUE);
5b7f1aab 166 void ClearData();
c801d85f
KB
167 void SetType(short);
168 void SetSize(long);
5b7f1aab
VZ
169
170 void* GetData();
171 short GetType();
172 long GetSize();
173
174 bool IsDirty();
c801d85f
KB
175};
176
177// Represents a column description
178class 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;
5b7f1aab 188
c801d85f
KB
189 public:
190 wxList fields;
5b7f1aab
VZ
191
192 wxQueryCol();
193 ~wxQueryCol();
194
c801d85f
KB
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);
5b7f1aab
VZ
203
204 char* GetName();
205 short GetType();
206 bool IsNullable();
c801d85f
KB
207 void* GetData(int);
208 long GetSize(int);
209
210 bool IsFieldDirty(int);
211};
212
213class WXDLLEXPORT wxRecordSet: public wxObject
214{
215 // JACS
216 DECLARE_DYNAMIC_CLASS(wxRecordSet)
217 private:
218 int cursor;
219 int type;
220 int options;
5b7f1aab 221
c801d85f
KB
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;
5b7f1aab 236
c801d85f
KB
237 void FillVars(int);
238
239 public:
240 // JACS gave parent a default value for benefit of IMPLEMENT_DYNAMIC_CLASS
5b7f1aab
VZ
241 wxRecordSet(wxDatabase *parent = NULL,
242 int = wxOPEN_TYPE_DYNASET,
243 int = wxOPTION_DEFAULT);
244 ~wxRecordSet();
245
c801d85f
KB
246 // My own, lower-level functions.
247 bool BeginQuery(int openType, char *sql = NULL, int options = wxOPTION_DEFAULT);
5b7f1aab 248 bool EndQuery();
c801d85f
KB
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; }
5b7f1aab
VZ
254 long GetNumberRecords();
255 long GetNumberCols();
c801d85f
KB
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; }
5b7f1aab
VZ
260 bool CanAppend();
261 bool CanRestart();
262 bool CanScroll();
263 bool CanTransact();
264 bool CanUpdate();
265 long GetCurrentRecord();
266 bool RecordCountFinal();
267 bool GetResultSet();
c801d85f 268 bool ExecuteSQL(char*);
5b7f1aab 269 bool GetTables();
c801d85f
KB
270 bool GetColumns(char* =NULL);
271 bool GetPrimaryKeys(char* =NULL);
272 bool GetForeignKeys(char* , char * );
5b7f1aab 273 char *GetTableName();
c801d85f 274 void SetTableName(char*);
5b7f1aab
VZ
275 char *GetSQL();
276 bool IsOpen();
277 bool IsBOF();
278 bool IsEOF();
279 bool IsDeleted();
c801d85f
KB
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);
5b7f1aab 292 int GetType();
c801d85f 293 void SetOptions(int);
5b7f1aab
VZ
294 int GetOptions();
295
c801d85f 296 // Update operations
5b7f1aab
VZ
297 void AddNew();
298 bool Delete();
299 void Edit();
300 bool Update();
c801d85f
KB
301
302 // Record navigation
303 virtual bool Move(long rows);
5b7f1aab
VZ
304 virtual bool MoveFirst();
305 virtual bool MoveLast();
306 virtual bool MoveNext();
307 virtual bool MovePrev();
c801d85f
KB
308 virtual bool GoTo(long);
309
310 // Others
5b7f1aab 311 bool GetDataSources();
c801d85f
KB
312
313 // Associate a column name/position with a data location
314 // bool BindColumn(int colPos, int dataType, void *dataPtr);
315
5b7f1aab 316 void Cancel();
c801d85f
KB
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*);
5b7f1aab 323 virtual bool Requery();
c801d85f
KB
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
5b7f1aab
VZ
329 virtual char *GetDefaultConnect();
330 virtual char *GetDefaultSQL();
331
c801d85f 332 // Internal
5b7f1aab 333
c801d85f 334 // Build SQL query from column specification
5b7f1aab 335 bool ConstructDefaultSQL();
c801d85f
KB
336 void SetDefaultSQL(char *s);
337 bool ReleaseHandle(void); // Added JACS
338};
339
340#endif
341
47d67540 342#endif // wxUSE_ODBC