Link to home
Start Free TrialLog in
Avatar of eric07
eric07

asked on

How to return these variables

I would like to create a function like this which works on sql api:

char szName[10];
int nCount;

...
SQLBindCol( hStmt, 1, SQL_C_CHAR, szName, sizeof( szName ), NULL );
SQLBindCol( hStmt, 2, SQL_LONG, &nCount, 0, NULL );
SQLFetch( ... );

The variables szName & nCount is not assigned until SQLFetch() is called.  How is the function able to send this values back to me?  Can someone write a small sample for the two on how it does this.

Thanks
Avatar of zebada
zebada

Hi Eric,

The two bind calls pass in the address of szName and nCount.  These addresses are
saved inside the data structure called hStmt. This "saving" of the variable's address
is called bindind which is why the function is called SQLBindCol().

I presume the SQLFetch() function requires you to also pass in hStmt.

When the SQLFetch() function is called the function "knows" the addresses of the two
'C' variables (szName and nCount) since they were "bound" to the hStmt previously.
The SQLFetch() function is then able to store data at those addresses, and limited
by the "size" of the variables. Note: the size is also passed in the SQLBind() statement
for non-simple types.

ASKER CERTIFIED SOLUTION
Avatar of nsrvijay
nsrvijay

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Do you Know SQLC?