Changes the default settings for various control parameters for a bulk copy between a file and Microsoft® SQL Server™.
RETCODE bcp_control (
HDBC hdbc,
INT eOption,
void* iValue );
Version 6.x format does not support several data types when bulk copying out from a SQL Server 7.0 database. Nullable bit values are converted to 0. char, varchar, binary, and varbinary values longer than 255 bytes are trunctated. uniqueidentifier, nchar, nvarchar, and ntext columns are not supported. Zero length data is converted to NULL.
When bulk copying in from a character data file column, blank input values are converted to NULL when iValue is set to FALSE and as follows when iValue is TRUE.
Target column data type | Resulting value |
---|---|
Any data type in the numeric category | 0 |
binary or varbinary | 0x00 |
datetime or smalldatetime | NULL |
uniqueidentifier | NULL |
When bulk copying in from a character data file column containing datetime strings, all datetime string formats supported by earlier DB-Library versions of bulk copy are supported.
When iValue is set to TRUE, a prefix of 0x is allowed for binary values specified in character mode data files. The prefix is not allowed if iValue is FALSE.
When iValue is set to FALSE, zero length indicates are stored as 0x00 in character mode data files and as 0x0000 in BCPUNICODE files.
BCPFILE_ACP: data in the file is in the Microsoft Windows® code page of the client.
BCPFILE_OEMCP: data in the file is in the OEM code page of the client (default).
BCPFILE_RAW: data in the file is in the code page of the SQL Server.
When FALSE, a datetime value representing January 1, 1997 is converted to the character string: 1997-01-01 00:00:00.000. When TRUE, the same datetime value is represented as: {ts '1997-01-01 00:00:00.000'}.
SUCCEED or FAIL.
This function sets various control parameters for bulk-copy operations, including the number of errors allowed before canceling a bulk copy, the numbers of the first and last rows to copy from a data file, and the batch size.
This function is also used to specify the SELECT statement when bulk copying out from SQL Server the result set of a SELECT. Set eOption to BCPHINTS and set iValue to have a pointer to a SQLTCHAR string containing the SELECT statement.
These control parameters are only meaningful when copying between a user file and a SQL Server table. Control parameter settings have no effect on rows copied to SQL Server with bcp_sendrow.
...
// Variables like henv not specified.
SQLHDBC hdbc;
DBINT nRowsProcessed;
// Application initiation, get an ODBC environment handle, allocate the
// hdbc, and so on.
...
// Enable bulk copy prior to connecting on allocated hdbc.
SQLSetConnectAttr(hdbc, SQL_COPT_SS_BCP, (SQLPOINTER) SQL_BCP_ON,
SQL_IS_INTEGER);
// Connect to the data source, return on error.
if (!SQL_SUCCEEDED(SQLConnect(hdbc, _T("myDSN"), SQL_NTS,
_T("myUser"), SQL_NTS, _T("myPwd"), SQL_NTS)))
{
// Raise error and return.
return;
}
// Initialize bulk copy.
if (bcp_init(hdbc, _T("address"), _T("address.add"), _T("addr.err"),
DB_IN) == FAIL)
{
// Raise error and return.
return;
}
// Set the number of rows per batch.
if (bcp_control(hdbc, BCPBATCH, (void*) 1000) == FAIL)
{
// Raise error and return.
return;
}
// Set file column count.
if (bcp_columns(hdbc, 1) == FAIL)
{
// Raise error and return.
return;
}
// Set the file format.
if (bcp_colfmt(hdbc, 1, 0, 0, SQL_VARLEN_DATA, '\n', 1, 1)
== FAIL)
{
// Raise error and return.
return;
}
// Execute the bulk copy.
if (bcp_exec(hdbc, &nRowsProcessed) == FAIL)
{
// Raise error and return.
return;
}
printf("%ld rows processed by bulk copy.", nRowsProcessed);
bcp Utility | bcp_sendrow |
bcp_exec |