Change various control parameter default settings.
RETCODE bcp_control(dbproc, field, value) DBPROCESS *dbproc; int field; DBINT value;
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 control-parameter identifier consisting of one of the following symbolic values:
Field |
Description |
---|---|
BCPMAXERRS |
The number of errors allowed before giving up. The default is 10. |
BCPFIRST |
The first row to copy. The default is 1. A value of less than 1 resets this field to its default value of 1. |
BCPLAST |
The last row to copy. The default is to copy all rows. A value of less than 1 resets this field to its default value. |
BCPBATCH |
The number of rows per batch. The default is 0, which means that the entire bulk copy will be done in one batch. This field is only meaningful when copying from a host file into Adaptive Server Enterprise. |
The value to change the corresponding control parameter to.
SUCCEED or FAIL.
This function sets various control parameters for bulk copy operations, including the number of errors allowed before aborting a bulk copy, the numbers of the first and last rows to copy, and the batch size.
These control parameters are only meaningful when the application copies between a host file and an Adaptive Server Enterprise table. Control parameter settings have no effect on bcp_bind row transfers.
By default, Adaptive Server Enterprise copies all the rows specified in one batch. Adaptive Server Enterprise considers each batch to be a separate bcp operation. Each batch is copied in a single insert transaction, and if any row in the batch is rejected, the entire insert is rolled back. bcp then continues to the next batch. You can use bcp_batch to break large input files into smaller units of recoverability. For example, if 300,000 rows are bulk copied in with a batch size of 100,000 rows, and there is a fatal error after row 200,000, the first two batches—200,000 rows—will have been successfully copied into Adaptive Server Enterprise. If batching had not been used, no rows would have been copied into Adaptive Server Enterprise.
The following program fragment illustrates bcp_control:
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, "comdb..address", "address.add",
"addr.error", DB_IN) == FAIL)
exit(ERREXIT);
/* Set the number of rows per batch. */
if (bcp_control(dbproc, BCPBATCH, 1000) == FAIL)
{
printf("bcp_control failed to set batching behavior.\n");
exit(ERREXIT);
}
/* Set host column count. */
if (bcp_columns(dbproc, 1) == FAIL)
{
printf("bcp_columns failed.\n");
exit(ERREXIT);
}
/* Set the host-file format. */
if (bcp_colfmt(dbproc, 1, 0, 0, -1, (BYTE *)("\n"), 1, 1) == FAIL)
{
printf("bcp_colformat failed.\n");
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’);
exit(ERREXIT);
}
bcp_batch, bcp_bind, bcp_colfmt, bcp_collen, bcp_colptr, bcp_columns, bcp_done, bcp_exec, bcp_init