Returns a pointer to the data for a compute column.
LPCBYTE dbadata (
PDBPROCESS dbproc,
INT computeid,
INT column );
where
A BYTE pointer to the data for a particular column in a compute. A null BYTE pointer is returned if there is no such column or compute or if the data has a null value. The data space pointed to is allocated and freed by DB-Library. Be careful not to overwrite the space.
After each call to dbnextrow that returns a value greater than 0, use dbadata to obtain a pointer to the data for a particular column in a compute. The data is not null-terminated. Use dbadlen to get the length of the data.
When a column of integer data is summed or averaged, SQL Server always returns a four-byte integer, regardless of the size of the column. Therefore, be sure that the variable that is to contain the result from such a compute is declared as DBINT.
The following program fragment shows how to use dbadata:
DBPROCESS *dbproc; int rowinfo; DBINT sum; // First, put the commands into the command buffer. dbcmd(dbproc, "select db_name(dbid), dbid, size from sysusages"); dbcmd(dbproc, " order by dbid"); dbcmd(dbproc, " compute sum(size) by dbid"); // Send the commands to SQL Server and start execution. dbsqlexec(dbproc); // Process the command. dbresults(dbproc); // Examine the results of the COMPUTE clause. while((rowinfo = dbnextrow(dbproc)) != NO_MORE_ROWS) { if (rowinfo == REG_ROW) printf("regular row returned.\n"); else { // This row is the result of a COMPUTE clause, // and "rowinfo" is the computeid of this COMPUTE // clause. sum = *(DBINT *)(dbadata(dbproc, rowinfo, 1)); printf("sum = %ld\n", sum); } }
The dbaltbind function automatically binds data to your program variables. It is somewhat easier to use than dbadata and dbadlen but is less efficient because it copies the data into your variable.
dbadlen, dbaltbind, dbaltlen, dbalttype, dbgetrow, dbnextrow, dbnumalts