1998-05-20 10:01:55 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: odbc.h
|
|
|
|
// Purpose: ODBC classes
|
|
|
|
// Author: Olaf Klein, Patrick Halke, Julian Smart
|
|
|
|
// Modified by:
|
|
|
|
// Created: 01/02/97
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) Julian Smart and Markus Holzem
|
1999-10-15 12:14:01 -04:00
|
|
|
// Licence: wxWindows licence
|
1998-05-20 10:01:55 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "wx/setup.h"
|
|
|
|
|
1998-09-25 09:28:52 -04:00
|
|
|
#if wxUSE_ODBC
|
1998-05-20 10:01:55 -04:00
|
|
|
|
1998-07-03 12:36:10 -04:00
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma interface "odbc.h"
|
|
|
|
#endif
|
|
|
|
|
1998-08-14 20:23:28 -04:00
|
|
|
#ifndef _WX_ODBCH__
|
|
|
|
#define _WX_ODBCH__
|
1998-05-20 10:01:55 -04:00
|
|
|
|
2000-01-20 09:16:43 -05:00
|
|
|
//#ifdef __WXMSW__
|
|
|
|
//#include <windows.h>
|
|
|
|
//#endif
|
1998-05-20 10:01:55 -04:00
|
|
|
|
1999-01-06 16:09:17 -05:00
|
|
|
|
1999-10-15 12:14:01 -04:00
|
|
|
#ifdef __UNIX__
|
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
#include "../../src/iodbc/isql.h"
|
|
|
|
#include "../../src/iodbc/isqlext.h"
|
|
|
|
#include "../../src/iodbc/odbc_funcs.h"
|
|
|
|
#include "../../src/iodbc/odbc_types.h"
|
|
|
|
|
|
|
|
typedef float SFLOAT;
|
|
|
|
typedef double SDOUBLE;
|
|
|
|
|
|
|
|
#define ULONG UDWORD
|
1998-07-18 06:15:35 -04:00
|
|
|
}
|
1999-10-15 12:14:01 -04:00
|
|
|
#else // !Unix
|
|
|
|
#include <sqlext.h>
|
|
|
|
#endif // Unix/!Unix
|
1998-05-20 10:01:55 -04:00
|
|
|
|
|
|
|
#include "wx/defs.h"
|
|
|
|
#include "wx/list.h"
|
|
|
|
#include "wx/string.h"
|
|
|
|
|
|
|
|
typedef RETCODE wxRETCODE;
|
|
|
|
|
|
|
|
// Recordset open types
|
|
|
|
#define wxOPEN_TYPE_DYNASET 1
|
|
|
|
#define wxOPEN_TYPE_SNAPSHOT 2
|
|
|
|
#define wxOPEN_TYPE_FORWARD_ONLY 3
|
|
|
|
|
|
|
|
// Recordset open options
|
|
|
|
#define wxOPTION_DEFAULT 1
|
|
|
|
#define wxOPTION_APPEND_ONLY 2
|
|
|
|
#define wxOPTION_READ_ONLY 3
|
|
|
|
|
|
|
|
// Data types
|
|
|
|
class WXDLLEXPORT wxRecordSet;
|
|
|
|
|
|
|
|
class WXDLLEXPORT wxDatabase: public wxObject
|
|
|
|
{
|
|
|
|
DECLARE_DYNAMIC_CLASS(wxDatabase)
|
|
|
|
protected:
|
|
|
|
static HENV hEnv;
|
|
|
|
static int refCount;
|
1999-10-15 12:14:01 -04:00
|
|
|
|
1998-05-20 10:01:55 -04:00
|
|
|
HDBC hDBC;
|
|
|
|
char* username;
|
|
|
|
char* password;
|
|
|
|
char* datasource;
|
|
|
|
char* dbname;
|
|
|
|
char* connectstring;
|
|
|
|
bool isOpen;
|
|
|
|
|
|
|
|
// error-handling variables
|
|
|
|
wxRETCODE retcode;
|
|
|
|
char sqlstate[SQL_SQLSTATE_SIZE+1]; // error class and subclass
|
|
|
|
char errmsg[SQL_MAX_MESSAGE_LENGTH]; // error message
|
|
|
|
long nat_err; // error number by ODBC driver
|
|
|
|
bool err_occured;
|
|
|
|
|
|
|
|
wxList recordSets; // Record sets: Added by JACS
|
1999-10-15 12:14:01 -04:00
|
|
|
|
1998-05-20 10:01:55 -04:00
|
|
|
public:
|
1999-10-15 12:14:01 -04:00
|
|
|
wxDatabase();
|
|
|
|
~wxDatabase();
|
|
|
|
|
1998-05-20 10:01:55 -04:00
|
|
|
bool Open(char *, bool exclusive =FALSE, bool readOnly =TRUE, char *username ="ODBC", char *password ="");
|
1999-10-15 12:14:01 -04:00
|
|
|
bool Close();
|
1998-05-20 10:01:55 -04:00
|
|
|
|
|
|
|
// Cleanup operations, added by JACS
|
|
|
|
void DeleteRecordSets(void); // Called when the database is deleted
|
|
|
|
void ResetRecordSets(void); // Required if the database is closed
|
|
|
|
inline wxList& GetRecordSets(void) { return recordSets; }
|
1999-10-15 12:14:01 -04:00
|
|
|
|
1998-05-20 10:01:55 -04:00
|
|
|
inline char *GetUsername(void) { return username; }
|
|
|
|
inline char *GetPassword(void) { return password; }
|
|
|
|
inline char *GetDataSource(void) { return datasource; }
|
|
|
|
inline bool IsOpen(void) { return isOpen; }
|
|
|
|
inline wxRETCODE GetErrorCode(void) { return retcode; }
|
|
|
|
inline HDBC GetHDBC(void) { return hDBC; }
|
|
|
|
inline HENV GetHENV(void) { return hEnv; }
|
1999-10-15 12:14:01 -04:00
|
|
|
|
1998-05-20 10:01:55 -04:00
|
|
|
void SetPassword(char *s);
|
|
|
|
void SetUsername(char *s);
|
|
|
|
void SetDataSource(char *s);
|
1999-10-15 12:14:01 -04:00
|
|
|
|
1998-05-20 10:01:55 -04:00
|
|
|
// Database attributes
|
1999-10-15 12:14:01 -04:00
|
|
|
char *GetDatabaseName();
|
|
|
|
bool CanUpdate();
|
|
|
|
bool CanTransact();
|
|
|
|
bool InWaitForDataSource();
|
1998-05-20 10:01:55 -04:00
|
|
|
void SetLoginTimeout(long seconds);
|
|
|
|
void SetQueryTimeout(long seconds);
|
|
|
|
void SetSynchronousMode(bool synchronous);
|
|
|
|
|
|
|
|
// Database operations
|
1999-10-15 12:14:01 -04:00
|
|
|
bool BeginTrans();
|
|
|
|
bool CommitTrans();
|
|
|
|
bool RollbackTrans();
|
|
|
|
void Cancel();
|
1998-05-20 10:01:55 -04:00
|
|
|
|
|
|
|
// Error handling
|
1999-10-15 12:14:01 -04:00
|
|
|
bool ErrorOccured();
|
|
|
|
char* GetErrorMessage();
|
|
|
|
long GetErrorNumber();
|
|
|
|
char* GetErrorClass();
|
1998-05-20 10:01:55 -04:00
|
|
|
inline void ErrorSnapshot(HSTMT =SQL_NULL_HSTMT);
|
|
|
|
|
|
|
|
// Overridables
|
|
|
|
virtual void OnSetOptions(wxRecordSet *recordSet);
|
|
|
|
virtual void OnWaitForDataSource(bool stillExecuting);
|
|
|
|
|
|
|
|
bool GetInfo(long infoType, long *buf);
|
|
|
|
bool GetInfo(long infoType, char *buf, int bufSize = -1);
|
|
|
|
|
|
|
|
// implementation = TRUE means get the DLL version.
|
|
|
|
// Otherwise, returns header file version.
|
|
|
|
wxString GetODBCVersionString(bool implementation = TRUE);
|
|
|
|
float GetODBCVersionFloat(bool implementation = TRUE);
|
|
|
|
};
|
|
|
|
|
|
|
|
// Represents a data row
|
|
|
|
class WXDLLEXPORT wxQueryField: public wxObject
|
|
|
|
{
|
|
|
|
// JACS
|
|
|
|
DECLARE_DYNAMIC_CLASS(wxQueryField)
|
|
|
|
private:
|
|
|
|
void *data;
|
|
|
|
short type;
|
|
|
|
long size;
|
|
|
|
bool dirty;
|
|
|
|
|
1999-10-15 12:14:01 -04:00
|
|
|
bool AllocData();
|
1998-05-20 10:01:55 -04:00
|
|
|
|
|
|
|
public:
|
1999-10-15 12:14:01 -04:00
|
|
|
wxQueryField();
|
|
|
|
~wxQueryField();
|
|
|
|
|
1998-05-20 10:01:55 -04:00
|
|
|
bool SetData(void*, long);
|
|
|
|
void SetDirty(bool =TRUE);
|
1999-10-15 12:14:01 -04:00
|
|
|
void ClearData();
|
1998-05-20 10:01:55 -04:00
|
|
|
void SetType(short);
|
|
|
|
void SetSize(long);
|
1999-10-15 12:14:01 -04:00
|
|
|
|
|
|
|
void* GetData();
|
|
|
|
short GetType();
|
|
|
|
long GetSize();
|
|
|
|
|
|
|
|
bool IsDirty();
|
1998-05-20 10:01:55 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
// Represents a column description
|
|
|
|
class WXDLLEXPORT wxQueryCol: public wxObject
|
|
|
|
{
|
|
|
|
// JACS
|
|
|
|
DECLARE_DYNAMIC_CLASS(wxQueryCol)
|
|
|
|
private:
|
|
|
|
short type;
|
|
|
|
char *name;
|
|
|
|
bool nullable;
|
|
|
|
long varsize;
|
|
|
|
void* var;
|
1999-10-15 12:14:01 -04:00
|
|
|
|
1998-05-20 10:01:55 -04:00
|
|
|
public:
|
|
|
|
wxList fields;
|
1999-10-15 12:14:01 -04:00
|
|
|
|
|
|
|
wxQueryCol();
|
|
|
|
~wxQueryCol();
|
|
|
|
|
1998-05-20 10:01:55 -04:00
|
|
|
void* BindVar(void*, long);
|
|
|
|
void FillVar(int);
|
|
|
|
void AppendField(void*, long);
|
|
|
|
bool SetData(int, void*, long);
|
|
|
|
void SetName(char*);
|
|
|
|
void SetNullable(bool);
|
|
|
|
void SetFieldDirty(int, bool =TRUE);
|
|
|
|
void SetType(short);
|
1999-10-15 12:14:01 -04:00
|
|
|
|
|
|
|
char* GetName();
|
|
|
|
short GetType();
|
|
|
|
bool IsNullable();
|
1998-05-20 10:01:55 -04:00
|
|
|
void* GetData(int);
|
|
|
|
long GetSize(int);
|
|
|
|
|
|
|
|
bool IsFieldDirty(int);
|
|
|
|
};
|
|
|
|
|
|
|
|
class WXDLLEXPORT wxRecordSet: public wxObject
|
|
|
|
{
|
|
|
|
// JACS
|
|
|
|
DECLARE_DYNAMIC_CLASS(wxRecordSet)
|
|
|
|
private:
|
|
|
|
int cursor;
|
|
|
|
int type;
|
|
|
|
int options;
|
1999-10-15 12:14:01 -04:00
|
|
|
|
1998-05-20 10:01:55 -04:00
|
|
|
protected:
|
|
|
|
HSTMT hStmt;
|
|
|
|
int nFields;
|
|
|
|
int nParams;
|
|
|
|
int nRecords;
|
|
|
|
short nCols;
|
|
|
|
char *recordFilter;
|
|
|
|
char *sortString;
|
|
|
|
char *defaultSQL;
|
|
|
|
char* tablename;
|
|
|
|
wxDatabase *parentdb;
|
|
|
|
wxRETCODE retcode;
|
|
|
|
wxList cols;
|
|
|
|
wxList fetchbuf;
|
1999-10-15 12:14:01 -04:00
|
|
|
|
1998-05-20 10:01:55 -04:00
|
|
|
void FillVars(int);
|
|
|
|
|
|
|
|
public:
|
|
|
|
// JACS gave parent a default value for benefit of IMPLEMENT_DYNAMIC_CLASS
|
1999-10-15 12:14:01 -04:00
|
|
|
wxRecordSet(wxDatabase *parent = NULL,
|
|
|
|
int = wxOPEN_TYPE_DYNASET,
|
|
|
|
int = wxOPTION_DEFAULT);
|
|
|
|
~wxRecordSet();
|
|
|
|
|
1998-05-20 10:01:55 -04:00
|
|
|
// My own, lower-level functions.
|
|
|
|
bool BeginQuery(int openType, char *sql = NULL, int options = wxOPTION_DEFAULT);
|
1999-10-15 12:14:01 -04:00
|
|
|
bool EndQuery();
|
1998-05-20 10:01:55 -04:00
|
|
|
bool Query(char* columns, char* table =NULL, char *filter =NULL);
|
|
|
|
|
|
|
|
// Attributes
|
|
|
|
inline int GetNumberFields(void) { return nFields; }
|
|
|
|
inline int GetNumberParams(void) { return nParams; }
|
1999-10-15 12:14:01 -04:00
|
|
|
long GetNumberRecords();
|
|
|
|
long GetNumberCols();
|
1998-05-20 10:01:55 -04:00
|
|
|
inline char *GetFilter(void) { return recordFilter; }
|
|
|
|
inline char *GetSortString(void) { return sortString; }
|
|
|
|
inline wxDatabase *GetDatabase(void) { return parentdb; }
|
|
|
|
inline wxRETCODE GetErrorCode(void) { return retcode; }
|
1999-10-15 12:14:01 -04:00
|
|
|
bool CanAppend();
|
|
|
|
bool CanRestart();
|
|
|
|
bool CanScroll();
|
|
|
|
bool CanTransact();
|
|
|
|
bool CanUpdate();
|
|
|
|
long GetCurrentRecord();
|
|
|
|
bool RecordCountFinal();
|
|
|
|
bool GetResultSet();
|
1998-05-20 10:01:55 -04:00
|
|
|
bool ExecuteSQL(char*);
|
1999-10-15 12:14:01 -04:00
|
|
|
bool GetTables();
|
1998-05-20 10:01:55 -04:00
|
|
|
bool GetColumns(char* =NULL);
|
|
|
|
bool GetPrimaryKeys(char* =NULL);
|
|
|
|
bool GetForeignKeys(char* , char * );
|
1999-10-15 12:14:01 -04:00
|
|
|
char *GetTableName();
|
1998-05-20 10:01:55 -04:00
|
|
|
void SetTableName(char*);
|
1999-10-15 12:14:01 -04:00
|
|
|
char *GetSQL();
|
|
|
|
bool IsOpen();
|
|
|
|
bool IsBOF();
|
|
|
|
bool IsEOF();
|
|
|
|
bool IsDeleted();
|
1998-05-20 10:01:55 -04:00
|
|
|
|
|
|
|
bool GetFieldData(int colPos, int dataType, void *dataPtr);
|
|
|
|
bool GetFieldData(const char*, int dataType, void *dataPtr);
|
|
|
|
void* GetFieldDataPtr(int, int);
|
|
|
|
void* GetFieldDataPtr(const char*, int);
|
|
|
|
char* GetColName(int);
|
|
|
|
short GetColType(int);
|
|
|
|
short GetColType(const char*);
|
|
|
|
void* BindVar(int, void*, long);
|
|
|
|
void* BindVar(const char*, void*, long);
|
|
|
|
|
|
|
|
void SetType(int);
|
1999-10-15 12:14:01 -04:00
|
|
|
int GetType();
|
1998-05-20 10:01:55 -04:00
|
|
|
void SetOptions(int);
|
1999-10-15 12:14:01 -04:00
|
|
|
int GetOptions();
|
|
|
|
|
1998-05-20 10:01:55 -04:00
|
|
|
// Update operations
|
1999-10-15 12:14:01 -04:00
|
|
|
void AddNew();
|
|
|
|
bool Delete();
|
|
|
|
void Edit();
|
|
|
|
bool Update();
|
1998-05-20 10:01:55 -04:00
|
|
|
|
|
|
|
// Record navigation
|
|
|
|
virtual bool Move(long rows);
|
1999-10-15 12:14:01 -04:00
|
|
|
virtual bool MoveFirst();
|
|
|
|
virtual bool MoveLast();
|
|
|
|
virtual bool MoveNext();
|
|
|
|
virtual bool MovePrev();
|
1998-05-20 10:01:55 -04:00
|
|
|
virtual bool GoTo(long);
|
|
|
|
|
|
|
|
// Others
|
1999-10-15 12:14:01 -04:00
|
|
|
bool GetDataSources();
|
1998-05-20 10:01:55 -04:00
|
|
|
|
|
|
|
// Associate a column name/position with a data location
|
|
|
|
// bool BindColumn(int colPos, int dataType, void *dataPtr);
|
|
|
|
|
1999-10-15 12:14:01 -04:00
|
|
|
void Cancel();
|
1998-05-20 10:01:55 -04:00
|
|
|
bool IsFieldDirty(int);
|
|
|
|
bool IsFieldDirty(const char*);
|
|
|
|
bool IsFieldNull(int);
|
|
|
|
bool IsFieldNull(const char*);
|
|
|
|
bool IsColNullable(int);
|
|
|
|
bool IsColNullable(const char*);
|
1999-10-15 12:14:01 -04:00
|
|
|
virtual bool Requery();
|
1998-05-20 10:01:55 -04:00
|
|
|
virtual void SetFieldDirty(int, bool dirty = TRUE);
|
|
|
|
virtual void SetFieldDirty(const char*, bool dirty = TRUE);
|
|
|
|
void SetFieldNull(void *p, bool isNull = TRUE);
|
|
|
|
|
|
|
|
// Overridables
|
1999-10-15 12:14:01 -04:00
|
|
|
virtual char *GetDefaultConnect();
|
|
|
|
virtual char *GetDefaultSQL();
|
|
|
|
|
1998-05-20 10:01:55 -04:00
|
|
|
// Internal
|
1999-10-15 12:14:01 -04:00
|
|
|
|
1998-05-20 10:01:55 -04:00
|
|
|
// Build SQL query from column specification
|
1999-10-15 12:14:01 -04:00
|
|
|
bool ConstructDefaultSQL();
|
1998-05-20 10:01:55 -04:00
|
|
|
void SetDefaultSQL(char *s);
|
|
|
|
bool ReleaseHandle(void); // Added JACS
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
1998-09-25 09:28:52 -04:00
|
|
|
#endif // wxUSE_ODBC
|