Changes the default settings for various control parameters for a bulk copy between a file and Microsoft® SQL Server™.
RETCODE bcp_control (
PDBPROCESS dbproc,
INT field,
DBINT value );
SUCCEED or FAIL.
This function sets various control parameters for bulk-copy operations, including the number of errors allowed before canceling a bulk copy, the numbers of the first and last rows to copy, and the batch size.
These control parameters are only meaningful when copying between a user file and a SQL Server table. Control parameter settings have no effect on bcp_bind row transfers.
The bcp_control function has a field parameter: BCPABORT. BCPABORT stops a bulk-copy operation that is already in progress. Call bcp_control with a field of BCPABORT from another thread to stop a running bulk-copy operation. The value parameter is ignored.
The following example shows how to use bcp_control:
LOGINREC *login;
DBPROCESS *dbproc;
DBINT rowsread;
// Install error-handler and message-handler.
dberrhandle(err_handler);
dbmsghandle(msg_handler);
// Open a DBPROCESS structure.
login = dblogin();
BCP_SETL(login, TRUE);
DBSETLUSER(login, "user");
DBSETLPWD(login, "my_passwd");
DBSETLAPP(login, "example");
dbproc = dbopen(login, "my_server");
// Initialize bulk copy.
if (bcp_init(dbproc, "comdb..address", "address.add", "addr.err",
DB_IN) == FAIL)
exit(ERREXIT);
// Set the number of rows per batch.
if (bcp_control(dbproc, BCPBATCH, (DBINT) 1000) == FAIL)
{
printf("bcp_control failed to set batching behavior.\n");
exit(ERREXIT);
}
// Set file column count.
if (bcp_columns(dbproc, 1) == FAIL)
{
printf("bcp_columns failed.\n");
exit(ERREXIT);
}
// Set the file format.
if (bcp_colfmt(dbproc, 1, 0, 0, (DBINT)-1, "\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_colptr |
bcp_bind | bcp_exec |
bcp_colfmt | bcp_init |
bcp_collen |