Return a pointer to the data in a regular result column.
BYTE *dbdata(dbproc, column) DBPROCESS *dbproc; int column;
A pointer to the DBPROCESS structure that provides the connection for a particular front-end/server process. It contains all the information that DB-Library uses to manage communications and data between the front end and server.
The number of the column of interest. The first column is number 1.
A BYTE pointer to the data for the particular column of interest. Be sure to cast this pointer into the proper type. A NULL BYTE pointer is returned if there is no such column or if the data has a null value. To make sure that the data is really a null value, you should always check for a return of 0 from dbdatlen.
This routine returns a pointer to the data in a regular (that is, non-compute) result column. The data is not null-terminated. You can use dbdatlen to get the length of the data.
Here is a small program fragment that uses dbdata:
DBPROCESS *dbproc;
DBINT row_number = 0;
DBINT object_id;
/* Put the command into the command buffer */
dbcmd(dbproc, "select id from sysobjects");
/*
** Send the command to Adaptive Server Enterprise and begin
** execution
*/
dbsqlexec(dbproc);
/* Process the command results */
dbresults(dbproc);
/* Examine the data in each row */
while (dbnextrow(dbproc) != NO_MORE_ROWS)
{
row_number++;
object_id = *((DBINT *)dbdata(dbproc, 1));
printf("row %ld, object id is %ld.\n",
row_number, object_id);
}
Do not add a null terminator to string data until you have copied it from the DBPROCESS with a routine such as strncpy. For example:
char objname[40];
...
strncpy(objname, (char *)dbdata(dbproc,2),
(int)dbdatlen(dbproc,2));
objname[dbdatlen(dbproc,2)] = ’\0’;
The function dbbind will automatically bind result data to your program variables. It does a copy of the data, but is often easier to use than dbdata. Furthermore, it includes a convenient type-conversion capability. By means of this capability, the application can, among other things, easily add a null terminator to a result string or convert money and datetime data to printable strings.