⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 db.h

📁 浙江大学的悟空嵌入式系统模拟器
💻 H
📖 第 1 页 / 共 3 页
字号:

#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;
    wxChar errorList[DB_MAX_ERROR_HISTORY][DB_MAX_ERROR_MSG_LEN];
    wxChar errorMsg[SQL_MAX_MESSAGE_LENGTH];
    SDWORD 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 &Dsn, const wxString &Uid, const wxString &AuthStr, bool failOnDataTypeUnsupported=TRUE);
    bool         Open(wxDbConnectInf *dbConnectInf);
    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         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;}
    bool            IsOpen(void)           {return dbIsOpen;}
    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


// This structure forms a node in a linked list.  The linked list of "DbList" objects
// keeps track of allocated database connections.  This allows the application to
// open more than one database connection through ODBC for multiple transaction support
// or for multiple database support.
struct wxDbList
{
    wxDbList *PtrPrev;       // Pointer to previous item in the list
    wxString  Dsn;           // Data Source Name
    wxString  Uid;           // User ID
    wxString  AuthStr;       // Authorization string (password)
    wxDb     *PtrDb;         // Pointer to the wxDb object
    bool      Free;          // Is item free or in use?
    wxDbList *PtrNext;       // Pointer to next item in the list
};


#ifdef __WXDEBUG__
#include "wx/object.h"
class wxTablesInUse : public wxObject
{
    public:
        const wxChar  *tableName;
        ULONG          tableID;
        class wxDb    *pDb;
};  // wxTablesInUse
#endif


// The following routines allow a user to get new database connections, free them
// for other code segments to use, or close all of them when the application has
// completed.
wxDb  WXDLLEXPORT *wxDbGetConnection(wxDbConnectInf *pDbConfig, bool FwdOnlyCursors=(bool)wxODBC_FWD_ONLY_CURSORS);
bool  WXDLLEXPORT  wxDbFreeConnection(wxDb *pDb);
void  WXDLLEXPORT  wxDbCloseConnections(void);
int   WXDLLEXPORT  wxDbConnectionsInUse(void);


// Writes a message to the wxLog window (stdout usually) when an internal error
// situation occurs.  This function only works in DEBUG builds
const wxChar* WXDLLEXPORT wxDbLogExtendedErrorMsg(const wxChar *userText,
                                                  wxDb *pDb,
                                                  const wxChar *ErrFile,
                                                  int ErrLine);


// This function sets the sql log state for all open wxDb objects
bool  WXDLLEXPORT  wxDbSqlLog(wxDbSqlLogState state, const wxString &filename = SQL_LOG_FILENAME);


#if 0
// MSW/VC6 ONLY!!!  Experimental
int WXDLLEXPORT wxDbCreateDataSource(const wxString &driverName, const wxString &dsn, const wxString &description=wxEmptyString,
                                     bool sysDSN=FALSE, const wxString &defDir=wxEmptyString, wxWindow *parent=NULL);
#endif

// 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 WXDLLEXPORT wxDbGetDataSource(HENV henv, wxChar *Dsn, SWORD DsnMax, wxChar *DsDesc,
                                   SWORD DsDescMax, UWORD direction = SQL_FETCH_NEXT);


// Change this to 0 to remove use of all deprecated functions
#if wxODBC_BACKWARD_COMPATABILITY
//#################################################################################
//############### DEPRECATED functions for backward compatability #################
//#################################################################################

// Backward compability structures/classes.  This will eventually go away
const int DB_PATH_MAX      = wxDB_PATH_MAX;

typedef wxDb                 wxDB;
typedef wxDbTableInf         wxTableInf;
typedef wxDbColInf           wxColInf;
typedef wxDbColInf           CcolInf;
typedef wxDbColFor           wxColFor;
typedef wxDbSqlTypeInfo      SqlTypeInfo;
typedef wxDbSqlTypeInfo      wxSqlTypeInfo;
typedef enum wxDbSqlLogState sqlLog;
typedef enum wxDbSqlLogState wxSqlLogState;
typedef enum wxDBMS          dbms;
typedef enum wxDBMS          DBMS;
typedef wxODBC_ERRORS        ODBC_ERRORS;
typedef wxDbConnectInf       DbStuff;
typedef wxDbList             DbList;
#ifdef __WXDEBUG__
typedef wxTablesInUse        CstructTablesInUse;
#endif

// Deprecated function names that are replaced by the function names listed above
wxDB  WXDLLEXPORT *GetDbConnection(DbStuff *pDbStuff, bool FwdOnlyCursors=(bool)wxODBC_FWD_ONLY_CURSORS);
bool  WXDLLEXPORT  FreeDbConnection(wxDB *pDb);
void  WXDLLEXPORT  CloseDbConnections(void);
int   WXDLLEXPORT  NumberDbConnectionsInUse(void);

bool SqlLog(sqlLog state, const wxChar *filename = SQL_LOG_FILENAME);

bool WXDLLEXPORT GetDataSource(HENV henv, char *Dsn, SWORD DsnMax, char *DsDesc, SWORD DsDescMax,
                               UWORD direction = SQL_FETCH_NEXT);
#endif  // Deprecated structures/classes/functions

#endif // _WX_DB_H_

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -