Copy all or a portion of the command buffer.
RETCODE dbstrcpy(dbproc, start, numbytes, dest) DBPROCESS *dbproc; int start; int numbytes; char *dest;
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.
Character position in the command buffer to start copying from. The first character has position 0. If start is greater than the length of the command buffer, dbstrcpy inserts a null terminator at dest[0].
The number of characters to copy. If numbytes is -1, dbstrcpy will copy the entire command buffer, whether or not dest points to adequate space. It is legal to copy 0 bytes, in which case dbstrcpy inserts a null terminator at dest[0]. If there are not numbytes available to copy, dbstrcpy copies the number of bytes available and returns SUCCEED.
A pointer to the destination buffer to copy the source string into. Before calling dbstrcpy, the caller must verify that the destination buffer is large enough to hold the copied characters. The function dbstrlen returns the size of the entire command buffer.
SUCCEED or FAIL.
dbstrcpy returns FAIL if start is negative.
dbstrcpy copies a portion of the command buffer to a string buffer supplied by the application. The copy is null-terminated.
Internally, the command buffer is a linked list of non-null-terminated text strings. dbgetchar, dbstrcpy, and dbstrlen together provide a way to locate and copy parts of the command buffer.
dbstrcpy assumes that the destination is large enough to receive the source string. If not, a segmentation fault is likely.
When numbytes is passed as -1, dbstrcpy copies the entire command buffer. Do not pass numbytes as -1 unless you are certain that dest points to adequate space for this string. The function dbstrlen returns the length of the current command string.
The following fragment shows how to print the entire command buffer to a file:
FILE *outfile;
DBPROCESS *dbproc;
char *prbuf; /* buffer for collecting the command buffer
** contents as a null-terminated string
*/
RETCODE return_code;
/*
** Allocate sufficient space. dbstrlen() returns the number of
** characters currently in the command buffer. We need one
** more byte because dbstrcpy will append a null terminator.
** NOTE that memory allocation and disposal may be done
** differently on your platform.
**/
prbuf = (char *) malloc(dbstrlen(dbproc) + 1);
if (prbuf == NULL)
{
fprintf(stderr, "Out of memory.");
dbexit();
exit(ERREXIT); /* ERREXIT is defined in the DB-lib headers */
}
/* Copy the command buffer into the allocated space: */
return_code = dbstrcpy(dbproc, 0, -1, prbuf);
assert(return_code == SUCCEED);
/* Print the contents: */
fprintf(outfile, "%s", prbuf);
/* Free the buffer: */
free(prbuf);