Executes a complete bulk copy of data between a database table and a user file.
RETCODE bcp_exec (
PDBPROCESS dbproc,
LPDBINT rows_copied );
SUCCEED or FAIL. The bcp_exec function 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 function copies data from a user file to a database table or vice versa, depending on the value of the direction parameter in bcp_init.
Before calling bcp_exec, call bcp_init with a valid user file name. Failure to do so results in an error.
The following example shows how to use bcp_exec:
LOGINREC *login;
DBPROCESS *dbproc;
DBINT rowsread;
// Install error-handler and message-handler.
dberrhandle(err_handler);
dbmsghandle(msg_handler);
// Open a DBPROCESS structure.
login = dblogin();
DBSETLUSER(login, "user");
DBSETLPWD(login, "my_passwd");
DBSETLAPP(login, "example");
BCP_SETL(login, TRUE);
dbproc = dbopen(login, "my_server");
// Initialize bulk copy.
if (bcp_init(dbproc, "pubs..authors", "authors.sav",
(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%s copied.\n",
rowsread, (rowsread == 1) ? "": "s");
bcp_batch | bcp_colptr |
bcp_bind | bcp_columns |
bcp_colfmt | bcp_control |
bcp_collen | bcp_sendrow |