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

SQL Server

开发平台:

Visual C++

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