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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Do you Know SQLC?
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.