]>
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"
31 #include "wx/string.h"
33 typedef RETCODE wxRETCODE
;
35 // Recordset open types
36 #define wxOPEN_TYPE_DYNASET 1
37 #define wxOPEN_TYPE_SNAPSHOT 2
38 #define wxOPEN_TYPE_FORWARD_ONLY 3
40 // Recordset open options
41 #define wxOPTION_DEFAULT 1
42 #define wxOPTION_APPEND_ONLY 2
43 #define wxOPTION_READ_ONLY 3
46 class WXDLLEXPORT wxRecordSet
;
48 class WXDLLEXPORT wxDatabase
: public wxObject
51 DECLARE_DYNAMIC_CLASS(wxDatabase
)
65 // error-handling variables
67 char sqlstate
[SQL_SQLSTATE_SIZE
+1]; // error class and subclass
68 char errmsg
[SQL_MAX_MESSAGE_LENGTH
]; // error message
69 long nat_err
; // error number by ODBC driver
72 wxList recordSets
; // Record sets: Added by JACS
78 bool Open(char *, bool exclusive
=FALSE
, bool readOnly
=TRUE
, char *username
="ODBC", char *password
="");
81 // Cleanup operations, added by JACS
82 void DeleteRecordSets(void); // Called when the database is deleted
83 void ResetRecordSets(void); // Required if the database is closed
84 inline wxList
& GetRecordSets(void) { return recordSets
; }
86 inline char *GetUsername(void) { return username
; }
87 inline char *GetPassword(void) { return password
; }
88 inline char *GetDataSource(void) { return datasource
; }
89 inline bool IsOpen(void) { return isOpen
; }
90 inline wxRETCODE
GetErrorCode(void) { return retcode
; }
91 inline HDBC
GetHDBC(void) { return hDBC
; }
92 inline HENV
GetHENV(void) { return hEnv
; }
94 void SetPassword(char *s
);
95 void SetUsername(char *s
);
96 void SetDataSource(char *s
);
98 // Database attributes
99 char *GetDatabaseName(void);
100 bool CanUpdate(void);
101 bool CanTransact(void);
102 bool InWaitForDataSource(void);
103 void SetLoginTimeout(long seconds
);
104 void SetQueryTimeout(long seconds
);
105 void SetSynchronousMode(bool synchronous
);
107 // Database operations
108 bool BeginTrans(void);
109 bool CommitTrans(void);
110 bool RollbackTrans(void);
114 bool ErrorOccured(void);
115 char* GetErrorMessage(void);
116 long GetErrorNumber(void);
117 char* GetErrorClass(void);
118 inline void ErrorSnapshot(HSTMT
=SQL_NULL_HSTMT
);
121 virtual void OnSetOptions(wxRecordSet
*recordSet
);
122 virtual void OnWaitForDataSource(bool stillExecuting
);
124 bool GetInfo(long infoType
, long *buf
);
125 bool GetInfo(long infoType
, char *buf
, int bufSize
= -1);
127 // implementation = TRUE means get the DLL version.
128 // Otherwise, returns header file version.
129 wxString
GetODBCVersionString(bool implementation
= TRUE
);
130 float GetODBCVersionFloat(bool implementation
= TRUE
);
133 // Represents a data row
134 class WXDLLEXPORT wxQueryField
: public wxObject
137 DECLARE_DYNAMIC_CLASS(wxQueryField
)
144 bool AllocData(void);
150 bool SetData(void*, long);
151 void SetDirty(bool =TRUE
);
152 void ClearData(void);
163 // Represents a column description
164 class WXDLLEXPORT wxQueryCol
: public wxObject
167 DECLARE_DYNAMIC_CLASS(wxQueryCol
)
181 void* BindVar(void*, long);
183 void AppendField(void*, long);
184 bool SetData(int, void*, long);
186 void SetNullable(bool);
187 void SetFieldDirty(int, bool =TRUE
);
192 bool IsNullable(void);
196 bool IsFieldDirty(int);
199 class WXDLLEXPORT wxRecordSet
: public wxObject
202 DECLARE_DYNAMIC_CLASS(wxRecordSet
)
218 wxDatabase
*parentdb
;
226 // JACS gave parent a default value for benefit of IMPLEMENT_DYNAMIC_CLASS
227 wxRecordSet(wxDatabase
*parent
= NULL
, int =wxOPEN_TYPE_DYNASET
, int =wxOPTION_DEFAULT
);
230 // My own, lower-level functions.
231 bool BeginQuery(int openType
, char *sql
= NULL
, int options
= wxOPTION_DEFAULT
);
233 bool Query(char* columns
, char* table
=NULL
, char *filter
=NULL
);
236 inline int GetNumberFields(void) { return nFields
; }
237 inline int GetNumberParams(void) { return nParams
; }
238 long GetNumberRecords(void);
239 long GetNumberCols(void);
240 inline char *GetFilter(void) { return recordFilter
; }
241 inline char *GetSortString(void) { return sortString
; }
242 inline wxDatabase
*GetDatabase(void) { return parentdb
; }
243 inline wxRETCODE
GetErrorCode(void) { return retcode
; }
244 bool CanAppend(void);
245 bool CanRestart(void);
246 bool CanScroll(void);
247 bool CanTransact(void);
248 bool CanUpdate(void);
249 long GetCurrentRecord(void);
250 bool RecordCountFinal(void);
251 bool GetResultSet(void);
252 bool ExecuteSQL(char*);
253 bool GetTables(void);
254 bool GetColumns(char* =NULL
);
255 bool GetPrimaryKeys(char* =NULL
);
256 bool GetForeignKeys(char* , char * );
257 char *GetTableName(void);
258 void SetTableName(char*);
263 bool IsDeleted(void);
265 bool GetFieldData(int colPos
, int dataType
, void *dataPtr
);
266 bool GetFieldData(const char*, int dataType
, void *dataPtr
);
267 void* GetFieldDataPtr(int, int);
268 void* GetFieldDataPtr(const char*, int);
269 char* GetColName(int);
270 short GetColType(int);
271 short GetColType(const char*);
272 void* BindVar(int, void*, long);
273 void* BindVar(const char*, void*, long);
277 void SetOptions(int);
278 int GetOptions(void);
287 virtual bool Move(long rows
);
288 virtual bool MoveFirst(void);
289 virtual bool MoveLast(void);
290 virtual bool MoveNext(void);
291 virtual bool MovePrev(void);
292 virtual bool GoTo(long);
295 bool GetDataSources(void);
297 // Associate a column name/position with a data location
298 // bool BindColumn(int colPos, int dataType, void *dataPtr);
301 bool IsFieldDirty(int);
302 bool IsFieldDirty(const char*);
303 bool IsFieldNull(int);
304 bool IsFieldNull(const char*);
305 bool IsColNullable(int);
306 bool IsColNullable(const char*);
307 virtual bool Requery(void);
308 virtual void SetFieldDirty(int, bool dirty
= TRUE
);
309 virtual void SetFieldDirty(const char*, bool dirty
= TRUE
);
310 void SetFieldNull(void *p
, bool isNull
= TRUE
);
313 virtual char *GetDefaultConnect(void);
314 virtual char *GetDefaultSQL(void);
318 // Build SQL query from column specification
319 bool ConstructDefaultSQL(void);
320 void SetDefaultSQL(char *s
);
321 bool ReleaseHandle(void); // Added JACS