home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / STDREG.PAK / TYPEINFO.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  3.9 KB  |  151 lines

  1. // typeinfo.cpp: implementation of the CTypeInfo class
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1992-1995 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.  
  14. #include "stdafx.h"
  15. #include "typeinfo.h"
  16.  
  17. /////////////////////////////////////////////////////////////////////////////
  18. // CTypeInfo implementation
  19.  
  20. IMPLEMENT_DYNAMIC(CTypeInfo, CRecordset)
  21.  
  22. CTypeInfo::CTypeInfo(CDatabase* pDatabase)
  23.     : CRecordset(pDatabase)
  24. {
  25.     //{{AFX_FIELD_INIT(CTypeInfo)
  26.     m_strTypeName = "";
  27.     m_nDataType = 0;
  28.     m_lPrecision = 0;
  29.     m_strLiteralPrefix = "";
  30.     m_strLiteralSuffix = "";
  31.     m_strCreateParams = "";
  32.     m_nNullable = 0;
  33.     m_nCaseSensitive = 0;
  34.     m_nSearchable = 0;
  35.     m_nUnsignedAttribute = 0;
  36.     m_nMoney = 0;
  37.     m_nAutoIncrement = 0;
  38.     m_strLocalTypeName = "";
  39.     m_nMinimumScale = 0;
  40.     m_nMaximumScale = 0;
  41.     m_nFields = 15;
  42.     //}}AFX_FIELD_INIT
  43. }
  44.  
  45. BOOL CTypeInfo::Open(UINT /* nOpenType = snapshot */,
  46.     LPCSTR lpszSQL /* = NULL */, DWORD /* dwOptions = none */)
  47. {
  48.     RETCODE nRetCode;
  49.     ASSERT(lpszSQL == NULL);
  50.     lpszSQL;    // not used in release builds
  51.  
  52.     // Allocation and opening of database not supported
  53.     if (m_hstmt == SQL_NULL_HSTMT)
  54.     {
  55.         CString strDefaultConnect;
  56.         TRY
  57.         {
  58.             if (m_pDatabase == NULL)
  59.             {
  60.                 m_pDatabase = new CDatabase();
  61.                 m_bRecordsetDb = TRUE;
  62.             }
  63.  
  64.             strDefaultConnect = GetDefaultConnect();
  65.             // If not already opened, attempt to open
  66.             if (!m_pDatabase->IsOpen() &&
  67.                 !m_pDatabase->Open("", FALSE, FALSE, strDefaultConnect))
  68.                 return FALSE;
  69.  
  70.             AFX_SQL_SYNC(::SQLAllocStmt(m_pDatabase->m_hdbc, &m_hstmt));
  71.             if (!Check(nRetCode))
  72.                 ThrowDBException(SQL_INVALID_HANDLE);
  73.         }
  74.         CATCH_ALL(e)
  75.         {
  76. #ifdef _DEBUG
  77.             if (afxTraceFlags & 0x20)
  78.                 TRACE0("Error: CDatabase create for CRecordset failed\n");
  79. #endif // _DEBUG
  80.             strDefaultConnect.Empty();
  81.             if (m_bRecordsetDb)
  82.             {
  83.                 delete m_pDatabase;
  84.                 m_pDatabase = NULL;
  85.             }
  86.             ASSERT(m_hstmt == SQL_NULL_HSTMT);
  87.             THROW_LAST();
  88.         }
  89.         END_CATCH_ALL
  90.     }
  91.  
  92.     TRY
  93.     {
  94.         // set any options, like timeouts, scrolling options
  95.         OnSetOptions(m_hstmt);
  96.  
  97.  
  98.         // call the ODBC catalog function with data member params
  99.         RETCODE nRetCode;
  100.         AFX_SQL_ASYNC(this, ::SQLGetTypeInfo(m_hstmt, m_fSqlTypeParam));
  101.         if (!Check(nRetCode))
  102.         {
  103.             AfxThrowDBException(nRetCode, m_pDatabase, m_hstmt);
  104.         }
  105.         // load first record
  106.         MoveFirst();
  107.     }
  108.     CATCH_ALL(e)
  109.     {
  110.         Close();
  111.         THROW_LAST();
  112.     }
  113.     END_CATCH_ALL
  114.     return TRUE;
  115. }
  116.  
  117. CString CTypeInfo::GetDefaultConnect()
  118. {
  119.     // this minimal connect string will cause ODBC login dialog to be brought up
  120.     return "ODBC;";
  121. }
  122.  
  123. CString CTypeInfo::GetDefaultSQL()
  124. {
  125.     // there is no default SQL - a direct ODBC call is made instead
  126.     ASSERT(FALSE);
  127.     return "!";
  128. }
  129.  
  130. void CTypeInfo::DoFieldExchange(CFieldExchange* pFX)
  131. {
  132.     //{{AFX_FIELD_MAP(CTypeInfo)
  133.     pFX->SetFieldType(CFieldExchange::outputColumn);
  134.     RFX_Text(pFX, "type_name", m_strTypeName);
  135.     RFX_Int(pFX, "data_type", m_nDataType);
  136.     RFX_Long(pFX, "precision", m_lPrecision);
  137.     RFX_Text(pFX, "literal_prefix", m_strLiteralPrefix);
  138.     RFX_Text(pFX, "literal_suffix", m_strLiteralSuffix);
  139.     RFX_Text(pFX, "create_params", m_strCreateParams);
  140.     RFX_Int(pFX, "nullable", m_nNullable);
  141.     RFX_Int(pFX, "case_sensitive", m_nCaseSensitive);
  142.     RFX_Int(pFX, "searchable", m_nSearchable);
  143.     RFX_Int(pFX, "unsigned_attribute", m_nUnsignedAttribute);
  144.     RFX_Int(pFX, "money", m_nMoney);
  145.     RFX_Int(pFX, "auto_increment", m_nAutoIncrement);
  146.     RFX_Text(pFX, "local_type_name", m_strLocalTypeName);
  147.     RFX_Int(pFX, "minimum_scale", m_nMinimumScale);
  148.     RFX_Int(pFX, "maximum_scale", m_nMaximumScale);
  149.     //}}AFX_FIELD_MAP
  150. }
  151.