]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/odbc.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: ODBC classes
4 // Author: Olaf Klein, Patrick Halke, Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
16 #if defined(__GNUG__) && !defined(__APPLE__)
17 #pragma interface "odbc.h"
24 //#include <windows.h>
32 #include "wx/isqlext.h"
35 typedef double SDOUBLE
;
38 #define SQL_SQLSTATE_SIZE 5
46 #include "wx/string.h"
48 typedef RETCODE wxRETCODE
;
50 // Recordset open types
51 #define wxOPEN_TYPE_DYNASET 1
52 #define wxOPEN_TYPE_SNAPSHOT 2
53 #define wxOPEN_TYPE_FORWARD_ONLY 3
55 // Recordset open options
56 #define wxOPTION_DEFAULT 1
57 #define wxOPTION_APPEND_ONLY 2
58 #define wxOPTION_READ_ONLY 3
61 class WXDLLEXPORT wxRecordSet
;
63 class WXDLLEXPORT wxDatabase
: public wxObject
65 DECLARE_DYNAMIC_CLASS(wxDatabase
)
78 // error-handling variables
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
85 wxList recordSets
; // Record sets: Added by JACS
91 bool Open(char *, bool exclusive
=FALSE
, bool readOnly
=TRUE
, char *username
="ODBC", char *password
="");
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
; }
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
; }
107 void SetPassword(char *s
);
108 void SetUsername(char *s
);
109 void SetDataSource(char *s
);
111 // Database attributes
112 char *GetDatabaseName();
115 bool InWaitForDataSource();
116 void SetLoginTimeout(long seconds
);
117 void SetQueryTimeout(long seconds
);
118 void SetSynchronousMode(bool synchronous
);
120 // Database operations
123 bool RollbackTrans();
128 char* GetErrorMessage();
129 long GetErrorNumber();
130 char* GetErrorClass();
131 inline void ErrorSnapshot(HSTMT
=SQL_NULL_HSTMT
);
134 virtual void OnSetOptions(wxRecordSet
*recordSet
);
135 virtual void OnWaitForDataSource(bool stillExecuting
);
137 bool GetInfo(long infoType
, long *buf
);
138 bool GetInfo(long infoType
, char *buf
, int bufSize
= -1);
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
);
146 // Represents a data row
147 class WXDLLEXPORT wxQueryField
: public wxObject
150 DECLARE_DYNAMIC_CLASS(wxQueryField
)
163 bool SetData(void*, long);
164 void SetDirty(bool =TRUE
);
176 // Represents a column description
177 class WXDLLEXPORT wxQueryCol
: public wxObject
180 DECLARE_DYNAMIC_CLASS(wxQueryCol
)
194 void* BindVar(void*, long);
196 void AppendField(void*, long);
197 bool SetData(int, void*, long);
199 void SetNullable(bool);
200 void SetFieldDirty(int, bool =TRUE
);
209 bool IsFieldDirty(int);
212 class WXDLLEXPORT wxRecordSet
: public wxObject
215 DECLARE_DYNAMIC_CLASS(wxRecordSet
)
231 wxDatabase
*parentdb
;
239 // JACS gave parent a default value for benefit of IMPLEMENT_DYNAMIC_CLASS
240 wxRecordSet(wxDatabase
*parent
= NULL
,
241 int = wxOPEN_TYPE_DYNASET
,
242 int = wxOPTION_DEFAULT
);
245 // My own, lower-level functions.
246 bool BeginQuery(int openType
, char *sql
= NULL
, int options
= wxOPTION_DEFAULT
);
248 bool Query(char* columns
, char* table
=NULL
, char *filter
=NULL
);
251 inline int GetNumberFields(void) { return nFields
; }
252 inline int GetNumberParams(void) { return nParams
; }
253 long GetNumberRecords();
254 long GetNumberCols();
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
; }
264 long GetCurrentRecord();
265 bool RecordCountFinal();
267 bool ExecuteSQL(char*);
269 bool GetColumns(char* =NULL
);
270 bool GetPrimaryKeys(char* =NULL
);
271 bool GetForeignKeys(char* , char * );
272 char *GetTableName();
273 void SetTableName(char*);
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);
292 void SetOptions(int);
302 virtual bool Move(long rows
);
303 virtual bool MoveFirst();
304 virtual bool MoveLast();
305 virtual bool MoveNext();
306 virtual bool MovePrev();
307 virtual bool GoTo(long);
310 bool GetDataSources();
312 // Associate a column name/position with a data location
313 // bool BindColumn(int colPos, int dataType, void *dataPtr);
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*);
322 virtual bool Requery();
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
);
328 virtual char *GetDefaultConnect();
329 virtual char *GetDefaultSQL();
333 // Build SQL query from column specification
334 bool ConstructDefaultSQL();
335 void SetDefaultSQL(char *s
);
336 bool ReleaseHandle(void); // Added JACS