Changes the default settings for various control parameters for a bulk copy between a file and SQL Server.
RETCODE bcp_control (
PDBPROCESS dbproc,
INT field,
DBINT value );
where
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 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.
login = dblogin();
BCP_SETL(login, TRUE);
DBSETLUSER(login, "user");
DBSETLPWD(login, "my_passwd");
DBSETLAPP(login, "example");
dbproc = dbopen(login, "my_server");
// Initialize bcp.
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_bind, bcp_colfmt, bcp_collen, bcp_colptr, bcp_columns, bcp_done, bcp_exec, bcp_init