home *** CD-ROM | disk | FTP | other *** search
- .Na "dbfcmd"
- .Aa
- .Fu
- Add text to the DBPROCESS command buffer using C run-time library
- \f2sprintf\f1-type formatting.
- .Ih "command buffer, adding text to"
- .Sy
- .Sf "RETCODE dbfcmd(dbproc, cmdstring, args...)"
- .Sp "DBPROCESS" "*dbproc"
- .Sp "char" "*cmdstring"
- .Sp "long" "args..."
- .Co
- .Bl
- This routine adds text to the \*N command buffer in the DBPROCESS
- structure.
- .I "dbfcmd()"
- works just like the C language Standard I/O library
- .I "sprintf()"
- function, using % conversion specifications.
- If you don't need any of the formatting capability of
- .I "sprintf(),"
- you can use
- .I "dbcmd()"
- instead.
- .Bl
- Since
- .I "dbfcmd()"
- calls
- .I "sprintf(),"
- you must remember that
- .I "%"
- has a special meaning as the beginning of a format command. If you want to include
- .I "%"
- in the command string, you must precede it with another
- .I "%".
- In addition, don't use variables containing strings with apostrophes
- or single quotes.
- .Bl
- .I "dbfcmd()"
- manages the space allocation for the command buffer.
- It adds to the existing command buffer\(emit doesn't
- delete or overwrite the current contents except after the
- buffer has been sent to \*S (see below).
- A single command buffer may contain multiple commands; in fact, this represents
- an efficient use of the command buffer.
- .Bl
- The application may call
- .I "dbfcmd()"
- repeatedly.
- The command strings in
- sequential calls are just concatenated together.
- It is the
- program's responsibility to ensure that any necessary blanks appear between
- the end of one string and the beginning of the next.
- .Bl
- After a call to \f2dbsqlexec()\f1 or \f2dbsqlsend()\f1,
- the first call to either \f2dbcmd()\f1 or \f2dbfcmd()\f1
- 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 \f2dbfreebuf()\f1.
- .Ih "DBNOAUTOFREE option"
- .Bl
- Here's a small program fragment that uses \f2dbfcmd()\f1
- to build up a multi-line SQL command:
- .ta +4n +4n +4n +4n +4n +4n
- .SD
- char *column_name;
- DBPROCESS *dbproc;
- int low_id;
- char *object_type;
- char *tablename;
-
- dbfcmd(dbproc, "select %s from %s", column_name, tablename);
- dbfcmd(dbproc, " where id > %d", low_id);
- dbfcmd(dbproc, " and type='%s'", object_type);
- .ED
- Note the required spaces at the start of the second and third command strings.
- .Bl
- Be sure to guard against passing a
- null pointer contained in a variable to \f2dbfcmd()\f1.
- If a null value is a possibility, you should check for it before using the
- variable with a \f2dbfcmd()\f1 call.
- .Bl
- The application can intermingle calls
- to \f2dbcmd()\f1 and \f2dbfcmd()\f1.
- .Bl
- At any time,
- the application can access the
- contents of the command buffer through calls to
- .I "dbgetchar(), dbstrlen(),"
- and
- .I "dbstrcpy()."
- .Bz
- .Pa
- .Pi dbproc
- A pointer to the DBPROCESS structure that provides the connection
- for a particular front end/\*S process. It contains all the
- information that \*L uses to manage communications and data between the
- front end and \*S.
- .Pi cmdstring
- A format string of the form used by the
- .I "sprintf()"
- routine.
- .Pi args...
- There is an optional and variable number of arguments to
- .I "dbfcmd()."
- The number of arguments required depends on the number indicated in the
- .I cmdstring
- argument. The arguments are passed directly to the
- .I "sprintf()"
- function.
- .in -.375i
- .Re
- SUCCEED or FAIL.
- .Bg
- Currently, only eight
- .I args
- may be handled in each call to
- .I dbfcmd().
- To format commands that require more than eight
- .I args,
- call
- .I dbfcmd()
- repeatedly.
- .sp
- This routine allocates its working buffer dynamically.
- The size it picks
- to allocate space is the maximum of a defined constant (1024) and
- the string length of
- .I cmdstring
- * 2.
- If the
- .I args
- are very big in comparison to the size of
- .I cmdstring ,
- there may not be enough space allocated.
- .Sa
- dbcmd,
- dbfreebuf,
- dbgetchar,
- dbstrcpy,
- dbstrlen,
- options
-