+ wxChar catalog[128+1];
+ wxChar schema[128+1];
+ int numTables; // How many tables does this database have
+ wxDbTableInf *pTableInf; // pTableInf = new wxDbTableInf[numTables];
+
+ wxDbInf();
+ ~wxDbInf();
+
+ bool Initialize();
+};
+
+
+enum wxDbSqlLogState
+{
+ sqlLogOFF,
+ sqlLogON
+};
+
+// These are the databases currently tested and working with these classes
+// See the comments in wxDb::Dbms() for exceptions/issues with
+// each of these database engines
+enum wxDBMS
+{
+ dbmsUNIDENTIFIED,
+ dbmsORACLE,
+ dbmsSYBASE_ASA, // Adaptive Server Anywhere
+ dbmsSYBASE_ASE, // Adaptive Server Enterprise
+ dbmsMS_SQL_SERVER,
+ dbmsMY_SQL,
+ dbmsPOSTGRES,
+ dbmsACCESS,
+ dbmsDBASE,
+ dbmsINFORMIX,
+ dbmsVIRTUOSO,
+ dbmsDB2,
+ dbmsINTERBASE,
+ dbmsPERVASIVE_SQL,
+ dbmsXBASE_SEQUITER,
+ dbmsFIREBIRD,
+ dbmsMAXDB,
+ dbmsFuture1,
+ dbmsFuture2,
+ dbmsFuture3,
+ dbmsFuture4,
+ dbmsFuture5,
+ dbmsFuture6,
+ dbmsFuture7,
+ dbmsFuture8,
+ dbmsFuture9,
+ dbmsFuture10
+};
+
+
+// The wxDb::errorList is copied to this variable when the wxDb object
+// is closed. This way, the error list is still available after the
+// database object is closed. This is necessary if the database
+// connection fails so the calling application can show the operator
+// why the connection failed. Note: as each wxDb object is closed, it
+// will overwrite the errors of the previously destroyed wxDb object in
+// this variable.
+
+extern WXDLLIMPEXP_DATA_ODBC(wxChar)
+ DBerrorList[DB_MAX_ERROR_HISTORY][DB_MAX_ERROR_MSG_LEN+1];
+
+
+class WXDLLIMPEXP_ODBC wxDb
+{
+private:
+ bool dbIsOpen;
+ bool dbIsCached; // Was connection created by caching functions
+ bool dbOpenedWithConnectionString; // Was the database connection opened with a connection string
+ wxString dsn; // Data source name
+ wxString uid; // User ID
+ wxString authStr; // Authorization string (password)
+ wxString inConnectionStr; // Connection string used to connect to the database
+ wxString outConnectionStr;// Connection string returned by the database when a connection is successfully opened
+ FILE *fpSqlLog; // Sql Log file pointer
+ wxDbSqlLogState sqlLogState; // On or Off
+ bool fwdOnlyCursors;
+ wxDBMS dbmsType; // Type of datasource - i.e. Oracle, dBase, SQLServer, etc
+
+ // Private member functions
+ bool getDbInfo(bool failOnDataTypeUnsupported=true);
+ bool getDataTypeInfo(SWORD fSqlType, wxDbSqlTypeInfo &structSQLTypeInfo);
+ bool setConnectionOptions(void);
+ void logError(const wxString &errMsg, const wxString &SQLState);
+ const wxChar *convertUserID(const wxChar *userID, wxString &UserID);
+ bool determineDataTypes(bool failOnDataTypeUnsupported);
+ void initialize();
+ bool open(bool failOnDataTypeUnsupported=true);
+
+#if !wxODBC_BACKWARD_COMPATABILITY
+ // ODBC handles
+ HENV henv; // ODBC Environment handle
+ HDBC hdbc; // ODBC DB Connection handle
+ HSTMT hstmt; // ODBC Statement handle
+
+ //Error reporting mode
+ bool silent;
+
+ // Number of Ctable objects connected to this db object. FOR INTERNAL USE ONLY!!!
+ unsigned int nTables;
+
+ // Information about logical data types VARCHAR, INTEGER, FLOAT and DATE.
+ //
+ // This information is obtained from the ODBC driver by use of the
+ // SQLGetTypeInfo() function. The key piece of information is the
+ // type name the data source uses for each logical data type.
+ // e.g. VARCHAR; Oracle calls it VARCHAR2.
+ wxDbSqlTypeInfo typeInfVarchar;
+ wxDbSqlTypeInfo typeInfInteger;
+ wxDbSqlTypeInfo typeInfFloat;
+ wxDbSqlTypeInfo typeInfDate;
+ wxDbSqlTypeInfo typeInfBlob;
+#endif
+
+public:
+
+ void setCached(bool cached) { dbIsCached = cached; }; // This function must only be called by wxDbGetConnection() and wxDbCloseConnections!!!
+ bool IsCached() { return dbIsCached; };
+
+ bool GetDataTypeInfo(SWORD fSqlType, wxDbSqlTypeInfo &structSQLTypeInfo)
+ { return getDataTypeInfo(fSqlType, structSQLTypeInfo); }
+
+#if wxODBC_BACKWARD_COMPATABILITY
+ // ODBC handles
+ HENV henv; // ODBC Environment handle
+ HDBC hdbc; // ODBC DB Connection handle
+ HSTMT hstmt; // ODBC Statement handle
+
+ //Error reporting mode
+ bool silent;
+
+ // Number of Ctable objects connected to this db object. FOR INTERNAL USE ONLY!!!
+ unsigned int nTables;
+#endif
+
+ // The following structure contains database information gathered from the
+ // datasource when the datasource is first opened.
+ struct
+ {
+ wxChar dbmsName[40]; // Name of the dbms product
+ wxChar dbmsVer[64]; // Version # of the dbms product
+ wxChar driverName[40]; // Driver name
+ wxChar odbcVer[60]; // ODBC version of the driver
+ wxChar drvMgrOdbcVer[60]; // ODBC version of the driver manager
+ wxChar driverVer[60]; // Driver version
+ wxChar serverName[80]; // Server Name, typically a connect string
+ wxChar databaseName[128]; // Database filename
+ wxChar outerJoins[2]; // Indicates whether the data source supports outer joins
+ wxChar procedureSupport[2]; // Indicates whether the data source supports stored procedures
+ wxChar accessibleTables[2]; // Indicates whether the data source only reports accessible tables in SQLTables.
+ UWORD maxConnections; // Maximum # of connections the data source supports
+ UWORD maxStmts; // Maximum # of HSTMTs per HDBC
+ UWORD apiConfLvl; // ODBC API conformance level
+ UWORD cliConfLvl; // Indicates whether the data source is SAG compliant
+ UWORD sqlConfLvl; // SQL conformance level
+ UWORD cursorCommitBehavior; // Indicates how cursors are affected by a db commit
+ UWORD cursorRollbackBehavior; // Indicates how cursors are affected by a db rollback
+ UWORD supportNotNullClause; // Indicates if data source supports NOT NULL clause
+ wxChar supportIEF[2]; // Integrity Enhancement Facility (Referential Integrity)
+ UDWORD txnIsolation; // Default transaction isolation level supported by the driver
+ UDWORD txnIsolationOptions; // Transaction isolation level options available
+ UDWORD fetchDirections; // Fetch directions supported
+ UDWORD lockTypes; // Lock types supported in SQLSetPos
+ UDWORD posOperations; // Position operations supported in SQLSetPos
+ UDWORD posStmts; // Position statements supported
+ UDWORD scrollConcurrency; // Concurrency control options supported for scrollable cursors
+ UDWORD scrollOptions; // Scroll Options supported for scrollable cursors
+ UDWORD staticSensitivity; // Indicates if additions, deletions and updates can be detected
+ UWORD txnCapable; // Indicates if the data source supports transactions
+ UDWORD loginTimeout; // Number seconds to wait for a login request
+ } dbInf;
+
+ // ODBC Error Inf.
+ SWORD cbErrorMsg;
+ int DB_STATUS;
+#ifdef __VMS
+ // The DECC compiler chokes when in db.cpp the array is accessed outside
+ // its bounds. Maybe this change should also applied for other platforms.
+ wxChar errorList[DB_MAX_ERROR_HISTORY][DB_MAX_ERROR_MSG_LEN+1];
+#else
+ wxChar errorList[DB_MAX_ERROR_HISTORY][DB_MAX_ERROR_MSG_LEN];
+#endif
+ wxChar errorMsg[SQL_MAX_MESSAGE_LENGTH];
+ SQLINTEGER nativeError;
+ wxChar sqlState[20];
+
+#if wxODBC_BACKWARD_COMPATABILITY
+ // Information about logical data types VARCHAR, INTEGER, FLOAT and DATE.
+ //
+ // This information is obtained from the ODBC driver by use of the
+ // SQLGetTypeInfo() function. The key piece of information is the
+ // type name the data source uses for each logical data type.
+ // e.g. VARCHAR; Oracle calls it VARCHAR2.
+ wxDbSqlTypeInfo typeInfVarchar;
+ wxDbSqlTypeInfo typeInfInteger;
+ wxDbSqlTypeInfo typeInfFloat;
+ wxDbSqlTypeInfo typeInfDate;
+ wxDbSqlTypeInfo typeInfBlob;
+#endif
+
+ // Public member functions
+ wxDb(const HENV &aHenv, bool FwdOnlyCursors=(bool)wxODBC_FWD_ONLY_CURSORS);
+ ~wxDb();
+
+ // Data Source Name, User ID, Password and whether open should fail on data type not supported
+ bool Open(const wxString& inConnectStr, bool failOnDataTypeUnsupported=true);
+ ///This version of Open will open the odbc source selection dialog. Cast a wxWindow::GetHandle() to SQLHWND to use.
+ bool Open(const wxString& inConnectStr, SQLHWND parentWnd, bool failOnDataTypeUnsupported=true);
+ bool Open(const wxString &Dsn, const wxString &Uid, const wxString &AuthStr, bool failOnDataTypeUnsupported=true);
+ bool Open(wxDbConnectInf *dbConnectInf, bool failOnDataTypeUnsupported=true);
+ bool Open(wxDb *copyDb); // pointer to a wxDb whose connection info should be copied rather than re-queried
+ 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(const wxString &viewName, const wxString &colList, const wxString &pSqlStmt, bool attemptDrop=true);
+ bool DropView(const wxString &viewName);
+ bool ExecSql(const wxString &pSqlStmt);
+ bool ExecSql(const wxString &pSqlStmt, wxDbColInf** columns, short& numcols);
+ bool GetNext(void);
+ bool GetData(UWORD colNo, SWORD cType, PTR pData, SDWORD maxLen, SDWORD FAR *cbReturned);
+ bool Grant(int privileges, const wxString &tableName, const wxString &userList = wxT("PUBLIC"));
+ int TranslateSqlState(const wxString &SQLState);
+ wxDbInf *GetCatalog(const wxChar *userID=NULL);
+ bool Catalog(const wxChar *userID=NULL, const wxString &fileName=SQL_CATALOG_FILENAME);
+ int GetKeyFields(const wxString &tableName, wxDbColInf* colInf, UWORD noCols);
+
+ wxDbColInf *GetColumns(wxChar *tableName[], const wxChar *userID=NULL);
+ wxDbColInf *GetColumns(const wxString &tableName, UWORD *numCols, const wxChar *userID=NULL);
+
+ int GetColumnCount(const wxString &tableName, const wxChar *userID=NULL);
+ const wxChar *GetDatabaseName(void) {return dbInf.dbmsName;}
+ const wxString &GetDataSource(void) {return dsn;}
+ const wxString &GetDatasourceName(void){return dsn;}
+ const wxString &GetUsername(void) {return uid;}
+ const wxString &GetPassword(void) {return authStr;}
+ const wxString &GetConnectionInStr(void) {return inConnectionStr;}
+ const wxString &GetConnectionOutStr(void) {return outConnectionStr;}
+ bool IsOpen(void) {return dbIsOpen;}
+ bool OpenedWithConnectionString(void) {return dbOpenedWithConnectionString;}
+ HENV GetHENV(void) {return henv;}
+ HDBC GetHDBC(void) {return hdbc;}
+ HSTMT GetHSTMT(void) {return hstmt;}
+ int GetTableCount() {return nTables;} // number of tables using this connection
+ wxDbSqlTypeInfo GetTypeInfVarchar() {return typeInfVarchar;}
+ wxDbSqlTypeInfo GetTypeInfInteger() {return typeInfInteger;}
+ wxDbSqlTypeInfo GetTypeInfFloat() {return typeInfFloat;}
+ wxDbSqlTypeInfo GetTypeInfDate() {return typeInfDate;}
+ wxDbSqlTypeInfo GetTypeInfBlob() {return typeInfBlob;}
+
+ // tableName can refer to a table, view, alias or synonym
+ bool TableExists(const wxString &tableName, const wxChar *userID=NULL,
+ const wxString &tablePath=wxEmptyString);
+ bool TablePrivileges(const wxString &tableName, const wxString &priv,
+ const wxChar *userID=NULL, const wxChar *schema=NULL,
+ const wxString &path=wxEmptyString);
+
+ // These two functions return the table name or column name in a form ready
+ // for use in SQL statements. For example, if the datasource allows spaces
+ // in the table name or column name, the returned string will have the
+ // correct enclosing marks around the name to allow it to be properly
+ // included in a SQL statement
+ const wxString SQLTableName(const wxChar *tableName);
+ const wxString SQLColumnName(const wxChar *colName);
+
+ void LogError(const wxString &errMsg, const wxString &SQLState = wxEmptyString)
+ { logError(errMsg, SQLState); }
+ void SetDebugErrorMessages(bool state) { silent = !state; }
+ bool SetSqlLogging(wxDbSqlLogState state, const wxString &filename = SQL_LOG_FILENAME,
+ bool append = false);
+ bool WriteSqlLog(const wxString &logMsg);
+
+ wxDBMS Dbms(void);
+ bool ModifyColumn(const wxString &tableName, const wxString &columnName,
+ int dataType, ULONG columnLength=0,
+ const wxString &optionalParam=wxEmptyString);
+
+ bool FwdOnlyCursors(void) {return fwdOnlyCursors;}
+
+ // These two functions are provided strictly for use by wxDbTable.
+ // DO NOT USE THESE FUNCTIONS, OR MEMORY LEAKS MAY OCCUR
+ void incrementTableCount() { nTables++; return; }
+ void decrementTableCount() { nTables--; return; }
+
+}; // wxDb