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

  1. // sqlcols.cpp: implementation of the CColumns class
  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.  
  14. #include "stdafx.h"
  15. #include "columnst.h"
  16.  
  17. /////////////////////////////////////////////////////////////////////////////
  18. // CColumns implementation
  19.  
  20. IMPLEMENT_DYNAMIC(CColumns, CRecordset)
  21.  
  22. CColumns::CColumns(CDatabase* pDatabase)
  23.     : CRecordset(pDatabase)
  24. {
  25.     //{{AFX_FIELD_INIT(CColumns)
  26.     m_strQualifier = "";
  27.     m_strOwner = "";
  28.     m_strTableName = "";
  29.     m_strColumnName = "";
  30.     m_nDataType = 0;
  31.     m_strTypeName = "";
  32.     m_lPrecision = 0;
  33.     m_lLength = 0;
  34.     m_nScale = 0;
  35.     m_nRadix = 0;
  36.     m_nFields = 11;
  37.     //}}AFX_FIELD_INIT
  38.     m_strQualifierParam = "";
  39.     m_strOwnerParam = "";
  40.     m_strTableNameParam = "";
  41.     m_strColumnNameParam = "";
  42. }
  43.  
  44. BOOL CColumns::Open(UINT nOpenType, LPCSTR lpszSQL, DWORD dwOptions)
  45. {
  46.     ASSERT(lpszSQL == NULL);
  47.  
  48.     RETCODE nRetCode;
  49.  
  50.     // Cache state info and allocate hstmt
  51.     SetState(nOpenType,NULL,noDirtyFieldCheck | dwOptions);
  52.     if (!AllocHstmt())
  53.         return FALSE;
  54.  
  55.     TRY
  56.     {
  57.         OnSetOptions(m_hstmt);
  58.         AllocStatusArrays();
  59.  
  60.         // call the ODBC catalog function with data member params
  61.         AFX_SQL_ASYNC(this, ::SQLColumns(m_hstmt,
  62.             (m_strQualifierParam.IsEmpty()? (UCHAR FAR *)NULL: (UCHAR FAR *)(const char*)m_strQualifierParam), SQL_NTS,
  63.             (m_strOwnerParam.IsEmpty()? (UCHAR FAR *)NULL: (UCHAR FAR *)(const char*)m_strOwnerParam), SQL_NTS,
  64.             (m_strTableNameParam.IsEmpty()? (UCHAR FAR *)NULL: (UCHAR FAR *)(const char*)m_strTableNameParam), SQL_NTS,
  65.             NULL, 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. CString CColumns::GetDefaultConnect()
  91. {
  92.     // this minimal connect string will cause ODBC login dialog to be brought up
  93.     return "ODBC;";
  94. }
  95.  
  96. CString CColumns::GetDefaultSQL()
  97. {
  98.     // there is no default SQL - a direct ODBC call is made instead
  99.     ASSERT(FALSE);
  100.     return "!";
  101. }
  102.  
  103. void CColumns::DoFieldExchange(CFieldExchange* pFX)
  104. {
  105.     //{{AFX_FIELD_MAP(CColumns)
  106.     pFX->SetFieldType(CFieldExchange::outputColumn);
  107.     RFX_Text(pFX, "table_qualifier", m_strQualifier);
  108.     RFX_Text(pFX, "table_owner", m_strOwner);
  109.     RFX_Text(pFX, "table_name", m_strTableName);
  110.     RFX_Text(pFX, "column_name", m_strColumnName);
  111.     RFX_Int(pFX, "data_type", m_nDataType);
  112.     RFX_Text(pFX, "type_name", m_strTypeName);
  113.     RFX_Long(pFX, "precision", m_lPrecision);
  114.     RFX_Long(pFX, "length", m_lLength);
  115.     RFX_Int(pFX, "scale", m_nScale);
  116.     RFX_Int(pFX, "radix", m_nRadix);
  117.     RFX_Int(pFX, "nullable", m_nNullable);
  118.     //}}AFX_FIELD_MAP
  119. }
  120.