]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/odbc.h
ed73055dedcc1f2d6e03c575b4556b8a26de862f
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"
28 #include <../iodbc/postgres/isqlext.h>
29 #include <../iodbc/postgres/odbc_funcs.h>
30 #include <../iodbc/postgres/odbc_types.h>
37 #include "wx/string.h"
39 typedef RETCODE wxRETCODE
;
41 // Recordset open types
42 #define wxOPEN_TYPE_DYNASET 1
43 #define wxOPEN_TYPE_SNAPSHOT 2
44 #define wxOPEN_TYPE_FORWARD_ONLY 3
46 // Recordset open options
47 #define wxOPTION_DEFAULT 1
48 #define wxOPTION_APPEND_ONLY 2
49 #define wxOPTION_READ_ONLY 3
52 class WXDLLEXPORT wxRecordSet
;
54 class WXDLLEXPORT wxDatabase
: public wxObject
57 DECLARE_DYNAMIC_CLASS(wxDatabase
)
71 // error-handling variables
73 char sqlstate
[SQL_SQLSTATE_SIZE
+1]; // error class and subclass
74 char errmsg
[SQL_MAX_MESSAGE_LENGTH
]; // error message
75 long nat_err
; // error number by ODBC driver
78 wxList recordSets
; // Record sets: Added by JACS
84 bool Open(char *, bool exclusive
=FALSE
, bool readOnly
=TRUE
, char *username
="ODBC", char *password
="");
87 // Cleanup operations, added by JACS
88 void DeleteRecordSets(void); // Called when the database is deleted
89 void ResetRecordSets(void); // Required if the database is closed
90 inline wxList
& GetRecordSets(void) { return recordSets
; }
92 inline char *GetUsername(void) { return username
; }
93 inline char *GetPassword(void) { return password
; }
94 inline char *GetDataSource(void) { return datasource
; }
95 inline bool IsOpen(void) { return isOpen
; }
96 inline wxRETCODE
GetErrorCode(void) { return retcode
; }
97 inline HDBC
GetHDBC(void) { return hDBC
; }
98 inline HENV
GetHENV(void) { return hEnv
; }
100 void SetPassword(char *s
);
101 void SetUsername(char *s
);
102 void SetDataSource(char *s
);
104 // Database attributes
105 char *GetDatabaseName(void);
106 bool CanUpdate(void);
107 bool CanTransact(void);
108 bool InWaitForDataSource(void);
109 void SetLoginTimeout(long seconds
);
110 void SetQueryTimeout(long seconds
);
111 void SetSynchronousMode(bool synchronous
);
113 // Database operations
114 bool BeginTrans(void);
115 bool CommitTrans(void);
116 bool RollbackTrans(void);
120 bool ErrorOccured(void);
121 char* GetErrorMessage(void);
122 long GetErrorNumber(void);
123 char* GetErrorClass(void);
124 inline void ErrorSnapshot(HSTMT
=SQL_NULL_HSTMT
);
127 virtual void OnSetOptions(wxRecordSet
*recordSet
);
128 virtual void OnWaitForDataSource(bool stillExecuting
);
130 bool GetInfo(long infoType
, long *buf
);
131 bool GetInfo(long infoType
, char *buf
, int bufSize
= -1);
133 // implementation = TRUE means get the DLL version.
134 // Otherwise, returns header file version.
135 wxString
GetODBCVersionString(bool implementation
= TRUE
);
136 float GetODBCVersionFloat(bool implementation
= TRUE
);
139 // Represents a data row
140 class WXDLLEXPORT wxQueryField
: public wxObject
143 DECLARE_DYNAMIC_CLASS(wxQueryField
)
150 bool AllocData(void);
156 bool SetData(void*, long);
157 void SetDirty(bool =TRUE
);
158 void ClearData(void);
169 // Represents a column description
170 class WXDLLEXPORT wxQueryCol
: public wxObject
173 DECLARE_DYNAMIC_CLASS(wxQueryCol
)
187 void* BindVar(void*, long);
189 void AppendField(void*, long);
190 bool SetData(int, void*, long);
192 void SetNullable(bool);
193 void SetFieldDirty(int, bool =TRUE
);
198 bool IsNullable(void);
202 bool IsFieldDirty(int);
205 class WXDLLEXPORT wxRecordSet
: public wxObject
208 DECLARE_DYNAMIC_CLASS(wxRecordSet
)
224 wxDatabase
*parentdb
;
232 // JACS gave parent a default value for benefit of IMPLEMENT_DYNAMIC_CLASS
233 wxRecordSet(wxDatabase
*parent
= NULL
, int =wxOPEN_TYPE_DYNASET
, int =wxOPTION_DEFAULT
);
236 // My own, lower-level functions.
237 bool BeginQuery(int openType
, char *sql
= NULL
, int options
= wxOPTION_DEFAULT
);
239 bool Query(char* columns
, char* table
=NULL
, char *filter
=NULL
);
242 inline int GetNumberFields(void) { return nFields
; }
243 inline int GetNumberParams(void) { return nParams
; }
244 long GetNumberRecords(void);
245 long GetNumberCols(void);
246 inline char *GetFilter(void) { return recordFilter
; }
247 inline char *GetSortString(void) { return sortString
; }
248 inline wxDatabase
*GetDatabase(void) { return parentdb
; }
249 inline wxRETCODE
GetErrorCode(void) { return retcode
; }
250 bool CanAppend(void);
251 bool CanRestart(void);
252 bool CanScroll(void);
253 bool CanTransact(void);
254 bool CanUpdate(void);
255 long GetCurrentRecord(void);
256 bool RecordCountFinal(void);
257 bool GetResultSet(void);
258 bool ExecuteSQL(char*);
259 bool GetTables(void);
260 bool GetColumns(char* =NULL
);
261 bool GetPrimaryKeys(char* =NULL
);
262 bool GetForeignKeys(char* , char * );
263 char *GetTableName(void);
264 void SetTableName(char*);
269 bool IsDeleted(void);
271 bool GetFieldData(int colPos
, int dataType
, void *dataPtr
);
272 bool GetFieldData(const char*, int dataType
, void *dataPtr
);
273 void* GetFieldDataPtr(int, int);
274 void* GetFieldDataPtr(const char*, int);
275 char* GetColName(int);
276 short GetColType(int);
277 short GetColType(const char*);
278 void* BindVar(int, void*, long);
279 void* BindVar(const char*, void*, long);
283 void SetOptions(int);
284 int GetOptions(void);
293 virtual bool Move(long rows
);
294 virtual bool MoveFirst(void);
295 virtual bool MoveLast(void);
296 virtual bool MoveNext(void);
297 virtual bool MovePrev(void);
298 virtual bool GoTo(long);
301 bool GetDataSources(void);
303 // Associate a column name/position with a data location
304 // bool BindColumn(int colPos, int dataType, void *dataPtr);
307 bool IsFieldDirty(int);
308 bool IsFieldDirty(const char*);
309 bool IsFieldNull(int);
310 bool IsFieldNull(const char*);
311 bool IsColNullable(int);
312 bool IsColNullable(const char*);
313 virtual bool Requery(void);
314 virtual void SetFieldDirty(int, bool dirty
= TRUE
);
315 virtual void SetFieldDirty(const char*, bool dirty
= TRUE
);
316 void SetFieldNull(void *p
, bool isNull
= TRUE
);
319 virtual char *GetDefaultConnect(void);
320 virtual char *GetDefaultSQL(void);
324 // Build SQL query from column specification
325 bool ConstructDefaultSQL(void);
326 void SetDefaultSQL(char *s
);
327 bool ReleaseHandle(void); // Added JACS