bcp_exec

Executes a complete bulk copy of data between a database table and a user file.

Syntax

RETCODE bcp_exec (
PDBPROCESS
dbproc,
LPDBINT
rows_copied );

where

dbproc
Is the DBPROCESS structure that is the handle for a particular workstation/ SQL Server 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.

Returns

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.

Remarks

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 filename. Failure to do so results in an error.

Example

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. 
login = dblogin();
DBSETLUSER(login, "user");
DBSETLPWD(login, "my_passwd");
DBSETLAPP(login, "example");
BCP_SETL(login, TRUE);
dbproc = dbopen(login, "my_server");

// Initialize bcp. 
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");

See Also

bcp_batch, bcp_bind, bcp_colfmt, bcp_collen, bcp_colptr, bcp_columns, bcp_control, bcp_done, bcp_init, bcp_sendrow