dbgetoff

Checks for the existence of Transact-SQL statements in the command buffer.

Syntax

INT dbgetoff (
PDBPROCESS
dbproc,
DBUSMALLINT
offtype,
INT
startfrom );

Arguments
dbproc
Is the DBPROCESS structure that is the handle for a particular workstation/ Microsoft® SQL Server™ process. It contains all the information that DB-Library uses to manage communications and data between the workstation and SQL Server.
offtype
Is the type of offset you want to find. The types (defined in the header file Sqlfront.h) are: OFF_SELECT, OFF_FROM, OFF_ORDER, OFF_COMPUTE, OFF_TABLE, OFF_PROCEDURE, OFF_STATEMENT, OFF_PARAM, and OFF_EXEC

For details, see DB-Library Options.

startfrom
Is the point in the buffer from which to start looking. The command buffer begins at 0.
Returns

The character offset into the command buffer for the specified offset. If the offset is not found, -1 is returned.

Remarks

If the DBOFFSET option has been set, dbgetoff can check for the location of certain Transact-SQL statements in the command buffer.

Examples

In this example, assume that the program doesn’t know the contents of the command buffer but needs to know where the Transact-SQL keyword SELECT appears:

int        select_offset[10];
int        last_offset;
int        i;

// Set the offset option.
dbsetopt(dbproc, DBOFFSET, "select");

dbsqlexec(dbproc);        // Execute the option on the server  while(dbresults(dbproc)!=NO_MORE_RESULTS); // Read returned results 
// Assume the command buffer contains the following SELECTs:
dbcmd(dbproc, "SELECT x = 100 SELECT y = 5");

// Send the query to SQL Server.
dbsqlexec(dbproc);

// Get all the offsets to the SELECT keyword.
for (i = 0, last_offset = 0; last_offset != -1; i++)
if ((last_offset = dbgetoff(dbproc, OFF_SELECT, last_offset))!= -1)
    select_offset[i] = last_offset++;

  

    dbresults(dbproc);

  

In this example, select_offset[0] = 0 and select_offset[1] = 15.

The function dbgetoff does not recognize SELECT statements in a subquery. If the command buffer contains the following, the second SELECT statement goes unrecognized:

SELECT pub_name
FROM publishers
WHERE pub_id NOT IN
(SELECT pub_id
FROM titles
WHERE type = "business")

  

See Also
Bulk-Copy Functions dbsetopt
dbcmd dbstrcpy
dbgetchar dbstrlen
DB-Library Options  

  


(c) 1988-98 Microsoft Corporation. All Rights Reserved.