]>
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 /////////////////////////////////////////////////////////////////////////////
27 #include "wx/string.h"
29 typedef RETCODE wxRETCODE
;
31 // Recordset open types
32 #define wxOPEN_TYPE_DYNASET 1
33 #define wxOPEN_TYPE_SNAPSHOT 2
34 #define wxOPEN_TYPE_FORWARD_ONLY 3
36 // Recordset open options
37 #define wxOPTION_DEFAULT 1
38 #define wxOPTION_APPEND_ONLY 2
39 #define wxOPTION_READ_ONLY 3
42 class WXDLLEXPORT wxRecordSet
;
44 class WXDLLEXPORT wxDatabase
: public wxObject
47 DECLARE_DYNAMIC_CLASS(wxDatabase
)
61 // error-handling variables
63 char sqlstate
[SQL_SQLSTATE_SIZE
+1]; // error class and subclass
64 char errmsg
[SQL_MAX_MESSAGE_LENGTH
]; // error message
65 long nat_err
; // error number by ODBC driver
68 wxList recordSets
; // Record sets: Added by JACS
74 bool Open(char *, bool exclusive
=FALSE
, bool readOnly
=TRUE
, char *username
="ODBC", char *password
="");
77 // Cleanup operations, added by JACS
78 void DeleteRecordSets(void); // Called when the database is deleted
79 void ResetRecordSets(void); // Required if the database is closed
80 inline wxList
& GetRecordSets(void) { return recordSets
; }
82 inline char *GetUsername(void) { return username
; }
83 inline char *GetPassword(void) { return password
; }
84 inline char *GetDataSource(void) { return datasource
; }
85 inline bool IsOpen(void) { return isOpen
; }
86 inline wxRETCODE
GetErrorCode(void) { return retcode
; }
87 inline HDBC
GetHDBC(void) { return hDBC
; }
88 inline HENV
GetHENV(void) { return hEnv
; }
90 void SetPassword(char *s
);
91 void SetUsername(char *s
);
92 void SetDataSource(char *s
);
94 // Database attributes
95 char *GetDatabaseName(void);
97 bool CanTransact(void);
98 bool InWaitForDataSource(void);
99 void SetLoginTimeout(long seconds
);
100 void SetQueryTimeout(long seconds
);
101 void SetSynchronousMode(bool synchronous
);
103 // Database operations
104 bool BeginTrans(void);
105 bool CommitTrans(void);
106 bool RollbackTrans(void);
110 bool ErrorOccured(void);
111 char* GetErrorMessage(void);
112 long GetErrorNumber(void);
113 char* GetErrorClass(void);
114 inline void ErrorSnapshot(HSTMT
=SQL_NULL_HSTMT
);
117 virtual void OnSetOptions(wxRecordSet
*recordSet
);
118 virtual void OnWaitForDataSource(bool stillExecuting
);
120 bool GetInfo(long infoType
, long *buf
);
121 bool GetInfo(long infoType
, char *buf
, int bufSize
= -1);
123 // implementation = TRUE means get the DLL version.
124 // Otherwise, returns header file version.
125 wxString
GetODBCVersionString(bool implementation
= TRUE
);
126 float GetODBCVersionFloat(bool implementation
= TRUE
);
129 // Represents a data row
130 class WXDLLEXPORT wxQueryField
: public wxObject
133 DECLARE_DYNAMIC_CLASS(wxQueryField
)
140 bool AllocData(void);
146 bool SetData(void*, long);
147 void SetDirty(bool =TRUE
);
148 void ClearData(void);
159 // Represents a column description
160 class WXDLLEXPORT wxQueryCol
: public wxObject
163 DECLARE_DYNAMIC_CLASS(wxQueryCol
)
177 void* BindVar(void*, long);
179 void AppendField(void*, long);
180 bool SetData(int, void*, long);
182 void SetNullable(bool);
183 void SetFieldDirty(int, bool =TRUE
);
188 bool IsNullable(void);
192 bool IsFieldDirty(int);
195 class WXDLLEXPORT wxRecordSet
: public wxObject
198 DECLARE_DYNAMIC_CLASS(wxRecordSet
)
214 wxDatabase
*parentdb
;
222 // JACS gave parent a default value for benefit of IMPLEMENT_DYNAMIC_CLASS
223 wxRecordSet(wxDatabase
*parent
= NULL
, int =wxOPEN_TYPE_DYNASET
, int =wxOPTION_DEFAULT
);
226 // My own, lower-level functions.
227 bool BeginQuery(int openType
, char *sql
= NULL
, int options
= wxOPTION_DEFAULT
);
229 bool Query(char* columns
, char* table
=NULL
, char *filter
=NULL
);
232 inline int GetNumberFields(void) { return nFields
; }
233 inline int GetNumberParams(void) { return nParams
; }
234 long GetNumberRecords(void);
235 long GetNumberCols(void);
236 inline char *GetFilter(void) { return recordFilter
; }
237 inline char *GetSortString(void) { return sortString
; }
238 inline wxDatabase
*GetDatabase(void) { return parentdb
; }
239 inline wxRETCODE
GetErrorCode(void) { return retcode
; }
240 bool CanAppend(void);
241 bool CanRestart(void);
242 bool CanScroll(void);
243 bool CanTransact(void);
244 bool CanUpdate(void);
245 long GetCurrentRecord(void);
246 bool RecordCountFinal(void);
247 bool GetResultSet(void);
248 bool ExecuteSQL(char*);
249 bool GetTables(void);
250 bool GetColumns(char* =NULL
);
251 bool GetPrimaryKeys(char* =NULL
);
252 bool GetForeignKeys(char* , char * );
253 char *GetTableName(void);
254 void SetTableName(char*);
259 bool IsDeleted(void);
261 bool GetFieldData(int colPos
, int dataType
, void *dataPtr
);
262 bool GetFieldData(const char*, int dataType
, void *dataPtr
);
263 void* GetFieldDataPtr(int, int);
264 void* GetFieldDataPtr(const char*, int);
265 char* GetColName(int);
266 short GetColType(int);
267 short GetColType(const char*);
268 void* BindVar(int, void*, long);
269 void* BindVar(const char*, void*, long);
273 void SetOptions(int);
274 int GetOptions(void);
283 virtual bool Move(long rows
);
284 virtual bool MoveFirst(void);
285 virtual bool MoveLast(void);
286 virtual bool MoveNext(void);
287 virtual bool MovePrev(void);
288 virtual bool GoTo(long);
291 bool GetDataSources(void);
293 // Associate a column name/position with a data location
294 // bool BindColumn(int colPos, int dataType, void *dataPtr);
297 bool IsFieldDirty(int);
298 bool IsFieldDirty(const char*);
299 bool IsFieldNull(int);
300 bool IsFieldNull(const char*);
301 bool IsColNullable(int);
302 bool IsColNullable(const char*);
303 virtual bool Requery(void);
304 virtual void SetFieldDirty(int, bool dirty
= TRUE
);
305 virtual void SetFieldDirty(const char*, bool dirty
= TRUE
);
306 void SetFieldNull(void *p
, bool isNull
= TRUE
);
309 virtual char *GetDefaultConnect(void);
310 virtual char *GetDefaultSQL(void);
314 // Build SQL query from column specification
315 bool ConstructDefaultSQL(void);
316 void SetDefaultSQL(char *s
);
317 bool ReleaseHandle(void); // Added JACS