⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tableset.cpp

📁 用ODBC对数据库实现连接 显示数据 修改数据
💻 CPP
字号:
// sqltable.cpp : implementation of the CTables 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 "tableset.h"

/////////////////////////////////////////////////////////////////////////////
// CTables implementation

IMPLEMENT_DYNAMIC(CTables, CRecordset)

CTables::CTables(CDatabase* pDatabase)
	: CRecordset(pDatabase)
{
	//{{AFX_FIELD_INIT(CTables)
	m_strQualifier = "";
	m_strOwner = "";
	m_strName = "";
	m_strType = "";
	m_strRemarks = "";
	m_nFields = 5;
	//}}AFX_FIELD_INIT
	m_strQualifierParam = "";
	m_strOwnerParam = "";
	m_strNameParam = "";
	m_strTypeParam = "";
}

BOOL CTables::Open(LPCSTR pszTableQualifier /* = NULL */, LPCSTR pszTableOwner /* = NULL */,LPCSTR pszTableName /* = NULL */,LPCSTR pszTableType /* = NULL */,UINT nOpenType /* = forwardOnly */)
{
	RETCODE nRetCode; 
	UWORD bFunctionExists; 
    //检验是否支持SQLTables函数
	AFX_SQL_SYNC(::SQLGetFunctions(m_pDatabase->m_hdbc,SQL_API_SQLTABLES,&bFunctionExists));
	if (!Check(nRetCode) || !bFunctionExists) 
	{ 
		if (!bFunctionExists) 
			TRACE(_T("SQLTables 不支持\n")); 
		return FALSE; 
	}
	//设置缓冲区状态,分配语句句柄 
	SetState(nOpenType,NULL,readOnly); 
	if (!AllocHstmt()) 
		return FALSE; 
	TRY 
	{ 
		OnSetOptions(m_hstmt); 
		AllocStatusArrays(); 
		//调用 ODBC的SQLTables函数 
		AFX_ODBC_CALL(::SQLTables(m_hstmt, 
			(UCHAR FAR*)pszTableQualifier,SQL_NTS, 
			(UCHAR FAR*)pszTableOwner,SQL_NTS, 
			(UCHAR FAR*)pszTableName,SQL_NTS, 
			(UCHAR FAR*)pszTableType,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 CTables::GetDefaultConnect()
{
	return "ODBC;";
}

CString CTables::GetDefaultSQL()
{
	// should SQLTables directly, so GetSQL should never be called
	ASSERT(FALSE);
	return "!";
}

void CTables::DoFieldExchange(CFieldExchange* pFX)
{
	//{{AFX_FIELD_MAP(CTables)
	pFX->SetFieldType(CFieldExchange::outputColumn);
	RFX_Text(pFX, "table_qualifier", m_strQualifier);
	RFX_Text(pFX, "table_owner", m_strOwner);
	RFX_Text(pFX, "table_name", m_strName);
	RFX_Text(pFX, "table_type", m_strType);
	RFX_Text(pFX, "remarks", m_strRemarks);
	//}}AFX_FIELD_MAP
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -