]>
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 "../../src/iodbc/isql.h"
32 #include "../../src/iodbc/isqlext.h"
33 #include "../../src/iodbc/odbc_funcs.h"
34 #include "../../src/iodbc/odbc_types.h"
37 typedef double SDOUBLE
;
47 #include "wx/string.h"
49 typedef RETCODE wxRETCODE
;
51 // Recordset open types
52 #define wxOPEN_TYPE_DYNASET 1
53 #define wxOPEN_TYPE_SNAPSHOT 2
54 #define wxOPEN_TYPE_FORWARD_ONLY 3
56 // Recordset open options
57 #define wxOPTION_DEFAULT 1
58 #define wxOPTION_APPEND_ONLY 2
59 #define wxOPTION_READ_ONLY 3
62 class WXDLLEXPORT wxRecordSet
;
64 class WXDLLEXPORT wxDatabase
: public wxObject
66 DECLARE_DYNAMIC_CLASS(wxDatabase
)
79 // error-handling variables
81 char sqlstate
[SQL_SQLSTATE_SIZE
+1]; // error class and subclass
82 char errmsg
[SQL_MAX_MESSAGE_LENGTH
]; // error message
83 long nat_err
; // error number by ODBC driver
86 wxList recordSets
; // Record sets: Added by JACS
92 bool Open(char *, bool exclusive
=FALSE
, bool readOnly
=TRUE
, char *username
="ODBC", char *password
="");
95 // Cleanup operations, added by JACS
96 void DeleteRecordSets(void); // Called when the database is deleted
97 void ResetRecordSets(void); // Required if the database is closed
98 inline wxList
& GetRecordSets(void) { return recordSets
; }
100 inline char *GetUsername(void) { return username
; }
101 inline char *GetPassword(void) { return password
; }
102 inline char *GetDataSource(void) { return datasource
; }
103 inline bool IsOpen(void) { return isOpen
; }
104 inline wxRETCODE
GetErrorCode(void) { return retcode
; }
105 inline HDBC
GetHDBC(void) { return hDBC
; }
106 inline HENV
GetHENV(void) { return hEnv
; }
108 void SetPassword(char *s
);
109 void SetUsername(char *s
);
110 void SetDataSource(char *s
);
112 // Database attributes
113 char *GetDatabaseName();
116 bool InWaitForDataSource();
117 void SetLoginTimeout(long seconds
);
118 void SetQueryTimeout(long seconds
);
119 void SetSynchronousMode(bool synchronous
);
121 // Database operations
124 bool RollbackTrans();
129 char* GetErrorMessage();
130 long GetErrorNumber();
131 char* GetErrorClass();
132 inline void ErrorSnapshot(HSTMT
=SQL_NULL_HSTMT
);
135 virtual void OnSetOptions(wxRecordSet
*recordSet
);
136 virtual void OnWaitForDataSource(bool stillExecuting
);
138 bool GetInfo(long infoType
, long *buf
);
139 bool GetInfo(long infoType
, char *buf
, int bufSize
= -1);
141 // implementation = TRUE means get the DLL version.
142 // Otherwise, returns header file version.
143 wxString
GetODBCVersionString(bool implementation
= TRUE
);
144 float GetODBCVersionFloat(bool implementation
= TRUE
);
147 // Represents a data row
148 class WXDLLEXPORT wxQueryField
: public wxObject
151 DECLARE_DYNAMIC_CLASS(wxQueryField
)
164 bool SetData(void*, long);
165 void SetDirty(bool =TRUE
);
177 // Represents a column description
178 class WXDLLEXPORT wxQueryCol
: public wxObject
181 DECLARE_DYNAMIC_CLASS(wxQueryCol
)
195 void* BindVar(void*, long);
197 void AppendField(void*, long);
198 bool SetData(int, void*, long);
200 void SetNullable(bool);
201 void SetFieldDirty(int, bool =TRUE
);
210 bool IsFieldDirty(int);
213 class WXDLLEXPORT wxRecordSet
: public wxObject
216 DECLARE_DYNAMIC_CLASS(wxRecordSet
)
232 wxDatabase
*parentdb
;
240 // JACS gave parent a default value for benefit of IMPLEMENT_DYNAMIC_CLASS
241 wxRecordSet(wxDatabase
*parent
= NULL
,
242 int = wxOPEN_TYPE_DYNASET
,
243 int = wxOPTION_DEFAULT
);
246 // My own, lower-level functions.
247 bool BeginQuery(int openType
, char *sql
= NULL
, int options
= wxOPTION_DEFAULT
);
249 bool Query(char* columns
, char* table
=NULL
, char *filter
=NULL
);
252 inline int GetNumberFields(void) { return nFields
; }
253 inline int GetNumberParams(void) { return nParams
; }
254 long GetNumberRecords();
255 long GetNumberCols();
256 inline char *GetFilter(void) { return recordFilter
; }
257 inline char *GetSortString(void) { return sortString
; }
258 inline wxDatabase
*GetDatabase(void) { return parentdb
; }
259 inline wxRETCODE
GetErrorCode(void) { return retcode
; }
265 long GetCurrentRecord();
266 bool RecordCountFinal();
268 bool ExecuteSQL(char*);
270 bool GetColumns(char* =NULL
);
271 bool GetPrimaryKeys(char* =NULL
);
272 bool GetForeignKeys(char* , char * );
273 char *GetTableName();
274 void SetTableName(char*);
281 bool GetFieldData(int colPos
, int dataType
, void *dataPtr
);
282 bool GetFieldData(const char*, int dataType
, void *dataPtr
);
283 void* GetFieldDataPtr(int, int);
284 void* GetFieldDataPtr(const char*, int);
285 char* GetColName(int);
286 short GetColType(int);
287 short GetColType(const char*);
288 void* BindVar(int, void*, long);
289 void* BindVar(const char*, void*, long);
293 void SetOptions(int);
303 virtual bool Move(long rows
);
304 virtual bool MoveFirst();
305 virtual bool MoveLast();
306 virtual bool MoveNext();
307 virtual bool MovePrev();
308 virtual bool GoTo(long);
311 bool GetDataSources();
313 // Associate a column name/position with a data location
314 // bool BindColumn(int colPos, int dataType, void *dataPtr);
317 bool IsFieldDirty(int);
318 bool IsFieldDirty(const char*);
319 bool IsFieldNull(int);
320 bool IsFieldNull(const char*);
321 bool IsColNullable(int);
322 bool IsColNullable(const char*);
323 virtual bool Requery();
324 virtual void SetFieldDirty(int, bool dirty
= TRUE
);
325 virtual void SetFieldDirty(const char*, bool dirty
= TRUE
);
326 void SetFieldNull(void *p
, bool isNull
= TRUE
);
329 virtual char *GetDefaultConnect();
330 virtual char *GetDefaultSQL();
334 // Build SQL query from column specification
335 bool ConstructDefaultSQL();
336 void SetDefaultSQL(char *s
);
337 bool ReleaseHandle(void); // Added JACS