/////////////////////////////////////////////////////////////////
// myGetProperty
//
//	This function gets the BOOL value for the specified property
//	and returns the result in *pbValue.
//
/////////////////////////////////////////////////////////////////
HRESULT myGetProperty
	(
	IUnknown *				pIUnknown, 
	REFIID					riid, 
	DBPROPID				dwPropertyID, 
	REFGUID					guidPropertySet, 
	BOOL *					pbValue
	)
{
	HRESULT					hr;
	DBPROPID				rgPropertyIDs[1];
	DBPROPIDSET				rgPropertyIDSets[1];
	
	ULONG					cPropSets					= 0;
	DBPROPSET *				rgPropSets					= NULL;

	IDBProperties *			pIDBProperties				= NULL;
	ISessionProperties *	pISesProps					= NULL;
	ICommandProperties *	pICmdProps					= NULL;
	IRowsetInfo *			pIRowsetInfo				= NULL;

	// Initialize the output value
	*pbValue = FALSE;

	// Set up the property ID array
	rgPropertyIDs[0] = dwPropertyID;
	
	// Set up the Property ID Set
	rgPropertyIDSets[0].rgPropertyIDs	= rgPropertyIDs;
	rgPropertyIDSets[0].cPropertyIDs	= 1;
	rgPropertyIDSets[0].guidPropertySet	= guidPropertySet;

	// Get the property value for this property from the provider, but
	// don't try to display extended error information, since this may
	// not be a supported property: a failure is, in fact, expected if
	// the property is not supported
	if( riid == IID_IDBProperties )
	{
		XCHECK_HR(hr = pIUnknown->QueryInterface(IID_IDBProperties, 
					(void**)&pIDBProperties));
		CHECK_HR(hr = pIDBProperties->GetProperties(
					1,					//cPropertyIDSets
					rgPropertyIDSets,	//rgPropertyIDSets
					&cPropSets,			//pcPropSets
					&rgPropSets			//prgPropSets
					));
	}
	else if( riid == IID_ISessionProperties )
	{
		XCHECK_HR(hr = pIUnknown->QueryInterface(IID_ISessionProperties, 
					(void**)&pISesProps));
		CHECK_HR(hr = pISesProps->GetProperties(
					1,					//cPropertyIDSets
					rgPropertyIDSets,	//rgPropertyIDSets
					&cPropSets,			//pcPropSets
					&rgPropSets			//prgPropSets
					));
	}
	else if( riid == IID_ICommandProperties )
	{
		XCHECK_HR(hr = pIUnknown->QueryInterface(IID_ICommandProperties, 
					(void**)&pICmdProps));
		CHECK_HR(hr = pICmdProps->GetProperties(
					1,					//cPropertyIDSets
					rgPropertyIDSets,	//rgPropertyIDSets
					&cPropSets,			//pcPropSets
					&rgPropSets			//prgPropSets
					));
	}
	else
	{
		XCHECK_HR(hr = pIUnknown->QueryInterface(IID_IRowsetInfo, 
					(void**)&pIRowsetInfo));
		CHECK_HR(hr = pIRowsetInfo->GetProperties(
					1,					//cPropertyIDSets
					rgPropertyIDSets,	//rgPropertyIDSets
					&cPropSets,			//pcPropSets
					&rgPropSets			//prgPropSets
					));
	}

	// Return the value for this property to the caller if
	// it's a VT_BOOL type value, as expected
	if( V_VT(&rgPropSets[0].rgProperties[0].vValue) == VT_BOOL )
		*pbValue = V_BOOL(&rgPropSets[0].rgProperties[0].vValue);

CLEANUP:
	if( rgPropSets )
	{
		CoTaskMemFree(rgPropSets[0].rgProperties);
		CoTaskMemFree(rgPropSets);
	}
	if( pIDBProperties )
		pIDBProperties->Release();
	if( pISesProps )
		pISesProps->Release();
	if( pICmdProps )
		pICmdProps->Release();
	if( pIRowsetInfo )
		pIRowsetInfo->Release();
	return hr;
}
Esempio n. 2
0
/*****************************************************************************
 * SELECT系のクエリを実行します。
 * SELECTの結果はDbSqlCeDataReaderクラスを実行して取得してください。
 *****************************************************************************/
DbSqlCeDataReader* DbSqlCeClient::exetute_select(const TCHAR *query)
{
	HRESULT hr;
	LONG lRows = 0;
	IRowsetPosition *pRowsetPos = NULL;
	ICommandProperties *pICmdProps = NULL;
	DBPROPSET dbPropSet[1] = {0};
	DBPROP    dbProps[1] = {0};

	try{
		// クエリ設定
		hr = m_pCmdtext->SetCommandText( DBGUID_DBSQL, query );
		if( FAILED( hr ) )		throw(-1);

		hr = m_pCmdtext->QueryInterface(IID_ICommandProperties, (void**) &pICmdProps);
		if( FAILED( hr ) )		throw(-1);

		dbProps[0].dwPropertyID   = DBPROP_CANFETCHBACKWARDS;
		dbProps[0].dwOptions      = DBPROPOPTIONS_REQUIRED;
		dbProps[0].vValue.vt      = VT_BOOL;
		dbProps[0].vValue.boolVal = VARIANT_TRUE;

		dbPropSet[0].cProperties = 1;
		dbPropSet[0].rgProperties = dbProps;
		dbPropSet[0].guidPropertySet = DBPROPSET_ROWSET;

		hr = pICmdProps->SetProperties(ARRAYSIZE(dbPropSet), dbPropSet);
		if( FAILED( hr ) ){
			throw(-1);
		}
		else{
			pICmdProps->Release();
			pICmdProps = NULL;
		}

		// クエリ実行
		hr = m_pCmdtext->Execute( NULL, IID_IRowsetPosition, NULL, NULL, (IUnknown**)&pRowsetPos );
		if( FAILED( hr ) )		throw(-2);


		// リーダー作成。
		m_pReader = new DbSqlCeDataReader( pRowsetPos );
		if( NULL == m_pReader )	throw(-3);

		// 初期化が正常終了したか確認します。
		if( false == m_pReader->m_IsInit ){
			throw(-4);
		}
	}
	catch(...){
        if( m_pReader ){
            delete m_pReader;
            m_pReader = NULL;
        }
		if( pICmdProps )	pICmdProps->Release();
		if( pRowsetPos )	pRowsetPos->Release();

		return NULL;
	}
	

	return m_pReader;
}