Add text to the DBPROCESS command buffer.
RETCODE dbcmd(dbproc, cmdstring) DBPROCESS *dbproc; char *cmdstring;
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.
A null-terminated character string that dbcmd copies into the command buffer.
SUCCEED or FAIL.
This routine adds text to the Transact-SQL command buffer in the DBPROCESS structure. It adds to the existing command buffer—it does not delete or overwrite the current contents except after the buffer has been sent to the server (see “Clearing the command buffer”). A single command buffer may contain multiple commands; in fact, this represents an efficient use of the command buffer.
dbfcmd is a related function. dbfcmd interprets the cmdstring as a format string that is passed to sprintf along with any additional arguments. The application can intermingle calls to dbcmd and dbfcmd.
The application may call dbcmd repeatedly. The command strings in sequential calls are just concatenated together. It is the application’s responsibility to ensure that any necessary blanks appear between the end of one string and the beginning of the next.
Here is a small example of using dbcmd to build up a multiline SQL command:
DBPROCESS *dbproc;
dbcmd(dbproc, "select name from sysobjects");
dbcmd(dbproc, " where id < 5");
dbcmd(dbproc, " and type=’S’");
Note the required spaces at the start of the second and third command strings.
At any time, the application can access the contents of the command buffer through calls to dbgetchar, dbstrlen, and dbstrcpy.
Available memory is the only constraint on the size of the DBPROCESS command buffer created by calls to dbcmd and dbfcmd.
After a call to dbsqlexec or dbsqlsend, the first call to either dbcmd or dbfcmd automatically clears the command buffer before the new text is entered. If this situation is undesirable, set the DBNOAUTOFREE option. When DBNOAUTOFREE is set, the command buffer is cleared only by an explicit call to dbfreebuf.