Execute a bulk copy of data between a database table and a host file.
RETCODE bcp_exec(dbproc, rows_copied) DBPROCESS *dbproc; DBINT *rows_copied;
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.
A pointer to a DBINT. bcp_exec will fill this DBINT with the number of rows successfully copied. If set to NULL, this parameter will not be filled in by bcp_exec.
SUCCEED or FAIL.
bcp_exec returns SUCCEED if all rows are copied. If a partial or complete failure occurs, bcp_exec returns FAIL. Check the rows_copied parameter for the number of rows successfully copied.
This routine copies data from a host file to a database table or vice-versa, depending on the value of the direction parameter in bcp_init.
Before calling this function you must call bcp_init with a valid host file name. Failure to do so will result in an error.
The following program fragment illustrates bcp_exec:
LOGINREC *login;
DBPROCESS *dbproc;
DBINT rowsread;
/* 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, "pubs2..authors", "authors.save",
(BYTE *)NULL, DB_OUT) == FAIL)
exit(ERREXIT);
/* Now, execute the bulk copy. */
if (bcp_exec(dbproc, &rowsread) == FAIL)
printf("Incomplete bulk copy. Only %ld row%c copied.\n",
rowsread, (rowsread == 1) ? ’ ’: ’s’);
bcp_batch, bcp_bind, bcp_colfmt, bcp_collen, bcp_colptr, bcp_columns, bcp_control, bcp_done, bcp_init, bcp_sendrow