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

📄 command.cpp

📁 oledb的例子
💻 CPP
字号:
//---------------------------------------------------------------------------
// Microsoft OLE DB Programmer's Reference Sample
// Copyright (C) 1998 By Microsoft Corporation.
//
// @doc
//
// @module COMMAND.CPP
//
//---------------------------------------------------------------------------
/////////////////////////////////////////////////////////////////
// Includes
//
/////////////////////////////////////////////////////////////////
#include "prsample.h"         // Programmer's Reference Sample includes
/////////////////////////////////////////////////////////////////
// myCreateCommand
//
// This function takes an IUnknown pointer on a session object
// and attempts to create a command object using the session's
// IDBCreateCommand interface. Since this interface is optional,
// this may fail.
//
/////////////////////////////////////////////////////////////////

HRESULT myCreateCommand(IUnknown *           pUnkSession,
												IUnknown **          ppUnkCommand
												)
{
	HRESULT              hr;
	IDBCreateCommand *   pIDBCreateCommand = NULL;

	// Attempt to create a command object from the session object
	XCHECK_HR(hr = pUnkSession->QueryInterface(IID_IDBCreateCommand, (void**)&pIDBCreateCommand));
	XCHECK_HR(hr = pIDBCreateCommand->CreateCommand(
									NULL,                                       // pUnkOuter
									IID_ICommand,                               // riid
									ppUnkCommand                                // ppCommand
									));

CLEANUP:
	if( pIDBCreateCommand )
		pIDBCreateCommand->Release();

	return hr;

}

/////////////////////////////////////////////////////////////////
// myExecuteCommand
//
// This function takes an IUnknown pointer on a command object
// and performs the following steps to create a new rowset
// object:
// - sets the given properties on the command object; these
//   properties will be applied by the provider to any rowset
//   created by this command.
// - sets the given command text for the command.
// - executes the command to create a new rowset object.
//
/////////////////////////////////////////////////////////////////

HRESULT myExecuteCommand(	IUnknown *             pUnkCommand,
													WCHAR *                pwszCommandText,
													ULONG                  cPropSets,
													DBPROPSET*             rgPropSets,
													IUnknown **            ppUnkRowset
													)
{
	HRESULT								hr;
	ICommandText *				pICommandText         = NULL;
	ICommandProperties *	pICommandProperties   = NULL;

	// Set the properties on the command object
	XCHECK_HR(hr = pUnkCommand->QueryInterface(IID_ICommandProperties, (void**)&pICommandProperties));
	XCHECK_HR(hr = pICommandProperties->SetProperties(cPropSets, rgPropSets));

	// Set the text for this command, using the default command text
	// dialect. All providers that support commands must support this
	// dialect, and providers that support SQL must be able to recognize
	// an SQL command as SQL when this dialect is specified.
	XCHECK_HR(hr = pUnkCommand->QueryInterface(IID_ICommandText, (void**)&pICommandText));
	XCHECK_HR(hr = pICommandText->SetCommandText(
											DBGUID_DEFAULT,                        // guidDialect
											pwszCommandText                        // pwszCommandText
											));

	// And execute the command. Note that the user could have
	// entered a non-row returning command, so we will check for
	// that and return failure to prevent the display of the
	// nonexistent rowset by the caller.

	XCHECK_HR(hr = pICommandText->Execute(
										NULL,                              // pUnkOuter
										IID_IRowset,                       // riid
										NULL,                              // pParams
										NULL,                              // pcRowsAffected
										ppUnkRowset                        // ppRowset
										));

	if( !*ppUnkRowset )
	{
		printf("\nThe command executed successfully, but did not " \
						"return a rowset.\nNo rowset will be displayed.\n");
		hr = E_FAIL;
	}

CLEANUP:
	if( pICommandText )
		pICommandText->Release();

	if( pICommandProperties )
		pICommandProperties->Release();

	return hr;

}

⌨️ 快捷键说明

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