📄 columnst.cpp
字号:
// sqlcols.cpp: implementation of the CColumns class
//
// This is a part of the Microsoft Foundation Classes C++ library.
// Copyright (C) 1992-1998 Microsoft Corporation
// All rights reserved.
//
// This source code is only intended as a supplement to the
// Microsoft Foundation Classes Reference and related
// electronic documentation provided with the library.
// See these sources for detailed information regarding the
// Microsoft Foundation Classes product.
#include "stdafx.h"
#include "columnst.h"
/////////////////////////////////////////////////////////////////////////////
// CColumns implementation
IMPLEMENT_DYNAMIC(CColumns, CRecordset)
CColumns::CColumns(CDatabase* pDatabase)
: CRecordset(pDatabase)
{
//{{AFX_FIELD_INIT(CColumns)
m_strQualifier = "";
m_strOwner = "";
m_strTableName = "";
m_strColumnName = "";
m_nDataType = 0;
m_strTypeName = "";
m_lPrecision = 0;
m_lLength = 0;
m_nScale = 0;
m_nRadix = 0;
m_nFields = 11;
//}}AFX_FIELD_INIT
m_strQualifierParam = "";
m_strOwnerParam = "";
m_strTableNameParam = "";
m_strColumnNameParam = "";
}
BOOL CColumns::Open(LPCSTR pszTableQualifier /* = NULL */, LPCSTR pszTableOwner /* = NULL */,LPCSTR pszTableName /* = NULL */,LPCSTR pszColumnName /* = NULL */,UINT nOpenType /* = forwardOnly */)
{
RETCODE nRetCode;
UWORD bFunctionExists;
//检验是否支持SQLColumns函数
AFX_SQL_SYNC(::SQLGetFunctions(m_pDatabase->m_hdbc,SQL_API_SQLCOLUMNS,&bFunctionExists));
if (!Check(nRetCode) || !bFunctionExists)
{
if (!bFunctionExists)
TRACE(_T("SQLColumns 不支持\n"));
return FALSE;
}
//设置缓冲区状态,分配语句句柄
SetState(nOpenType,NULL,readOnly);
if (!AllocHstmt())
return FALSE;
TRY
{
OnSetOptions(m_hstmt);
AllocStatusArrays();
// 调用ODBC的SQLColumns函数
AFX_ODBC_CALL(::SQLColumns(m_hstmt,
(UCHAR FAR*)pszTableQualifier,SQL_NTS,
(UCHAR FAR*)pszTableOwner,SQL_NTS,
(UCHAR FAR*)pszTableName,SQL_NTS,
(UCHAR FAR*)pszColumnName,SQL_NTS));
if (!Check(nRetCode))
ThrowDBException(nRetCode,m_hstmt);
// 分配内存,填写信息
AllocAndCacheFieldInfo();
AllocRowset();
MoveNext();
m_bBOF = m_bEOF;
}
//异常信息的捕获
CATCH_ALL(e)
{
Close();
THROW_LAST();
}
END_CATCH_ALL
return TRUE;
}
CString CColumns::GetDefaultConnect()
{
// this minimal connect string will cause ODBC login dialog to be brought up
return "ODBC;";
}
CString CColumns::GetDefaultSQL()
{
// there is no default SQL - a direct ODBC call is made instead
ASSERT(FALSE);
return "!";
}
void CColumns::DoFieldExchange(CFieldExchange* pFX)
{
//{{AFX_FIELD_MAP(CColumns)
pFX->SetFieldType(CFieldExchange::outputColumn);
RFX_Text(pFX, "table_qualifier", m_strQualifier);
RFX_Text(pFX, "table_owner", m_strOwner);
RFX_Text(pFX, "table_name", m_strTableName);
RFX_Text(pFX, "column_name", m_strColumnName);
RFX_Int(pFX, "data_type", m_nDataType);
RFX_Text(pFX, "type_name", m_strTypeName);
RFX_Long(pFX, "precision", m_lPrecision);
RFX_Long(pFX, "length", m_lLength);
RFX_Int(pFX, "scale", m_nScale);
RFX_Int(pFX, "radix", m_nRadix);
RFX_Int(pFX, "nullable", m_nNullable);
//}}AFX_FIELD_MAP
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -