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 / tableset.cpp < prev    next >
C/C++ Source or Header  |  1998-03-26  |  3KB  |  109 lines

  1. // sqltable.cpp : implementation of the CTables 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 "tableset.h"
  16.  
  17. /////////////////////////////////////////////////////////////////////////////
  18. // CTables implementation
  19.  
  20. IMPLEMENT_DYNAMIC(CTables, CRecordset)
  21.  
  22. CTables::CTables(CDatabase* pDatabase)
  23.     : CRecordset(pDatabase)
  24. {
  25.     //{{AFX_FIELD_INIT(CTables)
  26.     m_strQualifier = "";
  27.     m_strOwner = "";
  28.     m_strName = "";
  29.     m_strType = "";
  30.     m_strRemarks = "";
  31.     m_nFields = 5;
  32.     //}}AFX_FIELD_INIT
  33.     m_strQualifierParam = "";
  34.     m_strOwnerParam = "";
  35.     m_strNameParam = "";
  36.     m_strTypeParam = "";
  37. }
  38.  
  39. BOOL CTables::Open(UINT nOpenType, LPCSTR lpszSQL,
  40.     DWORD dwOptions)
  41. {
  42.     ASSERT(lpszSQL == NULL);
  43.  
  44.     RETCODE nRetCode;
  45.  
  46.     // Cache state info and allocate hstmt
  47.     SetState(nOpenType,NULL,noDirtyFieldCheck);
  48.     if (!AllocHstmt())
  49.         return FALSE;
  50.  
  51.     TRY
  52.     {
  53.         OnSetOptions(m_hstmt);
  54.         AllocStatusArrays();
  55.  
  56.         // call the ODBC catalog function with data member params
  57.         AFX_SQL_ASYNC(this, (::SQLTables)(m_hstmt,
  58.             (m_strQualifierParam.IsEmpty()? (UCHAR FAR *)NULL: (UCHAR FAR *)(const char*)m_strQualifierParam), SQL_NTS,
  59.             (m_strOwnerParam.IsEmpty()? (UCHAR FAR *)NULL: (UCHAR FAR *)(const char*)m_strOwnerParam), SQL_NTS,
  60.             (m_strNameParam.IsEmpty()? (UCHAR FAR *)NULL: (UCHAR FAR *)(const char*)m_strNameParam), SQL_NTS,
  61.             (m_strTypeParam.IsEmpty()? (UCHAR FAR *)NULL: (UCHAR FAR *)(const char*)m_strTypeParam), SQL_NTS));
  62.         if (!Check(nRetCode))
  63.             ThrowDBException(nRetCode, m_hstmt);
  64.  
  65.         // Allocate memory and cache info
  66.         AllocAndCacheFieldInfo();
  67.         AllocRowset();
  68.  
  69.         // Fetch the first row of data
  70.         MoveNext();
  71.  
  72.         // If EOF, result set is empty, set BOF as well
  73.         m_bBOF = m_bEOF;
  74.     }
  75.  
  76.     CATCH_ALL(e)
  77.     {
  78.         Close();
  79.         THROW_LAST();
  80.     }
  81.     END_CATCH_ALL
  82.  
  83.     return TRUE;
  84. }
  85.  
  86. CString CTables::GetDefaultConnect()
  87. {
  88.     return "ODBC;";
  89. }
  90.  
  91. CString CTables::GetDefaultSQL()
  92. {
  93.     // should SQLTables directly, so GetSQL should never be called
  94.     ASSERT(FALSE);
  95.     return "!";
  96. }
  97.  
  98. void CTables::DoFieldExchange(CFieldExchange* pFX)
  99. {
  100.     //{{AFX_FIELD_MAP(CTables)
  101.     pFX->SetFieldType(CFieldExchange::outputColumn);
  102.     RFX_Text(pFX, "table_qualifier", m_strQualifier);
  103.     RFX_Text(pFX, "table_owner", m_strOwner);
  104.     RFX_Text(pFX, "table_name", m_strName);
  105.     RFX_Text(pFX, "table_type", m_strType);
  106.     RFX_Text(pFX, "remarks", m_strRemarks);
  107.     //}}AFX_FIELD_MAP
  108. }
  109.