Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to bind parameters for CCommand<CDynamicParameterAccessor,CRowset,CMultipleResults>? HELP!

337 views
Skip to first unread message

Iwan Jahja

unread,
Jul 31, 2000, 3:00:00 AM7/31/00
to
I managed to get this far:

// in SQL: create procedure getCustomer @custId int as select * from
customer where custid = @custId

// usual CDataSource & CSession initialization ......................
CCommand<CDynamicParameterAccessor,CRowset,CMultipleResults> cmd;
const ULONG nParams = 1;
DBPARAMBINDINFO dbParamBindInfo[nParams] =
{
L"DBTYPE_I4", L"@custId", sizeof(int), DBPARAMFLAGS_ISINPUT, 10, 0
};
ULONG ParamOrdinals[nParams] = {1};
void *pDummy;
typedef struct tagGetParams
{
int lCustId;
} SGetParams;

hr = cmd.Create(session,"{ CALL getCustomer (?) }");
hr = cmd.SetParameterInfo(nParams,ParamOrdinals,dbParamBindInfo);
dbBinding[0].obLength = 0;
dbBinding[0].obStatus = 0;
dbBinding[0].pTypeInfo = NULL;
dbBinding[0].pObject = NULL;
dbBinding[0].pBindExt = NULL;
dbBinding[0].dwPart = DBPART_VALUE;
dbBinding[0].dwMemOwner = DBMEMOWNER_CLIENTOWNED;
dbBinding[0].dwFlags = 0;
dbBinding[0].bScale = 0;
dbBinding[0].iOrdinal = 1;
dbBinding[0].obValue = offsetof(SGetParams,lCustId);
dbBinding[0].eParamIO = DBPARAMIO_INPUT;
dbBinding[0].cbMaxLen = sizeof(int);
dbBinding[0].wType = DBTYPE_I4;
dbBinding[0].bPrecision = 10;

// ????? NEED HELP IN SETTING UP PARAMETER ACCESSOR

hr =
cmd.BindParameters(&cmd.m_hParameterAccessor,cmd.m_spCommand,&pDummy);
cmd.SetParam((ULONG)1,&custId);
hr = cmd.Open(NULL,NULL,0);

//--------------------------------------------------------------------------
-----

I'm basically stuck at steps 3 & 4 of "Calling a stored procedure (OLE DB)"
at
http://msdn.microsoft.com/library/psdk/dasdk/9_ol3ewp.htm

And I don't want to call cmd.Prepare() in order to save a roundtrip. Also,
is
there a macro that can make life easier here?

Thanks for any help.
Iwan

iro...@my-deja.com

unread,
Aug 8, 2000, 3:00:00 AM8/8/00
to
Depending on what you need to accomplish, CDynamicParameterAccessor
does a lot of what you're attempting to do below automatically:
__________________________________

CCommand<CDynamicParameterAccessor,CRowset,CMultipleResults> *prs;
prs = new CCommand<CDynamicParameterAccessor,CRowset,CMultipleResults>;

hr = prs->Create( m_Session, bstrCommandText );
void* pParamBuf;

if( SUCCEEDED(hr) )
hr = prs->Prepare( 100 );
// Bind the parameters.
if( SUCCEEDED(hr) )
hr = prs->BindParameters( &prs->m_hParameterAccessor,
prs->m_spCommand, &pParamBuf );
_________________________________

This assumes that their are no parameterized sub-queries in the stored
procedure. I'm hoping that if you don't call SetParam(...) for a
particular parameter that it will treat that parameter as NULL, but I
haven't tried it yet.

On the other hand if you *need* to build the parameters by hand I've
done that before (it's more efficient), so repost with your needs if
so. Good luck, and I'll be paying sporatic attention to this group for
a week or two more.

Ivo Roper
Senior C++ Consultant
MemeHive, LLP

In article <#6Mlb$z#$GA....@cppssbbsa02.microsoft.com>,


Sent via Deja.com http://www.deja.com/
Before you buy.

kenbr...@my-deja.com

unread,
Aug 25, 2000, 3:00:00 AM8/25/00
to
What does "This assumes that their are no parameterized sub-queries in
the stored procedure. " mean? What should one do if there is one?


In article <8mpt1t$gvb$1...@nnrp1.deja.com>,

0 new messages