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

  1. // catsets.cpp - recordsets that describe the type info
  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. // CGetTypeInfo
  18.  
  19. CGetTypeInfo::CGetTypeInfo(CDatabase* pDatabase)
  20.     : CRecordset(pDatabase)
  21. {
  22.     m_strTypeName           = _T("");
  23.     m_fDataType             = 0;
  24.     m_nPrecision            = 0;
  25.     m_strLiteralPrefix      = _T("");
  26.     m_strLiteralSuffix      = _T("");
  27.     m_strCreateParams       = _T("");
  28.     m_fNullable             = 0;
  29.     m_bCaseSensitive        = 0;
  30.     m_fSearchable           = 0;
  31.     m_fUnsignedAttribute    = 0;
  32.     m_bMoney                = 0;
  33.     m_fAutoIncrement        = 0;
  34.     m_strLocalTypeName      = _T("");
  35.     m_nMinimumScale         = 0;
  36.     m_nMaximumScale         = 0;
  37.     m_nFields = 15;
  38. }
  39.  
  40. BOOL CGetTypeInfo::Open(short fSqlType,
  41.     UINT nOpenType)
  42. {
  43.     RETCODE nRetCode;
  44.     UWORD   bFunctionExists;
  45.  
  46.     // make suer SQLGetTypeInfo exists
  47.     AFX_SQL_SYNC(::SQLGetFunctions(m_pDatabase->m_hdbc,
  48.         SQL_API_SQLGETTYPEINFO,&bFunctionExists));
  49.     if (!Check(nRetCode) || !bFunctionExists)
  50.     {
  51.         if (!bFunctionExists)
  52.             TRACE(_T("SQLGetTypeInfo not supported\n"));
  53.         return FALSE;
  54.     }
  55.  
  56.     // Cache state info and allocate hstmt
  57.     SetState(nOpenType, NULL, readOnly);
  58.     if(!AllocHstmt())
  59.         return FALSE;
  60.  
  61.     TRY
  62.     {
  63.         OnSetOptions(m_hstmt);
  64.  
  65.         // Build SQL and prep/execute or just execute direct
  66.         AllocStatusArrays();
  67.  
  68.         // call the ODBC function
  69.         AFX_SQL_ASYNC(this,::SQLGetTypeInfo(m_hstmt,fSqlType));
  70.         if (!Check(nRetCode))
  71.             ThrowDBException(nRetCode,m_hstmt);
  72.  
  73.         // Allocate memory and cache info
  74.         AllocAndCacheFieldInfo();
  75.         AllocRowset();
  76.  
  77.         // Fetch the first row of data
  78.         MoveNext();
  79.  
  80.         // If EOF, then result set empty, so set BOF as well
  81.         m_bBOF = m_bEOF;
  82.     }
  83.     CATCH_ALL(e)
  84.     {
  85.         Close();
  86.         THROW_LAST();
  87.     }
  88.     END_CATCH_ALL
  89.  
  90.     return TRUE;
  91. }
  92.  
  93. void CGetTypeInfo::DoFieldExchange(CFieldExchange* pFX)
  94. {
  95.     pFX->SetFieldType(CFieldExchange::outputColumn);
  96.     RFX_Text(pFX, _T("TYPE_NAME"), m_strTypeName);
  97.     RFX_Int(pFX, _T("DATA_TYPE"), m_fDataType);
  98.     RFX_Long(pFX, _T("PRECISION"), m_nPrecision);
  99.     RFX_Text(pFX, _T("LITERAL_PREFIX"), m_strLiteralPrefix);
  100.     RFX_Text(pFX, _T("LITERAL_SUFFIX"), m_strLiteralSuffix);
  101.     RFX_Text(pFX, _T("CREATE_PARAMS"), m_strCreateParams);
  102.     RFX_Int(pFX, _T("NULLABLE"), m_fNullable);
  103.     RFX_Int(pFX, _T("CASE_SENSITIVE"), m_bCaseSensitive);
  104.     RFX_Int(pFX, _T("SEARCHABLE"), m_fSearchable);
  105.     RFX_Int(pFX, _T("UNSIGNED_ATTRIBUTE"), m_fUnsignedAttribute);
  106.     RFX_Int(pFX, _T("MONEY"), m_bMoney);
  107.     RFX_Int(pFX, _T("AUTO_INCREMENT"), m_fAutoIncrement);
  108.     RFX_Text(pFX, _T("LOCAL_TYPE_NAME"), m_strLocalTypeName);
  109.     RFX_Int(pFX, _T("MINIMUM_SCALE"), m_nMinimumScale);
  110.     RFX_Int(pFX, _T("MAXIMUM_SCALE"), m_nMaximumScale);
  111. }
  112.