Executes a complete bulk copy of data between a database table and a user file.
RETCODE bcp_exec (
PDBPROCESS dbproc,
LPDBINT rows_copied );
dbproc
Is the DBPROCESS structure that is the handle for a particular workstation or Microsoft® SQL Server™ 2000 process. It contains all the information that DB-Library uses to manage communications and data between the workstation and SQL Server.
rows_copied
Is a pointer to a DBINT. The bcp_exec function fills this DBINT with the number of rows successfully copied. If set to NULL, this parameter is not filled in by bcp_exec.
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");