dbcmd

DB Library for C

DB Library for C

dbcmd

Adds text to the DBPROCESS command buffer.

Syntax

RETCODE dbcmd (
PDBPROCESS
dbproc,
LPCSTR
cmdstring );

Arguments

dbproc

Is the DBPROCESS structure that is the handle for a particular workstation or Microsoft® SQL Server™ 2000 process. It contains all the information that DB-Library uses to manage communications and data between the workstation and SQL Server.

cmdstring

Is a null-terminated character string to be copied into the command buffer.

Returns

SUCCEED or FAIL.

Remarks

This function adds text to the command buffer in the DBPROCESS structure. It adds to the existing command buffer; it doesn't delete or overwrite the current contents except after the buffer has been sent to SQL Server. The user can call dbcmd repeatedly. Note that sequential calls are concatenated; the application must include any necessary blanks between the end of one line and the beginning of the next.

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 a call to dbfreebuf.

The dbfcmd function is a related function. Unlike dbcmd, dbfcmd takes additional parameters and interprets cmdstring as a format string that is passed to sprintf along with any additional parameters.

Examples

This example shows how to use dbcmd to build up a multiple-line SQL statement:

DBPROCESS   *dbproc;

dbcmd(dbproc, "SELECT name FROM sysobjects");
dbcmd(dbproc, " WHERE id < 5");
dbcmd(dbproc, " AND type='S'");

Note the leading spaces in the second and third calls to dbcmd. Leading spaces are needed to properly concatenate the entire command string.

See Also

Bulk-Copy Functions

dbsetopt

dbfcmd

dbsqlexec

dbfreebuf

dbsqlsend

DB-Library Options