home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1997 May / Pcwk0597.iso / sybase / starbuck / hpp.z / WODBCDR.HPP < prev    next >
C/C++ Source or Header  |  1996-04-26  |  16KB  |  490 lines

  1.  
  2. #ifndef _WODBCDR_HPP_INCLUDED
  3. #define _WODBCDR_HPP_INCLUDED
  4.  
  5. //----------------------------------------------------------------------
  6. //
  7. // WODBCDriver -- ODBC Driver cover class
  8. //
  9. // Use this class to dynamically load an ODBC DLL (by default, ODBC32.DLL).
  10. // Each ODBC 2.0 API function is covered.
  11. //
  12. // Sample use:
  13. //
  14. //    WODBCDriver *driver = WODBCDriver::Load( "ODBC32" );
  15. //
  16. //    driver->SQLAllocEnv( ... );
  17. //
  18. // Drivers are automatically unloaded on program termination.  If you
  19. // wish to free them beforehand, call WODBCDriver::Unload (do not try
  20. // to delete them).
  21. //
  22. //-----------------------------------------------------------------------
  23.  
  24. #ifndef _WODBC_HPP_INCLUDED
  25. #include "wodbc.hpp"
  26. #endif
  27. #ifndef _WMODULE_HPP_INCLUDED
  28. #include "wmodule.hpp"
  29. #endif
  30. #ifndef _WDATAERR_HPP_INCLUDED
  31. #include "wdataerr.hpp"
  32. #endif
  33.  
  34. //
  35. // Define our ODBC cover class.  This class lets us talk to any
  36. // DLL that exposes an ODBC set of interface functions.
  37. //
  38.  
  39. class WCMCLASS WODBCDriver : public WObject {
  40.  
  41.     protected:
  42.  
  43.         WODBCDriver( const WChar *name, const WModule & module );
  44.  
  45.     public:
  46.  
  47.         ~WODBCDriver();
  48.  
  49.         // Name
  50.  
  51.         WString GetName() const;
  52.  
  53.         // DisplayErrors
  54.  
  55.         WBool DisplayErrors( const WDataErrorArray & errors );
  56.  
  57.         // Environment Handle
  58.  
  59.         HENV    ReferenceEnvironment();
  60.         WBool   UnreferenceEnvironment();
  61.  
  62.         // FetchErrors
  63.         //
  64.         //    Call SQLError and build an array of WDataErrors.
  65.  
  66.         WDataErrorArray FetchErrors( HENV env, HDBC conn, HSTMT stmt,
  67.                                      WLong rc, WLong funcCode=0,
  68.                                      const WChar *prefix=NULL );
  69.  
  70.         // APIName
  71.         //
  72.         //    Return the name associated with an API function code.
  73.  
  74.         static WString GetAPIName( int funcCode );
  75.  
  76.         // RetcodeName
  77.         //
  78.         //    Return the string identifying a return code value.
  79.  
  80.         static WString GetRetcodeName( RETCODE rc );
  81.  
  82.         // Load
  83.         //
  84.         //    Load an ODBC driver.  If no name is specified, defaults
  85.         //    to "ODBC32".  Returns a pointer to a WODBCDriver.
  86.         //    The user must not free this pointer.
  87.  
  88.         static WODBCDriver *Load( const WChar *name=NULL );
  89.  
  90.         // Unload
  91.         //
  92.         //    Unloads an ODBC driver and frees the WODBCDriver
  93.         //    associated with it.
  94.  
  95.         static WBool Unload( const WChar *name=NULL );
  96.  
  97.         /****************************************************************
  98.          * SQL Functions
  99.          ****************************************************************/
  100.  
  101.         /* API functions -- environment */
  102.  
  103.         RETCODE SQLAllocEnv( HENV *phenv );
  104.  
  105.         RETCODE SQLError( HENV henv, HDBC hdbc, HSTMT hstmt,
  106.                           UCHAR *szSqlState, SDWORD *pfNativeError,
  107.                           UCHAR *szErrorMsg, SWORD cbErrorMsgMax,
  108.                           SWORD *pcbErrorMsg );
  109.         
  110.         RETCODE SQLDataSources( HENV henv, UWORD fDirection,
  111.                                 UCHAR *szDSN,
  112.                                 SWORD cbDSNMax, SWORD *pcbDSN,
  113.                                 UCHAR *szDescription,
  114.                                 SWORD cbDescriptionMax,
  115.                                 SWORD *pcbDescription );
  116.  
  117.         RETCODE SQLFreeEnv( HENV env );
  118.  
  119.         /* API functions -- connections */
  120.         
  121.         RETCODE SQLAllocConnect( HENV henv, HDBC *phdbc );
  122.         
  123.         RETCODE SQLConnect( HDBC hdbc, UCHAR *szDSN,
  124.                             SWORD cbDSN, UCHAR *szUID,
  125.                             SWORD cbUID, UCHAR *szAuthStr,
  126.                             SWORD cbAuthStr );
  127.         
  128.         RETCODE SQLDriverConnect( HDBC hdbc, HWND hwnd,
  129.                                   UCHAR *szConnStrIn,
  130.                                   SWORD  cbConnStrIn,
  131.                                   UCHAR *szConnStrOut,
  132.                                   SWORD  cbConnStrOutMax,
  133.                                   SWORD *pcbConnStrOut,
  134.                                   UWORD  fDriverCompletion );
  135.         
  136.         RETCODE SQLBrowseConnect(    
  137.             HDBC        hdbc,
  138.             UCHAR  *    szConnStrIn,
  139.             SWORD        cbConnStrIn,
  140.             UCHAR  *    szConnStrOut,
  141.             SWORD        cbConnStrOutMax,
  142.             SWORD  *    pcbConnStrOut );
  143.         
  144.         RETCODE SQLDrivers(
  145.             HENV        henv,
  146.             UWORD        fDirection,
  147.             UCHAR  *    *szDriverDesc,
  148.             SWORD        cbDriverDescMax,
  149.             SWORD  *    *pcbDriverDesc,
  150.             UCHAR  *    *szDriverAttributes,
  151.             SWORD        cbDrvrAttrMax,
  152.             SWORD  *    *pcbDrvrAttr );
  153.         
  154.         RETCODE SQLGetConnectOption(
  155.             HDBC        hdbc,
  156.             UWORD        fOption,
  157.             PTR            pvParam );
  158.         
  159.         RETCODE SQLSetConnectOption(
  160.             HDBC        hdbc,
  161.             UWORD        fOption,
  162.             UDWORD        vParam );
  163.         
  164.         RETCODE SQLNativeSql(
  165.             HDBC        hdbc,
  166.             UCHAR  *    szSqlStrIn,
  167.             SDWORD        cbSqlStrIn,
  168.             UCHAR  *    szSqlStr,
  169.             SDWORD        cbSqlStrMax,
  170.             SDWORD  *    pcbSqlStr );
  171.         
  172.         RETCODE SQLTransact(
  173.             HENV        henv,
  174.             HDBC        hdbc,
  175.             UWORD        fType );
  176.         
  177.         RETCODE SQLDisconnect(
  178.             HDBC        hdbc );
  179.         
  180.         RETCODE SQLFreeConnect(    
  181.             HDBC        hdbc );
  182.  
  183.         /* API functions -- driver information */
  184.         
  185.         RETCODE SQLGetFunctions( 
  186.             HDBC        hdbc,
  187.             UWORD        fFunction, UWORD *pfExists );
  188.         
  189.         RETCODE SQLGetInfo(     
  190.             HDBC        hdbc,
  191.             UWORD        fInfoType, 
  192.             PTR            rgbInfoValue,
  193.             SWORD        cbInfoValueMax,
  194.             SWORD *    pcbInfoValue );
  195.             
  196.         /* API functions -- statements */
  197.         
  198.         RETCODE SQLAllocStmt(       
  199.             HDBC        hdbc,
  200.             HSTMT *    phstmt );
  201.         
  202.         RETCODE SQLCancel(       
  203.             HSTMT        hstmt );
  204.         
  205.         RETCODE SQLExecDirect(  
  206.             HSTMT        hstmt,
  207.             UCHAR *    szSqlStr,
  208.             SDWORD        cbSqlStr );
  209.         
  210.         RETCODE SQLPrepare(    
  211.             HSTMT        hstmt,
  212.             UCHAR *    szSqlStr,
  213.             SDWORD        cbSqlStr );
  214.         
  215.         RETCODE SQLExecute(   
  216.             HSTMT        hstmt );
  217.         
  218.         RETCODE SQLGetStmtOption(
  219.             HSTMT        hstmt,
  220.             UWORD        fOption,
  221.             PTR            pvParam );
  222.         
  223.         RETCODE SQLSetStmtOption( 
  224.             HSTMT        hstmt,
  225.             UWORD        fOption,  
  226.             UDWORD        vParam );
  227.         
  228.         RETCODE SQLFreeStmt(      
  229.             HSTMT        hstmt,
  230.             UWORD        fOption );
  231.         
  232.         /* Result related functions */
  233.         
  234.         RETCODE SQLBindCol(       
  235.             HSTMT        hstmt,
  236.             UWORD        icol,    
  237.             SWORD        fCType,    
  238.             PTR            rgbValue,
  239.             SDWORD        cbValueMax,
  240.             SDWORD *    pcbValue );
  241.         
  242.         RETCODE SQLColAttributes(   
  243.             HSTMT        hstmt,
  244.             UWORD        icol,     
  245.             UWORD        fDescType, 
  246.             PTR            rgbDesc,
  247.             SWORD        cbDescMax,
  248.             SWORD *    pcbDesc,
  249.             SDWORD *    pfDesc );
  250.         
  251.         RETCODE SQLDescribeCol(    
  252.             HSTMT        hstmt,
  253.             UWORD        icol,     
  254.             UCHAR *    szColName,
  255.             SWORD        cbColNameMax,
  256.             SWORD *    pcbColName,
  257.             SWORD *    pfSqlType,  
  258.             UDWORD *    pcbColDef,
  259.             SWORD *    pibScale,
  260.             SWORD *    pfNullable ); 
  261.         
  262.         RETCODE SQLFetch(       
  263.             HSTMT        hstmt );
  264.         
  265.         RETCODE SQLExtendedFetch(  
  266.             HSTMT        hstmt,
  267.             UWORD        fFetchType, 
  268.             SDWORD        irow,
  269.             UDWORD *    pcrow,       
  270.             UWORD *    rgfRowStatus ); 
  271.         
  272.         RETCODE SQLSetPos(     
  273.             HSTMT        hstmt,
  274.             UWORD        irow, 
  275.             UWORD        fRefresh,
  276.             UWORD        fLock ); 
  277.         
  278.         RETCODE SQLSetScrollOptions(  
  279.             HSTMT        hstmt,
  280.             UWORD        fConcurrency, 
  281.             SDWORD        crowKeySet, 
  282.             UWORD        crowRowSet );
  283.         
  284.         RETCODE SQLGetCursorName(    
  285.             HSTMT        hstmt,
  286.             UCHAR *    szCursor,
  287.             SWORD        cbCursorMax,
  288.             SWORD *    pcbCursor );
  289.         
  290.         RETCODE SQLGetData(        
  291.             HSTMT        hstmt,
  292.             UWORD        icol,     
  293.             SWORD        fCType,   
  294.             PTR            rgbValue,
  295.             SDWORD        cbValueMax,
  296.             SDWORD *    pcbValue );
  297.         
  298.         RETCODE SQLNumResultCols(  
  299.             HSTMT        hstmt,
  300.             SWORD *    pccol );
  301.         
  302.         RETCODE SQLRowCount(      
  303.             HSTMT        hstmt,
  304.             SDWORD *    pcrow );
  305.         
  306.         RETCODE SQLSetCursorName( 
  307.             HSTMT        hstmt,
  308.             UCHAR *    szCursor,
  309.             SWORD        cbCursor );
  310.         
  311.         /* Parameters */
  312.         
  313.         RETCODE SQLNumParams(    
  314.             HSTMT        hstmt,
  315.             SWORD *    pcpar );
  316.         
  317.         RETCODE SQLDescribeParam( 
  318.             HSTMT        hstmt,
  319.             UWORD        ipar,   
  320.             SWORD *    pfSqlType,
  321.             UDWORD *    pcbColDef,
  322.             SWORD *    pibScale,
  323.             SWORD *    pfNullable ); 
  324.         
  325.         RETCODE SQLBindParameter(
  326.             HSTMT        hstmt,
  327.             UWORD        ipar,
  328.             SWORD        fParamType,
  329.             SWORD        fCType,
  330.             SWORD        fSqlType,
  331.             UDWORD        cbColDef,
  332.             SWORD        ibScale,
  333.             PTR            rgbValue,
  334.             SDWORD        cbValueMax,
  335.             SDWORD *    pcbValue );
  336.             
  337.         RETCODE SQLSetParam(      
  338.             HSTMT        hstmt,
  339.             UWORD        ipar,    
  340.             SWORD        fCType,  
  341.             SWORD        fSqlType,
  342.             UDWORD        cbColDef, 
  343.             SWORD        ibScale,   
  344.             PTR            rgbValue,
  345.             SDWORD *    pcbValue );
  346.         
  347.         RETCODE SQLParamData(      
  348.             HSTMT        hstmt,
  349.             PTR *    prgbValue );  
  350.         
  351.         RETCODE SQLPutData(       
  352.             HSTMT        hstmt,
  353.             PTR            rgbValue,
  354.             SDWORD        cbValue );
  355.         
  356.         RETCODE SQLMoreResults(   
  357.             HSTMT        hstmt );
  358.         
  359.         RETCODE SQLParamOptions(  
  360.             HSTMT        hstmt,
  361.             UDWORD        crow,
  362.             UDWORD *    pirow );
  363.         
  364.         /* Catalog information */
  365.         
  366.         RETCODE SQLColumnPrivileges(    
  367.             HSTMT        hstmt,
  368.             UCHAR *    szTableQualifier,
  369.             SWORD        cbTableQualifier,
  370.             UCHAR *    szTableOwner,
  371.             SWORD        cbTableOwner,
  372.             UCHAR *    szTableName,
  373.             SWORD        cbTableName,
  374.             UCHAR *    szColumnName,
  375.             SWORD        cbColumnName );
  376.         
  377.         RETCODE SQLTablePrivileges(    
  378.             HSTMT        hstmt,
  379.             UCHAR *    szTableQualifier,
  380.             SWORD        cbTableQualifier,
  381.             UCHAR *    szTableOwner,
  382.             SWORD        cbTableOwner,
  383.             UCHAR *    szTableName,
  384.             SWORD        cbTableName );
  385.         
  386.         RETCODE SQLColumns(        
  387.             HSTMT        hstmt,
  388.             UCHAR *    szTableQualifier,
  389.             SWORD        cbTableQualifier,
  390.             UCHAR *    szTableOwner,
  391.             SWORD        cbTableOwner,
  392.             UCHAR *    szTableName,
  393.             SWORD        cbTableName,
  394.             UCHAR *    szColumnName,
  395.             SWORD        cbColumnName );
  396.         
  397.         RETCODE SQLForeignKeys(  
  398.             HSTMT        hstmt,
  399.             UCHAR *    szPkTableQualifier,
  400.             SWORD        cbPkTableQualifier,
  401.             UCHAR *    szPkTableOwner,
  402.             SWORD        cbPkTableOwner,
  403.             UCHAR *    szPkTableName,
  404.             SWORD        cbPkTableName,
  405.             UCHAR *    szFkTableQualifier,
  406.             SWORD        cbFkTableQualifier,
  407.             UCHAR *    szFkTableOwner,
  408.             SWORD        cbFkTableOwner,
  409.             UCHAR *    szFkTableName,
  410.             SWORD        cbFkTableName );
  411.         
  412.         RETCODE SQLGetTypeInfo( 
  413.             HSTMT        hstmt,
  414.             SWORD        fSqlType );
  415.         
  416.         RETCODE SQLPrimaryKeys(   
  417.             HSTMT        hstmt,
  418.             UCHAR *    szTableQualifier,
  419.             SWORD        cbTableQualifier,
  420.             UCHAR *    szTableOwner,
  421.             SWORD        cbTableOwner,
  422.             UCHAR *    szTableName,
  423.             SWORD        cbTableName );
  424.         
  425.         RETCODE SQLProcedureColumns(    
  426.             HSTMT        hstmt,
  427.             UCHAR *    szProcQualifier,
  428.             SWORD        cbProcQualifier,
  429.             UCHAR *    szProcOwner,
  430.             SWORD        cbProcOwner,
  431.             UCHAR *    szProcName,
  432.             SWORD        cbProcName,
  433.             UCHAR *    szColumnName,
  434.             SWORD        cbColumnName );
  435.         
  436.         RETCODE SQLProcedures(        
  437.             HSTMT        hstmt,
  438.             UCHAR *    szProcQualifier,
  439.             SWORD        cbProcQualifier,
  440.             UCHAR *    szProcOwner,
  441.             SWORD        cbProcOwner,
  442.             UCHAR *    szProcName,
  443.             SWORD        cbProcName );
  444.         
  445.         RETCODE SQLSpecialColumns( 
  446.             HSTMT        hstmt,
  447.             UWORD        fColType, 
  448.             UCHAR *    szTableQualifier,
  449.             SWORD        cbTableQualifier,
  450.             UCHAR *    szTableOwner,
  451.             SWORD        cbTableOwner,
  452.             UCHAR *    szTableName,
  453.             SWORD        cbTableName,
  454.             UWORD        fScope,       
  455.             UWORD        fNullable ); 
  456.         
  457.         RETCODE SQLStatistics(       
  458.             HSTMT        hstmt,
  459.             UCHAR *    szTableQualifier,
  460.             SWORD        cbTableQualifier,
  461.             UCHAR *    szTableOwner,
  462.             SWORD        cbTableOwner,
  463.             UCHAR *    szTableName,
  464.             SWORD        cbTableName,
  465.             UWORD        fUnique,   
  466.             UWORD        fAccuracy ); 
  467.         
  468.         RETCODE SQLTables(        
  469.             HSTMT        hstmt,
  470.             UCHAR *    szTableQualifier,
  471.             SWORD        cbTableQualifier,
  472.             UCHAR *    szTableOwner,
  473.             SWORD        cbTableOwner,
  474.             UCHAR *    szTableName,
  475.             SWORD        cbTableName,
  476.             UCHAR *    szTableType,   
  477.             SWORD        cbTableType );
  478.         
  479.     protected:
  480.     
  481.         WModule          _module;
  482.         WString          _name;
  483.         HENV             _envHandle;
  484.         WInt             _envCount;
  485.         void            *_jumpTable[ SQL_API_END_OF_FUNCTIONS ];
  486.         WDataErrorArray  _ignoreList;
  487. };
  488.     
  489. #endif
  490.