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

📄 session.cpp

📁 oledb的例子
💻 CPP
字号:
//---------------------------------------------------------------------------
// Microsoft OLE DB Programmer's Reference Sample
// Copyright (C) 1998 By Microsoft Corporation.
//
// @doc
//
// @module SESSION.CPP
//
//---------------------------------------------------------------------------
/////////////////////////////////////////////////////////////////
// Includes
//
/////////////////////////////////////////////////////////////////
#include "prsample.h"      // Programmer's Reference Sample includes
/////////////////////////////////////////////////////////////////
// myCreateSession
//
// Create an OLE DB session object from the given data source
// object. The IDBCreateSession interface is mandatory, so this
// is a simple operation.
//
/////////////////////////////////////////////////////////////////
HRESULTmyCreateSession(
												IUnknown *           pUnkDataSource,
												IUnknown **          ppUnkSession
												)
{
	HRESULT              hr;
	IDBCreateSession *   pIDBCreateSession= NULL;
	//Create a session object from a data source object
	XCHECK_HR(hr = pUnkDataSource->QueryInterface(IID_IDBCreateSession, (void**)&pIDBCreateSession));
	XCHECK_HR(hr = pIDBCreateSession->CreateSession(
									NULL,                                   // pUnkOuter
									IID_IOpenRowset,                        // riid
									ppUnkSession                            // ppSession
									));
CLEANUP:
	if( pIDBCreateSession )
		pIDBCreateSession->Release();
	return hr;
}
/////////////////////////////////////////////////////////////////
// myCreateSchemaRowset
//
// If the provider supports IDBSchemaRowset, this function will
// obtain the tables schema rowset, will display this rowset to
// the user, and will allow the user to select a row in the
// rowset containing the name of a table of interest
//
/////////////////////////////////////////////////////////////////

HRESULTmyCreateSchemaRowset(
														GUID                guidSchema, 
														IUnknown *          pUnkSession, 
														ULONG               cchBuffer, 
														LPWSTR              pwszBuffer
														)
{
	HRESULT             hr                 = S_OK;
	IDBSchemaRowset *   pIDBSchemaRowset   = NULL;
	IUnknown *          pUnkRowset         = NULL;
	const ULONG         cProperties        = 2;
	DBPROP              rgProperties[cProperties];
	DBPROPSET           rgPropSets[1];
	// Attempt to obtain the IDBSchemaRowset interface on the session 
	// object. This is not a mandatory interface; if it is not supported, 
	// we are done.
	CHECK_HR(pUnkSession->QueryInterface(IID_IDBSchemaRowset, (void**)&pIDBSchemaRowset));
	// Set properties on the rowset, to request additional functionality
	myAddRowsetProperties(rgPropSets, cProperties, rgProperties);
	// Get the requested schema rowset. If IDBSchemaRowset is supported,
	// the following schema rowsets are required to be supported:
	// DBSCHEMA_TABLES, DBSCHEMA_COLUMNS, and DBSCHEMA_PROVIDERTYPES
	// We know that we will be asking for one of these, so it is not
	// necessary to call IDBSchemaRowset::GetSchemas in this case.
	XCHECK_HR(hr = pIDBSchemaRowset->GetRowset(
									NULL,                              // pUnkOuter
									guidSchema,                        // guidSchema
									0,                                 // cRestrictions
									NULL,                              // rgRestrictions
									IID_IRowset,                       // riid
									1,                                 // cPropSets
									rgPropSets,                        // rgPropSets
									&pUnkRowset                        // ppRowset
									));

	// Display the rowset to the user. This will allow the user to
	// perform basic navigation of the rowset and will allow the user
	// to select a row containing a desired table name (taken from the
	// TABLE_NAME column).
	CHECK_HR(hr = myDisplayRowset(pUnkRowset, L"TABLE_NAME", cchBuffer, pwszBuffer));
CLEANUP:
	if( pIDBSchemaRowset )
		pIDBSchemaRowset->Release();
	if( pUnkRowset )
		pUnkRowset->Release();
	return hr;
}

⌨️ 快捷键说明

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