Check for the existence of Transact-SQL constructs in the command buffer.
int dbgetoff(dbproc, offtype, startfrom) DBPROCESS *dbproc; DBUSMALLINT offtype; int startfrom;
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 type of offset you want to find. The types, which are defined in the header file sybdb.h, are:
OFF_SELECT OFF_FROM OFF_ORDER OFF_COMPUTE OFF_TABLE OFF_PROCEDURE OFF_STATEMENT OFF_PARAM OFF_EXEC
See Options for details.
The point in the buffer at which to start looking. The command buffer begins at 0.
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 Options), this routine can check for the location of certain Transact-SQL constructs in the command buffer. As a simple example, assume the program does not 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");
/*
** Assume the command buffer contains the
** following selects.
*/
dbcmd(dbproc, "select x = 100 select y = 5");
/* Send the query to Adaptive Server Enterprise */
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++;
In this example, select_offset[0] = 0 and select_offset[1] = 15.
dbgetoff does not recognize select statements in a subquery. Thus, if the command buffer contained:
select pub_name
from publishers
where pub_id not in
(select pub_id
from titles
where type = "business")
the second “select” would not be recognized.