dbfcmd

Description

Add text to the DBPROCESS command buffer using C runtime library sprintf-type formatting.

Syntax

RETCODE dbfcmd(dbproc, cmdstring, args...)
 
DBPROCESS     *dbproc;
char                    *cmdstring;
???                     args...;

Parameters

dbproc

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.

cmdstring

A format string of the form used by the sprintf routine.

There is an optional and variable number of arguments to dbfcmd. The number and type of arguments required depends on the format specifiers included in the cmdstring argument. The arguments are passed directly to the C-library sprintf function. Neither dbfcmd nor the C compiler can type check these arguments. As with using sprintf, the programmer must ensure that each argument type matches the corresponding format specifier.

Returns

SUCCEED or FAIL.

Usage


Clearing the command buffer

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.


Limitations

Currently, only eight args may be handled in each call to dbfcmd. To format commands that require more than eight args, call dbfcmd repeatedly. On some platforms, dbfcmd may allow more than eight args per call. For portable code, do not pass more than eight arguments.

Because it makes text substitutions, dbfcmd uses a working buffer in addition to the DBPROCESS command buffer. dbfcmd allocates this working buffer dynamically. The size of the space it allocates is equal to the maximum of a defined constant (1024) or the string length of cmdstring *2 . For example, if the length of cmdstring is 600 bytes, dbfcmd allocates a working buffer 1200 bytes long. If the length of cmdstring is 34 bytes, dbfcmd allocates a working buffer 1024 bytes long. To work around this limitation:

sprintf (buffer, “%s”, SQL commmand”);
dbcmd (dbproc, buffer)

If the args are very big in comparison to the size of cmdstring, the working buffer may not be large enough to hold the string after substitutions are made. In this situation, break cmdstring up and use multiple calls to dbfcmd.

Note that the working buffer is not the same as the DBPROCESS command buffer. The working buffer is a temporary buffer used only by dbfcmd when making text substitutions. The DBPROCESS command buffer holds the text after substitutions have been made. There is no constraint, other than available memory, on the size of the DBPROCESS command buffer.

See also

dbcmd, dbfreebuf, dbgetchar, dbstrcpy, dbstrlen, Options