Tables.cpp
上传用户:jsxglz
上传日期:2007-01-03
资源大小:117k
文件大小:3k
源码类别:

SQL Server

开发平台:

Visual C++

  1. // Tables.cpp: implementation of the CTables class.
  2. //
  3. #include "stdafx.h"
  4. #include "interactivesql.h"
  5. #include "Tables.h"
  6. #ifdef _DEBUG
  7. #undef THIS_FILE
  8. static char THIS_FILE[]=__FILE__;
  9. #define new DEBUG_NEW
  10. #endif
  11. //////////////////////////////////////////////////////////////////////
  12. // Construction/Destruction
  13. IMPLEMENT_DYNAMIC(CTables, CRecordsetEx)
  14. CTables::CTables(CDatabase* pDatabase)
  15. : CRecordsetEx(pDatabase)
  16. {
  17. m_strTableQualifier = _T("");
  18. m_strTableOwner     = _T("");
  19. m_strTableName      = _T("");
  20. m_strTableType      = _T("");
  21. m_strRemarks        = _T("");
  22. m_nFields = 5;
  23. }
  24. BOOL CTables::Open(LPCSTR pszTableQualifier,
  25. LPCSTR pszTableOwner, LPCSTR pszTableName ,LPCSTR pszTableType,
  26. UINT nOpenType)
  27. {
  28. RETCODE nRetCode;
  29. UWORD   bFunctionExists;
  30. // Make sure SQLTables exists
  31. AFX_SQL_SYNC(::SQLGetFunctions(m_pDatabase->m_hdbc,
  32. SQL_API_SQLTABLES,&bFunctionExists));
  33. if(!Check(nRetCode))
  34. AfxThrowDBException(nRetCode, m_pDatabase, m_hstmt);
  35. if(!bFunctionExists)
  36. throw "<::SQLTables> not supported.";
  37. // Cache state info and allocate hstmt
  38. SetState(nOpenType,NULL,readOnly);
  39. if (!AllocHstmt())
  40. return FALSE;
  41. TRY
  42. {
  43. OnSetOptions(m_hstmt);
  44. AllocStatusArrays();
  45. // Call the ODBC function
  46. AFX_ODBC_CALL(::SQLTables(m_hstmt,
  47. (UCHAR FAR*)pszTableQualifier,SQL_NTS,
  48. (UCHAR FAR*)pszTableOwner,SQL_NTS,
  49. (UCHAR FAR*)pszTableName,SQL_NTS,
  50. (UCHAR FAR*)pszTableType,SQL_NTS));
  51. if (!Check(nRetCode))
  52. ThrowDBException(nRetCode,m_hstmt);
  53. // Allocate memory and cache info
  54. AllocAndCacheFieldInfo();
  55. AllocRowset();
  56. // Fetch the first row of data
  57. MoveNext();
  58. // If EOF, result set is empty, set BOF as well
  59. m_bBOF = m_bEOF;
  60. }
  61. CATCH_ALL(e)
  62. {
  63. Close();
  64. THROW_LAST();
  65. }
  66. END_CATCH_ALL
  67. return TRUE;
  68. }
  69. void CTables::DoFieldExchange(CFieldExchange* pFX)
  70. {
  71. pFX->SetFieldType(CFieldExchange::outputColumn);
  72. RFX_Text(pFX,_T("TABLE_QUALIFIER"),m_strTableQualifier);
  73. RFX_Text(pFX,_T("TABLE_OWNER"),m_strTableOwner);
  74. RFX_Text(pFX,_T("TABLE_NAME"),m_strTableName);
  75. RFX_Text(pFX,_T("TABLE_TYPE"),m_strTableType);
  76. RFX_Text(pFX,_T("REMARKS"),m_strRemarks);
  77. }
  78. CString CTables::GetDefaultConnect()
  79. return _T("ODBC;");
  80. }
  81. CString CTables::GetDefaultSQL()
  82. return "!"; // Direct ODBC call
  83. }
  84. /////////////////////////////////////////////////////////////////////////////
  85. // CTables diagnostics
  86. #ifdef _DEBUG
  87. void CTables::AssertValid() const
  88. {
  89. CRecordsetEx::AssertValid();
  90. }
  91. void CTables::Dump(CDumpContext& dc) const
  92. {
  93. CRecordsetEx::Dump(dc);
  94. }
  95. #endif //_DEBUG