X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/108106cfe7af7b582fcaae8f5fe0ac05c545259d..186005466d585f5553e6acc7d963cd5b62c3ea9f:/include/wx/db.h diff --git a/include/wx/db.h b/include/wx/db.h index 9f47abf00b..466000ddde 100644 --- a/include/wx/db.h +++ b/include/wx/db.h @@ -5,6 +5,8 @@ // source such as opening and closing the data source. // Author: Doug Card // Modified by: +// Mods: Dec, 1998: Added support for SQL statement logging and database +// cataloging // Created: 9.96 // RCS-ID: $Id$ // Copyright: (c) 1996 Remstar International, Inc. @@ -18,6 +20,7 @@ // 3) These classes may not be distributed as part of any other class library, // DLL, text (written or electronic), other than a complete distribution of // the wxWindows GUI development toolkit. +// /////////////////////////////////////////////////////////////////////////////// /* @@ -27,79 +30,82 @@ #ifndef DB_DOT_H #define DB_DOT_H - + #ifdef __GNUG__ #pragma interface "db.h" #endif -#if defined(wx_msw) || defined(WIN32) +#if defined(__WXMSW__) || defined(WIN32) #include #endif + +#ifdef __WXGTK__ + +extern "C" { +#include "../../src/iodbc/isql.h" +#include "../../src/iodbc/isqlext.h" +typedef float SFLOAT; +typedef double SDOUBLE; +typedef unsigned int UINT; +#define ULONG UDWORD + +} + +#else + #define ODBCVER 0x0250 #include #include +#endif + enum enumDummy {enumDum1}; #define SQL_C_BOOLEAN (sizeof(int) == 2 ? SQL_C_USHORT : SQL_C_ULONG) #define SQL_C_ENUM (sizeof(enumDummy) == 2 ? SQL_C_USHORT : SQL_C_ULONG) //glt 2-21-97 -/* -#ifndef Bool -#define Bool int -#endif - -#ifndef TRUE -#define TRUE 1 -#endif - -#ifndef FALSE -#define FALSE 0 -#endif -*/ - // Database Globals -const DB_TYPE_NAME_LEN = 40; -const DB_MAX_STATEMENT_LEN = 2048; -const DB_MAX_WHERE_CLAUSE_LEN = 1024; -const DB_MAX_ERROR_MSG_LEN = 512; -const DB_MAX_ERROR_HISTORY = 5; -const DB_MAX_TABLE_NAME_LEN = 128; -const DB_MAX_COLUMN_NAME_LEN = 128; - -const DB_DATA_TYPE_VARCHAR = 1; -const DB_DATA_TYPE_INTEGER = 2; -const DB_DATA_TYPE_FLOAT = 3; -const DB_DATA_TYPE_DATE = 4; - -const DB_SELECT_KEYFIELDS = 1; -const DB_SELECT_WHERE = 2; -const DB_SELECT_MATCHING = 3; -const DB_SELECT_STATEMENT = 4; - -const DB_UPD_KEYFIELDS = 1; -const DB_UPD_WHERE = 2; - -const DB_DEL_KEYFIELDS = 1; -const DB_DEL_WHERE = 2; -const DB_DEL_MATCHING = 3; - -const DB_WHERE_KEYFIELDS = 1; -const DB_WHERE_MATCHING = 2; - -const DB_CURSOR0 = 0; -const DB_CURSOR1 = 1; -const DB_CURSOR2 = 2; -//const DB_CURSOR3 = 3; -//const DB_CURSOR4 = 4; -//const DB_CURSOR5 = 5; - -const DB_GRANT_SELECT = 1; -const DB_GRANT_INSERT = 2; -const DB_GRANT_UPDATE = 4; -const DB_GRANT_DELETE = 8; -const DB_GRANT_ALL = DB_GRANT_SELECT | DB_GRANT_INSERT | DB_GRANT_UPDATE | DB_GRANT_DELETE; +const int DB_TYPE_NAME_LEN = 40; +const int DB_MAX_STATEMENT_LEN = 2048; +const int DB_MAX_WHERE_CLAUSE_LEN = 1024; +const int DB_MAX_ERROR_MSG_LEN = 512; +const int DB_MAX_ERROR_HISTORY = 5; +const int DB_MAX_TABLE_NAME_LEN = 128; +const int DB_MAX_COLUMN_NAME_LEN = 128; + +const int DB_DATA_TYPE_VARCHAR = 1; +const int DB_DATA_TYPE_INTEGER = 2; +const int DB_DATA_TYPE_FLOAT = 3; +const int DB_DATA_TYPE_DATE = 4; + +const int DB_SELECT_KEYFIELDS = 1; +const int DB_SELECT_WHERE = 2; +const int DB_SELECT_MATCHING = 3; +const int DB_SELECT_STATEMENT = 4; + +const int DB_UPD_KEYFIELDS = 1; +const int DB_UPD_WHERE = 2; + +const int DB_DEL_KEYFIELDS = 1; +const int DB_DEL_WHERE = 2; +const int DB_DEL_MATCHING = 3; + +const int DB_WHERE_KEYFIELDS = 1; +const int DB_WHERE_MATCHING = 2; + +const int DB_CURSOR0 = 0; +const int DB_CURSOR1 = 1; +const int DB_CURSOR2 = 2; +//const int DB_CURSOR3 = 3; +//const int DB_CURSOR4 = 4; +//const int DB_CURSOR5 = 5; + +const int DB_GRANT_SELECT = 1; +const int DB_GRANT_INSERT = 2; +const int DB_GRANT_UPDATE = 4; +const int DB_GRANT_DELETE = 8; +const int DB_GRANT_ALL = DB_GRANT_SELECT | DB_GRANT_INSERT | DB_GRANT_UPDATE | DB_GRANT_DELETE; // ODBC Error codes (derived from ODBC SqlState codes) enum ODBC_ERRORS @@ -216,7 +222,7 @@ typedef struct short MaximumScale; } SqlTypeInfo; -class CcolInf +class WXDLLEXPORT CcolInf { public: char tableName[DB_MAX_TABLE_NAME_LEN+1]; @@ -224,15 +230,23 @@ public: int sqlDataType; }; -class wxDB +enum sqlLog +{ + sqlLogOFF, + sqlLogON +}; + +class WXDLLEXPORT wxDB { private: // Private data - bool dbIsOpen; - char *dsn; // Data source name - char *uid; // User ID - char *authStr; // Authorization string (password) + bool dbIsOpen; + char *dsn; // Data source name + char *uid; // User ID + char *authStr; // Authorization string (password) + FILE *fpSqlLog; // Sql Log file pointer + enum sqlLog sqlLogState; // On or Off // Private member functions bool getDbInfo(void); @@ -247,12 +261,12 @@ public: struct { char dbmsName[40]; // Name of the dbms product - char dbmsVer[20]; // Version # of the dbms product + char dbmsVer[40]; // Version # of the dbms product char driverName[40]; // Driver name - char odbcVer[20]; // ODBC version of the driver - char drvMgrOdbcVer[20]; // ODBC version of the driver manager - char driverVer[40]; // Driver version - char serverName[40]; // Server Name, typically a connect string + char odbcVer[60]; // ODBC version of the driver + char drvMgrOdbcVer[60]; // ODBC version of the driver manager + char driverVer[60]; // Driver version + char serverName[80]; // Server Name, typically a connect string char databaseName[128]; // Database filename char outerJoins[2]; // Indicates whether the data source supports outer joins char procedureSupport[2]; // Indicates whether the data source supports stored procedures @@ -303,28 +317,31 @@ public: // Public member functions wxDB(HENV &aHenv); - bool Open(char *Dsn, char *Uid, char *AuthStr); // Data Source Name, User ID, Password - void Close(void); - bool CommitTrans(void); - bool RollbackTrans(void); - bool DispAllErrors(HENV aHenv, HDBC aHdbc = SQL_NULL_HDBC, HSTMT aHstmt = SQL_NULL_HSTMT); - bool GetNextError(HENV aHenv, HDBC aHdbc = SQL_NULL_HDBC, HSTMT aHstmt = SQL_NULL_HSTMT); - void DispNextError(void); - bool CreateView(char *viewName, char *colList, char *pSqlStmt); - bool ExecSql(char *pSqlStmt); - bool Grant(int privileges, char *tableName, char *userList = "PUBLIC"); - int TranslateSqlState(char *SQLState); - CcolInf *GetColumns(char *tableName[]); - char *GetDatabaseName(void) {return dbInf.dbmsName;} - char *GetDataSource(void) {return dsn;} - char *GetUsername(void) {return uid;} - char *GetPassword(void) {return authStr;} - bool IsOpen(void) {return dbIsOpen;} - HENV GetHENV(void) {return henv;} - HDBC GetHDBC(void) {return hdbc;} - HSTMT GetHSTMT(void) {return hstmt;} - bool TableExists(char *tableName); // Table name can refer to a table, view, alias or synonym - void LogError(char *errMsg, char *SQLState = 0) {logError(errMsg, SQLState);} + bool Open(char *Dsn, char *Uid, char *AuthStr); // Data Source Name, User ID, Password + void Close(void); + bool CommitTrans(void); + bool RollbackTrans(void); + bool DispAllErrors(HENV aHenv, HDBC aHdbc = SQL_NULL_HDBC, HSTMT aHstmt = SQL_NULL_HSTMT); + bool GetNextError(HENV aHenv, HDBC aHdbc = SQL_NULL_HDBC, HSTMT aHstmt = SQL_NULL_HSTMT); + void DispNextError(void); + bool CreateView(char *viewName, char *colList, char *pSqlStmt); + bool ExecSql(char *pSqlStmt); + bool Grant(int privileges, char *tableName, char *userList = "PUBLIC"); + int TranslateSqlState(char *SQLState); + bool Catalog(char *userID, char *fileName = "Catalog.txt"); + CcolInf *GetColumns(char *tableName[]); + char *GetDatabaseName(void) {return dbInf.dbmsName;} + char *GetDataSource(void) {return dsn;} + char *GetUsername(void) {return uid;} + char *GetPassword(void) {return authStr;} + bool IsOpen(void) {return dbIsOpen;} + HENV GetHENV(void) {return henv;} + HDBC GetHDBC(void) {return hdbc;} + HSTMT GetHSTMT(void) {return hstmt;} + bool TableExists(char *tableName); // Table name can refer to a table, view, alias or synonym + void LogError(char *errMsg, char *SQLState = 0) {logError(errMsg, SQLState);} + bool SqlLog(enum sqlLog state, char *filename = "sqllog.txt", bool append = FALSE); + bool WriteSqlLog(char *logMsg); }; // wxDB @@ -346,17 +363,16 @@ struct DbList // for other code segments to use, or close all of them when the application has // completed. -wxDB *GetDbConnection(DbStuff *pDbStuff); -bool FreeDbConnection(wxDB *pDb); -void CloseDbConnections(void); -int NumberDbConnectionsInUse(void); +wxDB* WXDLLEXPORT GetDbConnection(DbStuff *pDbStuff); +bool WXDLLEXPORT FreeDbConnection(wxDB *pDb); +void WXDLLEXPORT CloseDbConnections(void); +int WXDLLEXPORT NumberDbConnectionsInUse(void); // This routine allows you to query a driver manager // for a list of available datasources. Call this routine // the first time using SQL_FETCH_FIRST. Continue to call it // using SQL_FETCH_NEXT until you've exhausted the list. -bool GetDataSource(HENV henv, char *Dsn, SWORD DsnMax, char *DsDesc, SWORD DsDescMax, +bool WXDLLEXPORT GetDataSource(HENV henv, char *Dsn, SWORD DsnMax, char *DsDesc, SWORD DsDescMax, UWORD direction = SQL_FETCH_NEXT); #endif -