]>
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 /////////////////////////////////////////////////////////////////////////////
17 #pragma interface "odbc.h"
30 #include "../../src/iodbc/isql.h"
31 #include "../../src/iodbc/isqlext.h"
32 #include "../../src/iodbc/odbc_funcs.h"
33 #include "../../src/iodbc/odbc_types.h"
35 typedef double SDOUBLE
;
44 #include "wx/string.h"
46 typedef RETCODE wxRETCODE
;
48 // Recordset open types
49 #define wxOPEN_TYPE_DYNASET 1
50 #define wxOPEN_TYPE_SNAPSHOT 2
51 #define wxOPEN_TYPE_FORWARD_ONLY 3
53 // Recordset open options
54 #define wxOPTION_DEFAULT 1
55 #define wxOPTION_APPEND_ONLY 2
56 #define wxOPTION_READ_ONLY 3
59 class WXDLLEXPORT wxRecordSet
;
61 class WXDLLEXPORT wxDatabase
: public wxObject
64 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(void);
113 bool CanUpdate(void);
114 bool CanTransact(void);
115 bool InWaitForDataSource(void);
116 void SetLoginTimeout(long seconds
);
117 void SetQueryTimeout(long seconds
);
118 void SetSynchronousMode(bool synchronous
);
120 // Database operations
121 bool BeginTrans(void);
122 bool CommitTrans(void);
123 bool RollbackTrans(void);
127 bool ErrorOccured(void);
128 char* GetErrorMessage(void);
129 long GetErrorNumber(void);
130 char* GetErrorClass(void);
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
)
157 bool AllocData(void);
163 bool SetData(void*, long);
164 void SetDirty(bool =TRUE
);
165 void ClearData(void);
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
);
205 bool IsNullable(void);
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
, int =wxOPEN_TYPE_DYNASET
, int =wxOPTION_DEFAULT
);
243 // My own, lower-level functions.
244 bool BeginQuery(int openType
, char *sql
= NULL
, int options
= wxOPTION_DEFAULT
);
246 bool Query(char* columns
, char* table
=NULL
, char *filter
=NULL
);
249 inline int GetNumberFields(void) { return nFields
; }
250 inline int GetNumberParams(void) { return nParams
; }
251 long GetNumberRecords(void);
252 long GetNumberCols(void);
253 inline char *GetFilter(void) { return recordFilter
; }
254 inline char *GetSortString(void) { return sortString
; }
255 inline wxDatabase
*GetDatabase(void) { return parentdb
; }
256 inline wxRETCODE
GetErrorCode(void) { return retcode
; }
257 bool CanAppend(void);
258 bool CanRestart(void);
259 bool CanScroll(void);
260 bool CanTransact(void);
261 bool CanUpdate(void);
262 long GetCurrentRecord(void);
263 bool RecordCountFinal(void);
264 bool GetResultSet(void);
265 bool ExecuteSQL(char*);
266 bool GetTables(void);
267 bool GetColumns(char* =NULL
);
268 bool GetPrimaryKeys(char* =NULL
);
269 bool GetForeignKeys(char* , char * );
270 char *GetTableName(void);
271 void SetTableName(char*);
276 bool IsDeleted(void);
278 bool GetFieldData(int colPos
, int dataType
, void *dataPtr
);
279 bool GetFieldData(const char*, int dataType
, void *dataPtr
);
280 void* GetFieldDataPtr(int, int);
281 void* GetFieldDataPtr(const char*, int);
282 char* GetColName(int);
283 short GetColType(int);
284 short GetColType(const char*);
285 void* BindVar(int, void*, long);
286 void* BindVar(const char*, void*, long);
290 void SetOptions(int);
291 int GetOptions(void);
300 virtual bool Move(long rows
);
301 virtual bool MoveFirst(void);
302 virtual bool MoveLast(void);
303 virtual bool MoveNext(void);
304 virtual bool MovePrev(void);
305 virtual bool GoTo(long);
308 bool GetDataSources(void);
310 // Associate a column name/position with a data location
311 // bool BindColumn(int colPos, int dataType, void *dataPtr);
314 bool IsFieldDirty(int);
315 bool IsFieldDirty(const char*);
316 bool IsFieldNull(int);
317 bool IsFieldNull(const char*);
318 bool IsColNullable(int);
319 bool IsColNullable(const char*);
320 virtual bool Requery(void);
321 virtual void SetFieldDirty(int, bool dirty
= TRUE
);
322 virtual void SetFieldDirty(const char*, bool dirty
= TRUE
);
323 void SetFieldNull(void *p
, bool isNull
= TRUE
);
326 virtual char *GetDefaultConnect(void);
327 virtual char *GetDefaultSQL(void);
331 // Build SQL query from column specification
332 bool ConstructDefaultSQL(void);
333 void SetDefaultSQL(char *s
);
334 bool ReleaseHandle(void); // Added JACS