]>
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"
29 #include <../iodbc/postgres/isqlext.h>
30 #include <../iodbc/postgres/odbc_funcs.h>
31 #include <../iodbc/postgres/odbc_types.h>
39 #include "wx/string.h"
41 typedef RETCODE wxRETCODE
;
43 // Recordset open types
44 #define wxOPEN_TYPE_DYNASET 1
45 #define wxOPEN_TYPE_SNAPSHOT 2
46 #define wxOPEN_TYPE_FORWARD_ONLY 3
48 // Recordset open options
49 #define wxOPTION_DEFAULT 1
50 #define wxOPTION_APPEND_ONLY 2
51 #define wxOPTION_READ_ONLY 3
54 class WXDLLEXPORT wxRecordSet
;
56 class WXDLLEXPORT wxDatabase
: public wxObject
59 DECLARE_DYNAMIC_CLASS(wxDatabase
)
73 // error-handling variables
75 char sqlstate
[SQL_SQLSTATE_SIZE
+1]; // error class and subclass
76 char errmsg
[SQL_MAX_MESSAGE_LENGTH
]; // error message
77 long nat_err
; // error number by ODBC driver
80 wxList recordSets
; // Record sets: Added by JACS
86 bool Open(char *, bool exclusive
=FALSE
, bool readOnly
=TRUE
, char *username
="ODBC", char *password
="");
89 // Cleanup operations, added by JACS
90 void DeleteRecordSets(void); // Called when the database is deleted
91 void ResetRecordSets(void); // Required if the database is closed
92 inline wxList
& GetRecordSets(void) { return recordSets
; }
94 inline char *GetUsername(void) { return username
; }
95 inline char *GetPassword(void) { return password
; }
96 inline char *GetDataSource(void) { return datasource
; }
97 inline bool IsOpen(void) { return isOpen
; }
98 inline wxRETCODE
GetErrorCode(void) { return retcode
; }
99 inline HDBC
GetHDBC(void) { return hDBC
; }
100 inline HENV
GetHENV(void) { return hEnv
; }
102 void SetPassword(char *s
);
103 void SetUsername(char *s
);
104 void SetDataSource(char *s
);
106 // Database attributes
107 char *GetDatabaseName(void);
108 bool CanUpdate(void);
109 bool CanTransact(void);
110 bool InWaitForDataSource(void);
111 void SetLoginTimeout(long seconds
);
112 void SetQueryTimeout(long seconds
);
113 void SetSynchronousMode(bool synchronous
);
115 // Database operations
116 bool BeginTrans(void);
117 bool CommitTrans(void);
118 bool RollbackTrans(void);
122 bool ErrorOccured(void);
123 char* GetErrorMessage(void);
124 long GetErrorNumber(void);
125 char* GetErrorClass(void);
126 inline void ErrorSnapshot(HSTMT
=SQL_NULL_HSTMT
);
129 virtual void OnSetOptions(wxRecordSet
*recordSet
);
130 virtual void OnWaitForDataSource(bool stillExecuting
);
132 bool GetInfo(long infoType
, long *buf
);
133 bool GetInfo(long infoType
, char *buf
, int bufSize
= -1);
135 // implementation = TRUE means get the DLL version.
136 // Otherwise, returns header file version.
137 wxString
GetODBCVersionString(bool implementation
= TRUE
);
138 float GetODBCVersionFloat(bool implementation
= TRUE
);
141 // Represents a data row
142 class WXDLLEXPORT wxQueryField
: public wxObject
145 DECLARE_DYNAMIC_CLASS(wxQueryField
)
152 bool AllocData(void);
158 bool SetData(void*, long);
159 void SetDirty(bool =TRUE
);
160 void ClearData(void);
171 // Represents a column description
172 class WXDLLEXPORT wxQueryCol
: public wxObject
175 DECLARE_DYNAMIC_CLASS(wxQueryCol
)
189 void* BindVar(void*, long);
191 void AppendField(void*, long);
192 bool SetData(int, void*, long);
194 void SetNullable(bool);
195 void SetFieldDirty(int, bool =TRUE
);
200 bool IsNullable(void);
204 bool IsFieldDirty(int);
207 class WXDLLEXPORT wxRecordSet
: public wxObject
210 DECLARE_DYNAMIC_CLASS(wxRecordSet
)
226 wxDatabase
*parentdb
;
234 // JACS gave parent a default value for benefit of IMPLEMENT_DYNAMIC_CLASS
235 wxRecordSet(wxDatabase
*parent
= NULL
, int =wxOPEN_TYPE_DYNASET
, int =wxOPTION_DEFAULT
);
238 // My own, lower-level functions.
239 bool BeginQuery(int openType
, char *sql
= NULL
, int options
= wxOPTION_DEFAULT
);
241 bool Query(char* columns
, char* table
=NULL
, char *filter
=NULL
);
244 inline int GetNumberFields(void) { return nFields
; }
245 inline int GetNumberParams(void) { return nParams
; }
246 long GetNumberRecords(void);
247 long GetNumberCols(void);
248 inline char *GetFilter(void) { return recordFilter
; }
249 inline char *GetSortString(void) { return sortString
; }
250 inline wxDatabase
*GetDatabase(void) { return parentdb
; }
251 inline wxRETCODE
GetErrorCode(void) { return retcode
; }
252 bool CanAppend(void);
253 bool CanRestart(void);
254 bool CanScroll(void);
255 bool CanTransact(void);
256 bool CanUpdate(void);
257 long GetCurrentRecord(void);
258 bool RecordCountFinal(void);
259 bool GetResultSet(void);
260 bool ExecuteSQL(char*);
261 bool GetTables(void);
262 bool GetColumns(char* =NULL
);
263 bool GetPrimaryKeys(char* =NULL
);
264 bool GetForeignKeys(char* , char * );
265 char *GetTableName(void);
266 void SetTableName(char*);
271 bool IsDeleted(void);
273 bool GetFieldData(int colPos
, int dataType
, void *dataPtr
);
274 bool GetFieldData(const char*, int dataType
, void *dataPtr
);
275 void* GetFieldDataPtr(int, int);
276 void* GetFieldDataPtr(const char*, int);
277 char* GetColName(int);
278 short GetColType(int);
279 short GetColType(const char*);
280 void* BindVar(int, void*, long);
281 void* BindVar(const char*, void*, long);
285 void SetOptions(int);
286 int GetOptions(void);
295 virtual bool Move(long rows
);
296 virtual bool MoveFirst(void);
297 virtual bool MoveLast(void);
298 virtual bool MoveNext(void);
299 virtual bool MovePrev(void);
300 virtual bool GoTo(long);
303 bool GetDataSources(void);
305 // Associate a column name/position with a data location
306 // bool BindColumn(int colPos, int dataType, void *dataPtr);
309 bool IsFieldDirty(int);
310 bool IsFieldDirty(const char*);
311 bool IsFieldNull(int);
312 bool IsFieldNull(const char*);
313 bool IsColNullable(int);
314 bool IsColNullable(const char*);
315 virtual bool Requery(void);
316 virtual void SetFieldDirty(int, bool dirty
= TRUE
);
317 virtual void SetFieldDirty(const char*, bool dirty
= TRUE
);
318 void SetFieldNull(void *p
, bool isNull
= TRUE
);
321 virtual char *GetDefaultConnect(void);
322 virtual char *GetDefaultSQL(void);
326 // Build SQL query from column specification
327 bool ConstructDefaultSQL(void);
328 void SetDefaultSQL(char *s
);
329 bool ReleaseHandle(void); // Added JACS