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

📄 db.h

📁 浙江大学的悟空嵌入式系统模拟器
💻 H
📖 第 1 页 / 共 3 页
字号:
    DB_ERR_INVALID_BOOKMARK_VALUE,                     // SqlState = 'S1111'
    DB_ERR_DRIVER_NOT_CAPABLE,                         // SqlState = 'S1C00'
    DB_ERR_TIMEOUT_EXPIRED                             // SqlState = 'S1T00'
};

#ifndef MAXNAME
#define MAXNAME         31
#endif

#ifndef SQL_MAX_AUTHSTR_LEN
// There does not seem to be a standard for this, so I am
// defaulting to the value that MS uses
#define SQL_MAX_AUTHSTR_LEN MAXNAME
#endif

class WXDLLEXPORT wxDbConnectInf
{
    private:
        bool freeHenvOnDestroy;

    public:
        HENV Henv;
        wxChar Dsn[SQL_MAX_DSN_LENGTH+1];                  // Data Source Name
        wxChar Uid[SQL_MAX_USER_NAME_LEN+1];               // User ID
        wxChar AuthStr[SQL_MAX_AUTHSTR_LEN+1];             // Authorization string (password)

        wxString Description;                              // Not sure what the max length is
        wxString FileType;                                 // Not sure what the max length is

        // Optionals needed for some databases like dBase
        wxString DefaultDir;                               // Directory that db file resides in

    public:

        wxDbConnectInf();
        wxDbConnectInf(HENV henv, const wxString &dsn, const wxString &userID=wxEmptyString, 
                       const wxString &password=wxEmptyString, const wxString &defaultDir=wxEmptyString, 
                       const wxString &description=wxEmptyString, const wxString &fileType=wxEmptyString);

        ~wxDbConnectInf();

        bool             Initialize();

        bool             AllocHenv();
        void             FreeHenv();

        // Accessors
        const HENV       &GetHenv()          { return Henv; };

        const wxChar    *GetDsn()           { return Dsn; };

        const wxChar    *GetUid()           { return Uid; };
        const wxChar    *GetUserID()        { return Uid; };

        const wxChar    *GetAuthStr()       { return AuthStr; };
        const wxChar    *GetPassword()      { return AuthStr; };

        const wxChar    *GetDescription()   { return Description; };
        const wxChar    *GetFileType()      { return FileType; };
        const wxChar    *GetDefaultDir()    { return DefaultDir; };

        void             SetHenv(const HENV henv)               { Henv = henv; };

        void             SetDsn(const wxString &dsn);

        void             SetUserID(const wxString &userID);
        void             SetUid(const wxString &uid)            { SetUserID(uid); };

        void             SetPassword(const wxString &password);
        void             SetAuthStr(const wxString &authstr)    { SetPassword(authstr); };

        void             SetDescription(const wxString &desc)   { Description   = desc;     };
        void             SetFileType(const wxString &fileType)  { FileType      = fileType; };
        void             SetDefaultDir(const wxString &defDir)  { DefaultDir    = defDir;   };
};  // class wxDbConnectInf


struct WXDLLEXPORT wxDbSqlTypeInfo
{
    wxString    TypeName;
    SWORD       FsqlType;
    long        Precision;
    short       CaseSensitive;
//    short     MinimumScale;
    short       MaximumScale;
};


class WXDLLEXPORT wxDbColFor
{
public:
    wxString       s_Field;              // Formated String for Output
    wxString       s_Format[7];          // Formated Objects - TIMESTAMP has the biggest (7)
    wxString       s_Amount[7];          // Formated Objects - amount of things that can be formatted
    int            i_Amount[7];          // Formated Objects - TT MM YYYY HH MM SS m
    int            i_Nation;             // 0 = timestamp , 1=EU, 2=UK, 3=International, 4=US
    int            i_dbDataType;         // conversion of the 'sqlDataType' to the generic data type used by these classes
    SWORD          i_sqlDataType;

    wxDbColFor();
    ~wxDbColFor();

    void           Initialize();
    int            Format(int Nation, int dbDataType, SWORD sqlDataType, short columnSize, short decimalDigits);
};


class WXDLLEXPORT wxDbColInf
{
public:
    wxChar       catalog[128+1];
    wxChar       schema[128+1];
    wxChar       tableName[DB_MAX_TABLE_NAME_LEN+1];
    wxChar       colName[DB_MAX_COLUMN_NAME_LEN+1];
    SWORD        sqlDataType;
    wxChar       typeName[128+1];
    SWORD        columnSize;
    SWORD        bufferLength;
    short        decimalDigits;
    short        numPrecRadix;
    short        nullable;
    wxChar       remarks[254+1];
    int          dbDataType;  // conversion of the 'sqlDataType' to the generic data type used by these classes
 // mj10777.19991224 : new
    int          PkCol;       // Primary key column       0=No; 1= First Key, 2 = Second Key etc.
    wxChar       PkTableName[DB_MAX_TABLE_NAME_LEN+1]; // Tables that use this PKey as a FKey
    int          FkCol;       // Foreign key column       0=No; 1= First Key, 2 = Second Key etc.
    wxChar       FkTableName[DB_MAX_TABLE_NAME_LEN+1]; // Foreign key table name
    wxDbColFor  *pColFor;                              // How should this columns be formatted

    wxDbColInf();
    ~wxDbColInf();

    bool Initialize();
};


class WXDLLEXPORT wxDbTableInf        // Description of a Table
{
public:
    wxChar      tableName[DB_MAX_TABLE_NAME_LEN+1];
    wxChar      tableType[254+1];           // "TABLE" or "SYSTEM TABLE" etc.
    wxChar      tableRemarks[254+1];
    UWORD       numCols;                    // How many Columns does this Table have: GetColumnCount(..);
    wxDbColInf *pColInf;                    // pColInf = NULL ; User can later call GetColumns(..);

    wxDbTableInf();
    ~wxDbTableInf();

    bool             Initialize();
};


class WXDLLEXPORT wxDbInf     // Description of a Database
{
public:
    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
};


// 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.

WXDLLEXPORT_DATA(extern wxChar) DBerrorList[DB_MAX_ERROR_HISTORY][DB_MAX_ERROR_MSG_LEN];


class WXDLLEXPORT wxDb
{
private:
    bool             dbIsOpen;
    bool             dbIsCached;      // Was connection created by caching functions
    wxString         dsn;             // Data source name
    wxString         uid;             // User ID
    wxString         authStr;         // Authorization string (password)
    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(void);
    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);
    void             initialize();

#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); }

⌨️ 快捷键说明

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