Checks for the existence of Transact-SQL statements in the command buffer.
INT dbgetoff (
PDBPROCESS dbproc,
DBUSMALLINT offtype,
INT startfrom );
For details, see DB-Library Options.
The character offset into the command buffer for the specified offset. If the offset is not found, -1 is returned.
If the DBOFFSET option has been set, dbgetoff can check for the location of certain Transact-SQL statements in the command buffer.
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")
Bulk-Copy Functions | dbsetopt |
dbcmd | dbstrcpy |
dbgetchar | dbstrlen |
DB-Library Options |