Initializes bulk copy operation.
RETCODE bcp_init (
PDBPROCESS dbproc,
LPCSTR tblname,
LPCSTR hfile,
LPCSTR errfile,
INT direction );
If direction is DB_OUT, tblname can also be the name of a database view.
SUCCEED or FAIL.
bcp_init performs the necessary initializations for a bulk copy of data between the workstation and SQL Server. It sets the default user-file data formats and examines the structure of the database table.
If a user file is being used (see the description of the hfile parameter), the default data native formats are as follows:
When a given database column’s data is variable length or when it can contain null values, the user file’s data column is prefixed by a 4-byte length value for SQLTEXT and SQLIMAGE data types and a 1-byte length value for all other types.
Any of these defaults can be overridden by calling bcp_columns and bcp_colfmt.
To use the bulk copy functions to copy data to a database table, follow these examples:
login = dblogin();
BCP_SETL(login, TRUE);
sp_dboption 'mydb', 'select into/bulkcopy', 'true'
GO
USE mydb
GO
CHECKPOINT
If no user file is being used, it is necessary to call bcp_bind to specify the format and location in memory for each column’s data value, and send the rows using bcp_sendrow
The bcp_init function must be called before any other bulk-copy functions. Failure to do so results in an error.
bcp_batch | bcp_columns |
bcp_bind | bcp_control |
bcp_colfmt | bcp_done |
bcp_collen | bcp_sendrow |
bcp_colptr |