Checks for the existence of Transact-SQL statements in the command buffer.
INT dbgetoff (
PDBPROCESS dbproc,
DBUSMALLINT offtype,
INT startfrom );
where
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 (see DB-Library Options), 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 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. So, 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")
dbcmd, dbgetchar, dbsetopt, dbstrcpy, dbstrlen; Bulk-Copy Functions, and DB-Library Options