bcp_exec

DB Library for C

DB Library for C

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 );

Arguments

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.

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

Examples

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");

See Also

bcp_batch

bcp_colptr

bcp_bind

bcp_columns

bcp_colfmt

bcp_control

bcp_collen

bcp_sendrow