home *** CD-ROM | disk | FTP | other *** search
-
- 1 Version 4.0 -- 5/1/89 dbadata
- ______________________________________________________________________
-
- NAME: dbadata
-
- FUNCTION:
- Return a pointer to the data for a compute column.
-
- SYNTAX:
- BYTE *dbadata(dbproc, computeid, column)
-
- DBPROCESS *dbproc;
- int computeid;
- int column;
-
-
-
-
-
-
-
-
- dbadata Version 4.0 -- 5/1/89 2
- ______________________________________________________________________
-
- COMMENTS:
-
- o After each call to dbnextrow(), you can use this routine to
- return a pointer to the data for a particular column in a com-
- pute row. The data is not null-terminated. You can use
- dbadlen() to get the length of the data.
- o When a column of integer data is summed or averaged, SQL Server
- always returns a 4-byte integer, regardless of the size of the
- column. Therefore, be sure that the variable which is to con-
- tain the result from such a compute is declared as DBINT.
-
- o Here's a short program fragment which illustrates the use of
- dbadata():
-
- DBPROCESS *dbproc;
- int rowinfo;
- DBINT sum;
-
-
- 3 Version 4.0 -- 5/1/89 dbadata
- ______________________________________________________________________
-
- /* 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");
-
-
-
- dbadata Version 4.0 -- 5/1/89 4
- ______________________________________________________________________
- 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);
- }
- }
-
-
- o The function dbaltbind() automatically binds compute data to
- your program variables. It does a copy of the data, but is
- often easier to use than dbadata(). Furthermore, it includes a
- convenient type conversion capability. By means of this capa-
- bility, the application can, among other things, easily add a
- null terminator to a result string or convert money and
-
-
- 5 Version 4.0 -- 5/1/89 dbadata
- ______________________________________________________________________
- datetime data to printable strings.
-
- PARAMETERS:
- dbproc - A pointer to the DBPROCESS structure that provides the
- connection for a particular front-end/SQL Server process. It
- contains all the information that DB-Library uses to manage
- communications and data between the front end and SQL Server.
- computeid - The id that identifies the particular compute row of
- interest. A SQL SELECT statement may have multiple COMPUTE
- clauses, each of which returns a separate compute row. The
- computeid corresponding to the first COMPUTE clause in a
- SELECT is 1. The computeid is returned by dbnextrow() or
- dbgetrow().
- column - The number of the column of interest. The first column
- returned is number 1. Note that the order in which compute
- columns are returned is determined by the order of the
- corresponding columns in the select-list, not by the order in
-
-
-
- dbadata Version 4.0 -- 5/1/89 6
- ______________________________________________________________________
- which the compute columns were originally specified. For
- example, in the following query the result of "sum(price)" is
- referenced by giving column a value of 1, not 2:
-
- select price, advance from titles
- compute sum(advance), sum(price)
-
- The relative order of compute columns in the select-list,
- rather than their absolute position, determines the value of
- column. For instance, given the following variation of the
- previous SELECT:
-
- select title_id, price, advance from titles
- compute sum(advance), sum(price)
-
- the column for "sum(price)" still has a value of 1 and not 2,
- because the "title_id" column in the select-list is not a
-
-
-
- 7 Version 4.0 -- 5/1/89 dbadata
- ______________________________________________________________________
- compute column and therefore is ignored when determining the
- compute column's number.
-
- RETURNS:
- A BYTE pointer to the data for a particular column in a particu-
- lar compute. Be sure to cast this pointer into the proper type.
- A BYTE pointer to NULL is returned if there is no such column or
- compute or if the data has a null value.
-
- DB-Library allocates and frees the data space that the BYTE
- pointer points to. Do not overwrite this space.
-
- SEE ALSO:
- dbadlen, dbaltbind, dbaltlen, dbalttype, dbgetrow, dbnextrow,
- dbnumalts
-
-
-
-
-