Send part of a text or image value to Adaptive Server Enterprise.
RETCODE bcp_moretext(dbproc, size, text) DBPROCESS *dbproc; DBINT size; BYTE *text;
A pointer to the DBPROCESS structure that provides the connection for a particular front-end/Adaptive Server Enterprise process. It contains all the information that DB-Library uses to manage communications and data between the front end and Adaptive Server Enterprise.
The size of this particular part of the text or image value being sent to Adaptive Server Enterprise. It is an error to send more text or image bytes to Adaptive Server Enterprise than were specified in the call to bcp_bind or bcp_collen.
A pointer to the text or image portion to be written.
SUCCEED or FAIL.
This routine is used in conjunction with bcp_bind and bcp_sendrow to send a large SYBTEXT or SYBIMAGE value to Adaptive Server Enterprise in the form of a number of smaller chunks. This is particularly useful with operating systems unable to allocate extremely long data buffers.
If bcp_bind is called with a type parameter of SYBTEXT or SYBIMAGE and a non-NULL varaddr parameter, bcp_sendrow will send the entire text or image data value, just as it does for all other datatypes. If, however, bcp_bind has a NULL varaddr parameter, bcp_sendrow will return control to the application immediately after all non-text or image columns are sent to Adaptive Server Enterprise. The application can then call bcp_moretext repeatedly to send the text and image columns to Adaptive Server Enterprise, a chunk at a time.
Here is an example that illustrates how to use bcp_moretext with bcp_bind and bcp_sendrow:
LOGINREC *login;
DBPROCESS *dbproc;
DBINT id = 5;
char *part1 = "This text value isn’t very long,";
char *part2 = " but it’s broken up into three parts";
char *part3 = " anyhow.";
/* Initialize DB-Library. */
if (dbinit() == FAIL)
exit(ERREXIT);
/* Install error handler and message handler. */
dberrhandle(err_handler);
dbmsghandle(msg_handler);
/* Open a DBPROCESS */
login = dblogin();
BCP_SETL(login, TRUE);
dbproc = dbopen(login, NULL);
/* Initialize bcp. */
if (bcp_init(dbproc, "comdb..articles", (BYTE *)NULL,
(BYTE *)NULL, DB_IN) == FAIL)
exit(ERREXIT);
/* Bind program variables to table columns. */
if (bcp_bind(dbproc, (BYTE *)&id, 0, (DBINT)-1,
(BYTE *)NULL, 0, SYBINT4, 1) == FAIL)
{
fprintf(stderr, "bcp_bind, column 1, failed.\n");
exit(ERREXIT);
}
if (bcp_bind
(dbproc, (BYTE *)NULL, 0,
(DBINT) (strlen(part1) + strlen(part2) + strlen(part3)),
(BYTE *)NULL, 0, SYBTEXT, 2)
== FAIL)
{
fprintf(stderr, "bcp_bind, column 2, failed.\n");
exit(ERREXIT);
}
/*
** Now send this row, with the text value broken into
** three chunks.
*/
if (bcp_sendrow(dbproc) == FAIL)
exit(ERREXIT);
if (bcp_moretext(dbproc, (DBINT)strlen(part1), part1) == FAIL)
exit(ERREXIT);
if (bcp_moretext(dbproc, (DBINT)strlen(part2), part2) == FAIL)
exit(ERREXIT);
if (bcp_moretext(dbproc, (DBINT)strlen(part3), part3) == FAIL)
exit(ERREXIT);
/* We’re all done. */
bcp_done(dbproc);
dbclose(dbproc);
If you use bcp_moretext to send one text or image column in the row, you must also use it to send all other text and image columns in the row.
If the row contains more than one text or image column, bcp_moretext will first send its data to the lowest-numbered (that is, leftmost) text or image column, followed by the next lowest-numbered column, and so on.
An application will normally call bcp_sendrow and bcp_moretext within loops, to send a number of rows of data. Here is an outline of how to do this for a table containing two text columns:
while (there are still rows to send)
{
bcp_sendrow(...);
for (all the data in the first text column)
bcp_moretext(...);
for (all the data in the second text column)
bcp_moretext(...);
}