home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / mfc / database / catalog2 / catsets.cpp < prev    next >
C/C++ Source or Header  |  1998-03-26  |  26KB  |  1,013 lines

  1. // catsets.cpp :
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1992-1998 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Microsoft Foundation Classes Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Microsoft Foundation Classes product.
  12.  
  13. #include "stdafx.h"
  14. #include "catsets.h"
  15.  
  16. //---------------------------------------------------------------------
  17. // CColumnPrivileges
  18.  
  19. CColumnPrivileges::CColumnPrivileges(CDatabase* pDatabase)
  20.     : CRecordset(pDatabase)
  21. {
  22.     m_strTableQualifier = _T("");
  23.     m_strTableOwner     = _T("");
  24.     m_strTableName      = _T("");
  25.     m_strColumnName     = _T("");
  26.     m_strGrantor        = _T("");
  27.     m_strGrantee        = _T("");
  28.     m_strPrivilege      = _T("");
  29.     m_strIsGrantable    = _T("");
  30.     m_nFields = 8;
  31. }
  32.  
  33. BOOL CColumnPrivileges::Open(LPCSTR pszTableQualifier,
  34.     LPCSTR pszTableOwner,LPCSTR pszTableName,LPCSTR pszColumnName,
  35.     UINT nOpenType)
  36. {
  37.     RETCODE nRetCode;
  38.     UWORD   bFunctionExists;
  39.  
  40.     // Make sure SQLColumnPrivileges is supported
  41.     AFX_SQL_SYNC(::SQLGetFunctions(m_pDatabase->m_hdbc,
  42.         SQL_API_SQLCOLUMNPRIVILEGES,&bFunctionExists));
  43.     if (!Check(nRetCode) || !bFunctionExists)
  44.     {
  45.         if (!bFunctionExists)
  46.             TRACE(_T("SQLColumnPrivileges not supported\n"));
  47.         return FALSE;
  48.     }
  49.  
  50.     // Cache state info and allocate hstmt
  51.     SetState(nOpenType,NULL,readOnly);
  52.     if (!AllocHstmt())
  53.         return FALSE;
  54.  
  55.     TRY
  56.     {
  57.         OnSetOptions(m_hstmt);
  58.         AllocStatusArrays();
  59.  
  60.         // Call the ODBC function
  61.         AFX_ODBC_CALL(::SQLColumnPrivileges(m_hstmt,
  62.             (UCHAR FAR*)pszTableQualifier,SQL_NTS,
  63.             (UCHAR FAR*)pszTableOwner,SQL_NTS,
  64.             (UCHAR FAR*)pszTableName,SQL_NTS,
  65.             (UCHAR FAR*)pszColumnName,SQL_NTS));
  66.         if (!Check(nRetCode))
  67.             ThrowDBException(nRetCode,m_hstmt);
  68.  
  69.         // Allocate memory and cache info
  70.         AllocAndCacheFieldInfo();
  71.         AllocRowset();
  72.  
  73.         // Fetch the first row of data
  74.         MoveNext();
  75.  
  76.         // If EOF, result set is empty, set BOF as well
  77.         m_bBOF = m_bEOF;
  78.  
  79.     }
  80.     CATCH_ALL(e)
  81.     {
  82.         Close();
  83.         THROW_LAST();
  84.     }
  85.     END_CATCH_ALL
  86.  
  87.     return TRUE;
  88. }
  89.  
  90. void CColumnPrivileges::DoFieldExchange(CFieldExchange* pFX)
  91. {
  92.     pFX->SetFieldType(CFieldExchange::outputColumn);
  93.     RFX_Text(pFX,_T("TABLE_QUALIFIER"),m_strTableQualifier);
  94.     RFX_Text(pFX,_T("TABLE_OWNER"),m_strTableOwner);
  95.     RFX_Text(pFX,_T("TABLE_NAME"),m_strTableName);
  96.     RFX_Text(pFX,_T("COLUMN_NAME"),m_strColumnName);
  97.     RFX_Text(pFX,_T("GRANTOR"),m_strGrantor);
  98.     RFX_Text(pFX,_T("GRANTEE"),m_strGrantee);
  99.     RFX_Text(pFX,_T("PRIVILEGE"),m_strPrivilege);
  100.     RFX_Text(pFX,_T("IS_GRANTABLE"),m_strIsGrantable);
  101. }
  102.  
  103. //---------------------------------------------------------------------
  104. // CColumns
  105.  
  106. CColumns::CColumns(CDatabase* pDatabase)
  107.     : CRecordset(pDatabase)
  108. {
  109.     m_strTableQualifier = _T("");
  110.     m_strTableOwner     = _T("");
  111.     m_strTableName      = _T("");
  112.     m_strColumnName     = _T("");
  113.     m_nDataType         = 0;
  114.     m_strTypeName       = _T("");
  115.     m_nPrecision        = 0;
  116.     m_nLength           = 0;
  117.     m_nScale            = 0;
  118.     m_nRadix            = 0;
  119.     m_fNullable         = 0;
  120.     m_strRemarks        = _T("");
  121.     m_nFields = 12;
  122. }
  123.  
  124. BOOL CColumns::Open(LPCSTR pszTableQualifier,
  125.     LPCSTR pszTableOwner,LPCSTR pszTableName,LPCSTR pszColumnName,
  126.     UINT nOpenType)
  127. {
  128.     RETCODE nRetCode;
  129.     UWORD   bFunctionExists;
  130.  
  131.     // Make sure SQLColumns is supported
  132.     AFX_SQL_SYNC(::SQLGetFunctions(m_pDatabase->m_hdbc,
  133.         SQL_API_SQLCOLUMNS,&bFunctionExists));
  134.     if (!Check(nRetCode) || !bFunctionExists)
  135.     {
  136.         if (!bFunctionExists)
  137.             TRACE(_T("SQLColumns not supported\n"));
  138.         return FALSE;
  139.     }
  140.  
  141.     // Cache state info and allocate hstmt
  142.     SetState(nOpenType,NULL,readOnly);
  143.     if (!AllocHstmt())
  144.         return FALSE;
  145.  
  146.     TRY
  147.     {
  148.         OnSetOptions(m_hstmt);
  149.         AllocStatusArrays();
  150.  
  151.         // Call the ODBC function
  152.         AFX_ODBC_CALL(::SQLColumns(m_hstmt,
  153.             (UCHAR FAR*)pszTableQualifier,SQL_NTS,
  154.             (UCHAR FAR*)pszTableOwner,SQL_NTS,
  155.             (UCHAR FAR*)pszTableName,SQL_NTS,
  156.             (UCHAR FAR*)pszColumnName,SQL_NTS));
  157.         if (!Check(nRetCode))
  158.             ThrowDBException(nRetCode,m_hstmt);
  159.  
  160.         // Allocate memory and cache info
  161.         AllocAndCacheFieldInfo();
  162.         AllocRowset();
  163.  
  164.         // Fetch the first row of data
  165.         MoveNext();
  166.  
  167.         // If EOF, result set is empty, set BOF as well
  168.         m_bBOF = m_bEOF;
  169.  
  170.     }
  171.     CATCH_ALL(e)
  172.     {
  173.         Close();
  174.         THROW_LAST();
  175.     }
  176.     END_CATCH_ALL
  177.  
  178.     return TRUE;
  179. }
  180.  
  181. void CColumns::DoFieldExchange(CFieldExchange* pFX)
  182. {
  183.     pFX->SetFieldType(CFieldExchange::outputColumn);
  184.     RFX_Text(pFX,_T("TABLE_QUALIFIER"),m_strTableQualifier);
  185.     RFX_Text(pFX,_T("TABLE_OWNER"),m_strTableOwner);
  186.     RFX_Text(pFX,_T("TABLE_NAME"),m_strTableName);
  187.     RFX_Text(pFX,_T("COLUMN_NAME"),m_strColumnName);
  188.     RFX_Int(pFX,_T("DATA_TYPE"),m_nDataType);
  189.     RFX_Text(pFX,_T("TYPE_NAME"),m_strTypeName);
  190.     RFX_Long(pFX,_T("PRECISION"),m_nPrecision);
  191.     RFX_Long(pFX,_T("LENGTH"),m_nLength);
  192.     RFX_Int(pFX,_T("SCALE"),m_nScale);
  193.     RFX_Int(pFX,_T("RADIX"),m_nRadix);
  194.     RFX_Int(pFX,_T("NULLABLE"),m_fNullable);
  195.     RFX_Text(pFX,_T("REMARKS"),m_strRemarks);
  196. }
  197.  
  198. //---------------------------------------------------------------------
  199. // CForeignKeys
  200.  
  201. CForeignKeys::CForeignKeys(CDatabase* pDatabase)
  202.     : CRecordset(pDatabase)
  203. {
  204.  
  205.     m_strPkTableQualifier   = _T("");
  206.     m_strPkTableOwner       = _T("");
  207.     m_strPkTableName        = _T("");
  208.     m_strPkColumnName       = _T("");
  209.     m_strFkTableQualifier   = _T("");
  210.     m_strFkTableOwner       = _T("");
  211.     m_strFkTableName        = _T("");
  212.     m_strFkColumnName       = _T("");
  213.     m_nKeySeq               = 0;
  214.     m_fUpdateRule           = 0;
  215.     m_fDeleteRule           = 0;
  216.     m_strFkName             = _T("");
  217.     m_strPkName             = _T("");
  218.     m_nFields = 13;
  219. }
  220.  
  221. BOOL CForeignKeys::Open(LPCSTR pszPkTableQualifier,
  222.     LPCSTR pszPkTableOwner,LPCSTR pszPkTableName,LPCSTR pszFkTableQualifier,
  223.     LPCSTR pszFkTableOwner,LPCSTR pszFkTableName,
  224.     UINT nOpenType)
  225. {
  226.     RETCODE nRetCode;
  227.     UWORD   bFunctionExists;
  228.  
  229.     // Make sure SQLForeignKeys is supported
  230.     AFX_SQL_SYNC(::SQLGetFunctions(m_pDatabase->m_hdbc,
  231.         SQL_API_SQLFOREIGNKEYS,&bFunctionExists));
  232.     if (!Check(nRetCode) || !bFunctionExists)
  233.     {
  234.         if (!bFunctionExists)
  235.             TRACE(_T("SQLForeignKeys not supported\n"));
  236.         return FALSE;
  237.     }
  238.  
  239.     // Cache state info and allocate hstmt
  240.     SetState(nOpenType,NULL,readOnly);
  241.     if (!AllocHstmt())
  242.         return FALSE;
  243.  
  244.     TRY
  245.     {
  246.         OnSetOptions(m_hstmt);
  247.         AllocStatusArrays();
  248.  
  249.         // Call the ODBC function
  250.         AFX_ODBC_CALL(::SQLForeignKeys(m_hstmt,
  251.             (UCHAR FAR*)pszPkTableQualifier,SQL_NTS,
  252.             (UCHAR FAR*)pszPkTableOwner,SQL_NTS,
  253.             (UCHAR FAR*)pszPkTableName,SQL_NTS,
  254.             (UCHAR FAR*)pszFkTableQualifier,SQL_NTS,
  255.             (UCHAR FAR*)pszFkTableOwner,SQL_NTS,
  256.             (UCHAR FAR*)pszFkTableName,SQL_NTS));
  257.         if (!Check(nRetCode))
  258.             ThrowDBException(nRetCode,m_hstmt);
  259.  
  260.         // Allocate memory and cache info
  261.         AllocAndCacheFieldInfo();
  262.         AllocRowset();
  263.  
  264.         // Fetch the first row of data
  265.         MoveNext();
  266.  
  267.         // If EOF, result set is empty, set BOF as well
  268.         m_bBOF = m_bEOF;
  269.  
  270.     }
  271.     CATCH_ALL(e)
  272.     {
  273.         Close();
  274.         THROW_LAST();
  275.     }
  276.     END_CATCH_ALL
  277.  
  278.     return TRUE;
  279. }
  280.  
  281. void CForeignKeys::DoFieldExchange(CFieldExchange* pFX)
  282. {
  283.     pFX->SetFieldType(CFieldExchange::outputColumn);
  284.     RFX_Text(pFX,_T("PKTABLE_QUALIFIER"),m_strPkTableQualifier);
  285.     RFX_Text(pFX,_T("PKTABLE_OWNER"),m_strPkTableOwner);
  286.     RFX_Text(pFX,_T("PKTABLE_NAME"),m_strPkTableName);
  287.     RFX_Text(pFX,_T("PKCOLUMN_NAME"),m_strPkColumnName);
  288.     RFX_Text(pFX,_T("FKTABLE_QUALIFIER"),m_strFkTableQualifier);
  289.     RFX_Text(pFX,_T("FKTABLE_OWNER"),m_strFkTableOwner);
  290.     RFX_Text(pFX,_T("FKTABLE_NAME"),m_strFkTableName);
  291.     RFX_Text(pFX,_T("FKCOLUMN_NAME"),m_strFkColumnName);
  292.     RFX_Int(pFX,_T("KEY_SEQ"),m_nKeySeq);
  293.     RFX_Int(pFX,_T("UPDATE_RULE"),m_fUpdateRule);
  294.     RFX_Int(pFX,_T("DELETE_RULE"),m_fDeleteRule);
  295.     RFX_Text(pFX,_T("FK_NAME"),m_strFkName);
  296.     RFX_Text(pFX,_T("PK_NAME"),m_strPkName);
  297. }
  298.  
  299. //---------------------------------------------------------------------
  300. // CGetTypeInfo
  301.  
  302. CGetTypeInfo::CGetTypeInfo(CDatabase* pDatabase)
  303.     : CRecordset(pDatabase)
  304. {
  305.     m_strTypeName           = _T("");
  306.     m_fDataType             = 0;
  307.     m_nPrecision            = 0;
  308.     m_strLiteralPrefix      = _T("");
  309.     m_strLiteralSuffix      = _T("");
  310.     m_strCreateParams       = _T("");
  311.     m_fNullable             = 0;
  312.     m_bCaseSensitive        = 0;
  313.     m_fSearchable           = 0;
  314.     m_fUnsignedAttribute    = 0;
  315.     m_bMoney                = 0;
  316.     m_fAutoIncrement        = 0;
  317.     m_strLocalTypeName      = _T("");
  318.     m_nMinimumScale         = 0;
  319.     m_nMaximumScale         = 0;
  320.     m_nFields = 15;
  321. }
  322.  
  323. BOOL CGetTypeInfo::Open(short fSqlType,
  324.     UINT nOpenType)
  325. {
  326.     RETCODE nRetCode;
  327.     UWORD   bFunctionExists;
  328.  
  329.     // Make sure SQLGetTypeInfo exists
  330.     AFX_SQL_SYNC(::SQLGetFunctions(m_pDatabase->m_hdbc,
  331.         SQL_API_SQLGETTYPEINFO,&bFunctionExists));
  332.     if (!Check(nRetCode) || !bFunctionExists)
  333.     {
  334.         if (!bFunctionExists)
  335.             TRACE(_T("SQLGetTypeInfo not supported\n"));
  336.         return FALSE;
  337.     }
  338.  
  339.     // Cache state info and allocate hstmt
  340.     SetState(nOpenType,NULL,readOnly);
  341.     if (!AllocHstmt())
  342.         return FALSE;
  343.  
  344.     TRY
  345.     {
  346.         OnSetOptions(m_hstmt);
  347.         AllocStatusArrays();
  348.  
  349.         // Call the ODBC function
  350.         AFX_ODBC_CALL(::SQLGetTypeInfo(m_hstmt,fSqlType));
  351.         if (!Check(nRetCode))
  352.             ThrowDBException(nRetCode,m_hstmt);
  353.  
  354.         // Allocate memory and cache info
  355.         AllocAndCacheFieldInfo();
  356.         AllocRowset();
  357.  
  358.         // Fetch the first row of data
  359.         MoveNext();
  360.  
  361.         // If EOF, result set is empty, set BOF as well
  362.         m_bBOF = m_bEOF;
  363.  
  364.     }
  365.  
  366.     CATCH_ALL(e)
  367.     {
  368.         Close();
  369.         THROW_LAST();
  370.     }
  371.     END_CATCH_ALL
  372.  
  373.     return TRUE;
  374. }
  375.  
  376. void CGetTypeInfo::DoFieldExchange(CFieldExchange* pFX)
  377. {
  378.     pFX->SetFieldType(CFieldExchange::outputColumn);
  379.     RFX_Text(pFX,_T("TYPE_NAME"),m_strTypeName);
  380.     RFX_Int(pFX,_T("DATA_TYPE"),m_fDataType);
  381.     RFX_Long(pFX,_T("PRECISION"),m_nPrecision);
  382.     RFX_Text(pFX,_T("LITERAL_PREFIX"),m_strLiteralPrefix);
  383.     RFX_Text(pFX,_T("LITERAL_SUFFIX"),m_strLiteralSuffix);
  384.     RFX_Text(pFX,_T("CREATE_PARAMS"),m_strCreateParams);
  385.     RFX_Int(pFX,_T("NULLABLE"),m_fNullable);
  386.     RFX_Bool(pFX,_T("CASE_SENSITIVE"),m_bCaseSensitive);
  387.     RFX_Int(pFX,_T("SEARCHABLE"),m_fSearchable);
  388.     RFX_Int(pFX,_T("UNSIGNED_ATTRIBUTE"),m_fUnsignedAttribute);
  389.     RFX_Bool(pFX,_T("MONEY"),m_bMoney);
  390.     RFX_Int(pFX,_T("AUTO_INCREMENT"),m_fAutoIncrement);
  391.     RFX_Text(pFX,_T("LOCAL_TYPE_NAME"),m_strLocalTypeName);
  392.     RFX_Int(pFX,_T("MINIMUM_SCALE"),m_nMinimumScale);
  393.     RFX_Int(pFX,_T("MAXIMUM_SCALE"),m_nMaximumScale);
  394. }
  395.  
  396. //---------------------------------------------------------------------
  397. // CPrimaryKeys
  398.  
  399. CPrimaryKeys::CPrimaryKeys(CDatabase* pDatabase)
  400.     : CRecordset(pDatabase)
  401. {
  402.     m_strTableQualifier = _T("");
  403.     m_strTableOwner     = _T("");
  404.     m_strTableName      = _T("");
  405.     m_strColumnName     = _T("");
  406.     m_nKeySeq           = 0;
  407.     m_strPkName         = _T("");
  408.     m_nFields = 6;
  409. }
  410.  
  411. BOOL CPrimaryKeys::Open(LPCSTR pszTableQualifier,
  412.     LPCSTR pszTableOwner,LPCSTR pszTableName,
  413.     UINT nOpenType)
  414. {
  415.     RETCODE nRetCode;
  416.     UWORD   bFunctionExists;
  417.  
  418.     // Make sure SQLPrimaryKeys exists
  419.     AFX_SQL_SYNC(::SQLGetFunctions(m_pDatabase->m_hdbc,
  420.         SQL_API_SQLPRIMARYKEYS,&bFunctionExists));
  421.     if (!Check(nRetCode) || !bFunctionExists)
  422.     {
  423.         if (!bFunctionExists)
  424.             TRACE(_T("SQLPrimaryKeys not supported\n"));
  425.         return FALSE;
  426.     }
  427.  
  428.     // Cache state info and allocate hstmt
  429.     SetState(nOpenType,NULL,readOnly);
  430.     if (!AllocHstmt())
  431.         return FALSE;
  432.  
  433.     TRY
  434.     {
  435.         OnSetOptions(m_hstmt);
  436.         AllocStatusArrays();
  437.  
  438.         // Call the ODBC function
  439.         AFX_ODBC_CALL(::SQLPrimaryKeys(m_hstmt,
  440.             (UCHAR FAR*)pszTableQualifier,SQL_NTS,
  441.             (UCHAR FAR*)pszTableOwner,SQL_NTS,
  442.             (UCHAR FAR*)pszTableName,SQL_NTS));
  443.         if (!Check(nRetCode))
  444.             ThrowDBException(nRetCode,m_hstmt);
  445.  
  446.         // Allocate memory and cache info
  447.         AllocAndCacheFieldInfo();
  448.         AllocRowset();
  449.  
  450.         // Fetch the first row of data
  451.         MoveNext();
  452.  
  453.         // if EOF, result set is empty, set BOF as well
  454.         m_bBOF = m_bEOF;
  455.  
  456.     }
  457.  
  458.     CATCH_ALL(e)
  459.     {
  460.         Close();
  461.         THROW_LAST();
  462.     }
  463.     END_CATCH_ALL
  464.  
  465.     return TRUE;
  466. }
  467.  
  468. void CPrimaryKeys::DoFieldExchange(CFieldExchange* pFX)
  469. {
  470.     pFX->SetFieldType(CFieldExchange::outputColumn);
  471.     RFX_Text(pFX,_T("TABLE_QUALIFIER"),m_strTableQualifier);
  472.     RFX_Text(pFX,_T("TABLE_OWNER"),m_strTableOwner);
  473.     RFX_Text(pFX,_T("TABLE_NAME"),m_strTableName);
  474.     RFX_Text(pFX,_T("COLUMN_NAME"),m_strColumnName);
  475.     RFX_Int(pFX,_T("KEY_SEQ"),m_nKeySeq);
  476.     RFX_Text(pFX,_T("PK_NAME"),m_strPkName);
  477. }
  478.  
  479. //---------------------------------------------------------------------
  480. // CProcedureColumns
  481.  
  482. CProcedureColumns::CProcedureColumns(CDatabase* pDatabase)
  483.     : CRecordset(pDatabase)
  484. {
  485.     m_strProcedureQualifier = _T("");
  486.     m_strProcedureOwner     = _T("");
  487.     m_strProcedureName      = _T("");
  488.     m_strColumnName         = _T("");
  489.     m_fColumnType           = 0;
  490.     m_nDataType             = 0;
  491.     m_strTypeName           = _T("");
  492.     m_nPrecision            = 0;
  493.     m_nLength               = 0;
  494.     m_nScale                = 0;
  495.     m_nRadix                = 0;
  496.     m_fNullable             = 0;
  497.     m_strRemarks            = _T("");
  498.     m_nFields = 13;
  499. }
  500.  
  501. BOOL CProcedureColumns::Open(LPCSTR pszProcQualifier,
  502.     LPCSTR pszProcOwner,LPCSTR pszProcName,LPCSTR pszColumnName,
  503.     UINT nOpenType)
  504. {
  505.     RETCODE nRetCode;
  506.     UWORD   bFunctionExists;
  507.  
  508.     // Make sure SQLProcedureColumns exists
  509.     AFX_SQL_SYNC(::SQLGetFunctions(m_pDatabase->m_hdbc,
  510.         SQL_API_SQLPROCEDURECOLUMNS,&bFunctionExists));
  511.     if (!Check(nRetCode) || !bFunctionExists)
  512.     {
  513.         if (!bFunctionExists)
  514.             TRACE(_T("SQLProcedureColumns not supported\n"));
  515.         return FALSE;
  516.     }
  517.  
  518.     // Cache stat info and allocate hstmt
  519.     SetState(nOpenType,NULL,readOnly);
  520.     if (!AllocHstmt())
  521.         return FALSE;
  522.  
  523.     TRY
  524.     {
  525.         OnSetOptions(m_hstmt);
  526.         AllocStatusArrays();
  527.  
  528.         // Call the ODBC function
  529.         AFX_ODBC_CALL(::SQLProcedureColumns(m_hstmt,
  530.             (UCHAR FAR*)pszProcQualifier,SQL_NTS,
  531.             (UCHAR FAR*)pszProcOwner,SQL_NTS,
  532.             (UCHAR FAR*)pszProcName,SQL_NTS,
  533.             (UCHAR FAR*)pszColumnName,SQL_NTS));
  534.         if (!Check(nRetCode))
  535.             ThrowDBException(nRetCode,m_hstmt);
  536.  
  537.         // Allocate memory and cache info
  538.         AllocAndCacheFieldInfo();
  539.         AllocRowset();
  540.  
  541.         // Fetch the first row of data
  542.         MoveNext();
  543.  
  544.         // If EOF, result set is empty, set BOF as well
  545.         m_bBOF = m_bEOF;
  546.  
  547.     }
  548.  
  549.     CATCH_ALL(e)
  550.     {
  551.         Close();
  552.         THROW_LAST();
  553.     }
  554.     END_CATCH_ALL
  555.  
  556.     return TRUE;
  557. }
  558.  
  559. void CProcedureColumns::DoFieldExchange(CFieldExchange* pFX)
  560. {
  561.     pFX->SetFieldType(CFieldExchange::outputColumn);
  562.     RFX_Text(pFX,_T("PROCEDURE_QUALIFIER"),m_strProcedureQualifier);
  563.     RFX_Text(pFX,_T("PROCEDURE_OWNER"),m_strProcedureOwner);
  564.     RFX_Text(pFX,_T("PROCEDURE_NAME"),m_strProcedureName);
  565.     RFX_Text(pFX,_T("COLUMN_NAME"),m_strColumnName);
  566.     RFX_Int(pFX,_T("COLUMN_TYPE"),m_fColumnType);
  567.     RFX_Int(pFX,_T("DATA_TYPE"),m_nDataType);
  568.     RFX_Text(pFX,_T("TYPE_NAME"),m_strTypeName);
  569.     RFX_Long(pFX,_T("PRECISION"),m_nPrecision);
  570.     RFX_Long(pFX,_T("LENGTH"),m_nLength);
  571.     RFX_Int(pFX,_T("SCALE"),m_nScale);
  572.     RFX_Int(pFX,_T("RADIX"),m_nRadix);
  573.     RFX_Int(pFX,_T("NULLABLE"),m_fNullable);
  574.     RFX_Text(pFX,_T("REMARKS"),m_strRemarks);
  575. }
  576.  
  577. //---------------------------------------------------------------------
  578. // CProcedures
  579.  
  580. CProcedures::CProcedures(CDatabase* pDatabase)
  581.     : CRecordset(pDatabase)
  582. {
  583.     m_strProcedureQualifier = _T("");
  584.     m_strProcedureOwner     = _T("");
  585.     m_strProcedureName      = _T("");
  586.     m_strRemarks            = _T("");
  587.     m_fProcedureType        = 0;
  588.     m_nFields = 5;
  589. }
  590.  
  591. BOOL CProcedures::Open(LPCSTR pszProcQualifier,
  592.     LPCSTR pszProcOwner,LPCSTR pszProcName,
  593.     UINT nOpenType)
  594. {
  595.     RETCODE nRetCode;
  596.     UWORD   bFunctionExists;
  597.  
  598.     // Make sure SQLProcedures is supported
  599.     AFX_SQL_SYNC(::SQLGetFunctions(m_pDatabase->m_hdbc,
  600.         SQL_API_SQLPROCEDURES,&bFunctionExists));
  601.     if (!Check(nRetCode) || !bFunctionExists)
  602.     {
  603.         if (!bFunctionExists)
  604.             TRACE(_T("SQLProcedures not supported\n"));
  605.         return FALSE;
  606.     }
  607.  
  608.     // Cache state info and allocate hstmt
  609.     SetState(nOpenType,NULL,readOnly);
  610.     if (!AllocHstmt())
  611.         return FALSE;
  612.  
  613.     TRY
  614.     {
  615.         OnSetOptions(m_hstmt);
  616.         AllocStatusArrays();
  617.  
  618.         // Call the ODBC function
  619.         AFX_ODBC_CALL(::SQLProcedures(m_hstmt,
  620.             (UCHAR FAR*)pszProcQualifier,SQL_NTS,
  621.             (UCHAR FAR*)pszProcOwner,SQL_NTS,
  622.             (UCHAR FAR*)pszProcName,SQL_NTS));
  623.         if (!Check(nRetCode))
  624.             ThrowDBException(nRetCode,m_hstmt);
  625.  
  626.         // Allocate memory and cache info
  627.         AllocAndCacheFieldInfo();
  628.         AllocRowset();
  629.  
  630.         // Fetch the first row of data
  631.         MoveNext();
  632.  
  633.         // If EOF, result set is empty, set BOF as well
  634.         m_bBOF = m_bEOF;
  635.  
  636.     }
  637.  
  638.     CATCH_ALL(e)
  639.     {
  640.         Close();
  641.         THROW_LAST();
  642.     }
  643.     END_CATCH_ALL
  644.  
  645.     return TRUE;
  646. }
  647.  
  648. void CProcedures::DoFieldExchange(CFieldExchange* pFX)
  649. {
  650.     pFX->SetFieldType(CFieldExchange::outputColumn);
  651.     RFX_Text(pFX,_T("PROCEDURE_QUALIFIER"),m_strProcedureQualifier);
  652.     RFX_Text(pFX,_T("PROCEDURE_OWNER"),m_strProcedureOwner);
  653.     RFX_Text(pFX,_T("PROCEDURE_NAME"),m_strProcedureName);
  654.     RFX_Text(pFX,_T("REMARKS"),m_strRemarks);
  655.     RFX_Int(pFX,_T("PROCEDURE_TYPE"),m_fProcedureType);
  656. }
  657.  
  658. //---------------------------------------------------------------------
  659. // CSpecialColumns
  660.  
  661. CSpecialColumns::CSpecialColumns(CDatabase* pDatabase)
  662.     : CRecordset(pDatabase)
  663. {
  664.     m_fScope        = 0;
  665.     m_strColumnName = _T("");
  666.     m_nDataType     = 0;
  667.     m_strTypeName   = _T("");
  668.     m_nPrecision    = 0;
  669.     m_nLength       = 0;
  670.     m_nScale        = 0;
  671.     m_fPseudoColumn = 0;
  672.     m_nFields = 8;
  673. }
  674.  
  675. BOOL CSpecialColumns::Open(short fColType,LPCSTR pszTableQualifier,
  676.     LPCSTR pszTableOwner,LPCSTR pszTableName,short fScope,short fNullable,
  677.     UINT nOpenType)
  678. {
  679.     RETCODE nRetCode;
  680.     UWORD   bFunctionExists;
  681.  
  682.     // Make sure SQLSpecialColumns is supported
  683.     AFX_SQL_SYNC(::SQLGetFunctions(m_pDatabase->m_hdbc,
  684.         SQL_API_SQLSPECIALCOLUMNS,&bFunctionExists));
  685.     if (!Check(nRetCode) || !bFunctionExists)
  686.     {
  687.         if (!bFunctionExists)
  688.             TRACE(_T("SQLSpecialColumns not supported\n"));
  689.         return FALSE;
  690.     }
  691.  
  692.     // Cache state info and allocate hstmt
  693.     SetState(nOpenType,NULL,readOnly);
  694.     if (!AllocHstmt())
  695.         return FALSE;
  696.  
  697.     TRY
  698.     {
  699.         OnSetOptions(m_hstmt);
  700.         AllocStatusArrays();
  701.  
  702.         // Call the ODBC function
  703.         AFX_ODBC_CALL(::SQLSpecialColumns(m_hstmt,
  704.             (UWORD)fColType,
  705.             (UCHAR FAR*)pszTableQualifier,SQL_NTS,
  706.             (UCHAR FAR*)pszTableOwner,SQL_NTS,
  707.             (UCHAR FAR*)pszTableName,SQL_NTS,
  708.             (UWORD)fScope,
  709.             (UWORD)fNullable));
  710.         if (!Check(nRetCode))
  711.             ThrowDBException(nRetCode,m_hstmt);
  712.  
  713.         // Allocate memory and cache info
  714.         AllocAndCacheFieldInfo();
  715.         AllocRowset();
  716.  
  717.         // Fetch the first row of data
  718.         MoveNext();
  719.  
  720.         // If EOF, result set is empty, set BOF as well
  721.         m_bBOF = m_bEOF;
  722.  
  723.     }
  724.  
  725.     CATCH_ALL(e)
  726.     {
  727.         Close();
  728.         THROW_LAST();
  729.     }
  730.     END_CATCH_ALL
  731.  
  732.     return TRUE;
  733. }
  734.  
  735. void CSpecialColumns::DoFieldExchange(CFieldExchange* pFX)
  736. {
  737.     pFX->SetFieldType(CFieldExchange::outputColumn);
  738.     RFX_Int(pFX,_T("SCOPE"),m_fScope);
  739.     RFX_Text(pFX,_T("COLUMN_NAME"),m_strColumnName);
  740.     RFX_Int(pFX,_T("DATA_TYPE"),m_nDataType);
  741.     RFX_Text(pFX,_T("TYPE_NAME"),m_strTypeName);
  742.     RFX_Long(pFX,_T("PRECISION"),m_nPrecision);
  743.     RFX_Long(pFX,_T("LENGTH"),m_nLength);
  744.     RFX_Int(pFX,_T("SCALE"),m_nScale);
  745.     RFX_Int(pFX,_T("PSEUDO_COLUMN"),m_fPseudoColumn);
  746. }
  747.  
  748. //---------------------------------------------------------------------
  749. // CStatistics
  750.  
  751. CStatistics::CStatistics(CDatabase* pDatabase)
  752.     : CRecordset(pDatabase)
  753. {
  754.     m_strTableQualifier     = _T("");
  755.     m_strTableOwner         = _T("");
  756.     m_strTableName          = _T("");
  757.     m_fNonUnique            = 0;
  758.     m_strIndexQualifier     = _T("");
  759.     m_strIndexName          = _T("");
  760.     m_fType                 = 0;
  761.     m_nSeqInIndex           = 0;
  762.     m_strColumnName         = _T("");
  763.     m_strCollation          = _T("");
  764.     m_nCardinality          = 0;
  765.     m_nPages                = 0;
  766.     m_strFilterCondition    = _T("");
  767.     m_nFields = 13;
  768. }
  769.  
  770. BOOL CStatistics::Open(LPCSTR pszTableQualifier,
  771.     LPCSTR pszTableOwner,LPCSTR pszTableName,short fUnique,short fAccuracy,
  772.     UINT nOpenType)
  773. {
  774.     RETCODE nRetCode;
  775.     UWORD   bFunctionExists;
  776.  
  777.     // Make sure SQLStatistics is supported
  778.     AFX_SQL_SYNC(::SQLGetFunctions(m_pDatabase->m_hdbc,
  779.         SQL_API_SQLSTATISTICS,&bFunctionExists));
  780.     if (!Check(nRetCode) || !bFunctionExists)
  781.     {
  782.         if (!bFunctionExists)
  783.             TRACE(_T("SQLStatistics not supported\n"));
  784.         return FALSE;
  785.     }
  786.  
  787.     // Cache state info and allocate hstmt
  788.     SetState(nOpenType,NULL,readOnly);
  789.     if (!AllocHstmt())
  790.         return FALSE;
  791.  
  792.     TRY
  793.     {
  794.         OnSetOptions(m_hstmt);
  795.         AllocStatusArrays();
  796.  
  797.         // Call the ODBC function
  798.         AFX_ODBC_CALL(::SQLStatistics(m_hstmt,
  799.             (UCHAR FAR*)pszTableQualifier,SQL_NTS,
  800.             (UCHAR FAR*)pszTableOwner,SQL_NTS,
  801.             (UCHAR FAR*)pszTableName,SQL_NTS,
  802.             (UWORD)fUnique,
  803.             (UWORD)fAccuracy));
  804.         if (!Check(nRetCode))
  805.             ThrowDBException(nRetCode,m_hstmt);
  806.  
  807.         // Allocate memory and cache info
  808.         AllocAndCacheFieldInfo();
  809.         AllocRowset();
  810.  
  811.         // Fetch the first row of data
  812.         MoveNext();
  813.  
  814.         // If EOF, result set is empty, set BOF as well
  815.         m_bBOF = m_bEOF;
  816.  
  817.     }
  818.  
  819.     CATCH_ALL(e)
  820.     {
  821.         Close();
  822.         THROW_LAST();
  823.     }
  824.     END_CATCH_ALL
  825.  
  826.     return TRUE;
  827. }
  828.  
  829. void CStatistics::DoFieldExchange(CFieldExchange* pFX)
  830. {
  831.     pFX->SetFieldType(CFieldExchange::outputColumn);
  832.     RFX_Text(pFX,_T("TABLE_QUALIFIER"),m_strTableQualifier);
  833.     RFX_Text(pFX,_T("TABLE_OWNER"),m_strTableOwner);
  834.     RFX_Text(pFX,_T("TABLE_NAME"),m_strTableName);
  835.     RFX_Int(pFX,_T("NON_UNIQUE"),m_fNonUnique);
  836.     RFX_Text(pFX,_T("INDEX_QUALIFIER"),m_strIndexQualifier);
  837.     RFX_Text(pFX,_T("INDEX_NAME"),m_strIndexName);
  838.     RFX_Int(pFX,_T("TYPE"),m_fType);
  839.     RFX_Int(pFX,_T("SEQ_IN_INDEX"),m_nSeqInIndex);
  840.     RFX_Text(pFX,_T("COLUMN_NAME"),m_strColumnName);
  841.     RFX_Text(pFX,_T("COLLATION"),m_strCollation);
  842.     RFX_Long(pFX,_T("CARDINALITY"),m_nCardinality);
  843.     RFX_Long(pFX,_T("PAGES"),m_nPages);
  844.     RFX_Text(pFX,_T("FILTER_CONDITION"),m_strFilterCondition);
  845. }
  846.  
  847. //---------------------------------------------------------------------
  848. // CTablePrivileges
  849.  
  850. CTablePrivileges::CTablePrivileges(CDatabase* pDatabase)
  851.     : CRecordset(pDatabase)
  852. {
  853.     m_strTableQualifier = _T("");
  854.     m_strTableOwner     = _T("");
  855.     m_strTableName      = _T("");
  856.     m_strGrantor        = _T("");
  857.     m_strGrantee        = _T("");
  858.     m_strPrivilege      = _T("");
  859.     m_strIsGrantable    = _T("");
  860.     m_nFields = 7;
  861. }
  862.  
  863. BOOL CTablePrivileges::Open(LPCSTR pszTableQualifier,
  864.     LPCSTR pszTableOwner,LPCSTR pszTableName,
  865.     UINT nOpenType)
  866. {
  867.     RETCODE nRetCode;
  868.     UWORD   bFunctionExists;
  869.  
  870.     // Make sure SQLTablePrivileges exists
  871.     AFX_SQL_SYNC(::SQLGetFunctions(m_pDatabase->m_hdbc,
  872.         SQL_API_SQLTABLEPRIVILEGES,&bFunctionExists));
  873.     if (!Check(nRetCode) || !bFunctionExists)
  874.     {
  875.         if (!bFunctionExists)
  876.             TRACE(_T("SQLTablePrivileges not supported\n"));
  877.         return FALSE;
  878.     }
  879.  
  880.     // Cache state info and allocate hstmt
  881.     SetState(nOpenType,NULL,readOnly);
  882.     if (!AllocHstmt())
  883.         return FALSE;
  884.  
  885.     TRY
  886.     {
  887.         OnSetOptions(m_hstmt);
  888.         AllocStatusArrays();
  889.  
  890.         // Call the ODBC function
  891.         AFX_ODBC_CALL(::SQLTablePrivileges(m_hstmt,
  892.             (UCHAR FAR*)pszTableQualifier,SQL_NTS,
  893.             (UCHAR FAR*)pszTableOwner,SQL_NTS,
  894.             (UCHAR FAR*)pszTableName,SQL_NTS));
  895.         if (!Check(nRetCode))
  896.             ThrowDBException(nRetCode,m_hstmt);
  897.  
  898.         // Allocate memory and cache info
  899.         AllocAndCacheFieldInfo();
  900.         AllocRowset();
  901.  
  902.         // Fetch the first row of data
  903.         MoveNext();
  904.  
  905.         // If EOF, result set is empty, set BOF as well
  906.         m_bBOF = m_bEOF;
  907.  
  908.     }
  909.  
  910.     CATCH_ALL(e)
  911.     {
  912.         Close();
  913.         THROW_LAST();
  914.     }
  915.     END_CATCH_ALL
  916.  
  917.     return TRUE;
  918. }
  919.  
  920. void CTablePrivileges::DoFieldExchange(CFieldExchange* pFX)
  921. {
  922.     pFX->SetFieldType(CFieldExchange::outputColumn);
  923.     RFX_Text(pFX,_T("TABLE_QUALIFIER"),m_strTableQualifier);
  924.     RFX_Text(pFX,_T("TABLE_OWNER"),m_strTableOwner);
  925.     RFX_Text(pFX,_T("TABLE_NAME"),m_strTableName);
  926.     RFX_Text(pFX,_T("GRANTOR"),m_strGrantor);
  927.     RFX_Text(pFX,_T("GRANTEE"),m_strGrantee);
  928.     RFX_Text(pFX,_T("PRIVILEGE"),m_strPrivilege);
  929.     RFX_Text(pFX,_T("IS_GRANTABLE"),m_strIsGrantable);
  930. }
  931.  
  932. //---------------------------------------------------------------------
  933. // CTables
  934.  
  935. CTables::CTables(CDatabase* pDatabase)
  936.     : CRecordset(pDatabase)
  937. {
  938.     m_strTableQualifier = _T("");
  939.     m_strTableOwner     = _T("");
  940.     m_strTableName      = _T("");
  941.     m_strTableType      = _T("");
  942.     m_strRemarks        = _T("");
  943.     m_nFields = 5;
  944. }
  945.  
  946. BOOL CTables::Open(LPCSTR pszTableQualifier,
  947.     LPCSTR pszTableOwner,LPCSTR pszTableName,LPCSTR pszTableType,
  948.     UINT nOpenType)
  949. {
  950.     RETCODE nRetCode;
  951.     UWORD   bFunctionExists;
  952.  
  953.     // Make sure SQLTables exists
  954.     AFX_SQL_SYNC(::SQLGetFunctions(m_pDatabase->m_hdbc,
  955.         SQL_API_SQLTABLES,&bFunctionExists));
  956.     if (!Check(nRetCode) || !bFunctionExists)
  957.     {
  958.         if (!bFunctionExists)
  959.             TRACE(_T("SQLTables not supported\n"));
  960.         return FALSE;
  961.     }
  962.  
  963.     // Cache state info and allocate hstmt
  964.     SetState(nOpenType,NULL,readOnly);
  965.     if (!AllocHstmt())
  966.         return FALSE;
  967.  
  968.     TRY
  969.     {
  970.         OnSetOptions(m_hstmt);
  971.         AllocStatusArrays();
  972.  
  973.         // Call the ODBC function
  974.         AFX_ODBC_CALL(::SQLTables(m_hstmt,
  975.             (UCHAR FAR*)pszTableQualifier,SQL_NTS,
  976.             (UCHAR FAR*)pszTableOwner,SQL_NTS,
  977.             (UCHAR FAR*)pszTableName,SQL_NTS,
  978.             (UCHAR FAR*)pszTableType,SQL_NTS));
  979.         if (!Check(nRetCode))
  980.             ThrowDBException(nRetCode,m_hstmt);
  981.  
  982.         // Allocate memory and cache info
  983.         AllocAndCacheFieldInfo();
  984.         AllocRowset();
  985.  
  986.         // Fetch the first row of data
  987.         MoveNext();
  988.  
  989.         // If EOF, result set is empty, set BOF as well
  990.         m_bBOF = m_bEOF;
  991.  
  992.     }
  993.  
  994.     CATCH_ALL(e)
  995.     {
  996.         Close();
  997.         THROW_LAST();
  998.     }
  999.     END_CATCH_ALL
  1000.  
  1001.     return TRUE;
  1002. }
  1003.  
  1004. void CTables::DoFieldExchange(CFieldExchange* pFX)
  1005. {
  1006.     pFX->SetFieldType(CFieldExchange::outputColumn);
  1007.     RFX_Text(pFX,_T("TABLE_QUALIFIER"),m_strTableQualifier);
  1008.     RFX_Text(pFX,_T("TABLE_OWNER"),m_strTableOwner);
  1009.     RFX_Text(pFX,_T("TABLE_NAME"),m_strTableName);
  1010.     RFX_Text(pFX,_T("TABLE_TYPE"),m_strTableType);
  1011.     RFX_Text(pFX,_T("REMARKS"),m_strRemarks);
  1012. }
  1013.