Converting a DB-Library bulk copy program to ODBC is easy because the bulk copy functions supported by the Microsoft® SQL Server™ ODBC driver are similar to the DB-Library bulk copy functions, with the following exceptions:
SQLSetConnectAttr(hdbc, SQL_COPT_SS_BCP,
(void *)SQL_BCP_ON, SQL_IS_INTEGER);
Condition indicated |
DB-Library varlen value | ODBC cbData value |
---|---|---|
Null values supplied | 0 | -1 (SQL_NULL_DATA) |
Variable data supplied | -1 | -10 (SQL_VARLEN_DATA) |
Zero length character or binary string | NA | 0 |
In DB-Library, a varlen value of -1 indicates that variable length data is being supplied, which in the ODBC cbData is interpreted to meant that only NULL values are being supplied. Change any DB-Library varlen specifications of -1 to SQL_VARLEN_DATA and any varlen specifications of 0 to SQL_NULL_DATA.
When set to TRUE, specifies that datetime and smalldatetime values saved in character format will have the ODBC timestamp escape sequence prefix and suffix. This only applies to BCP_OUT operations.
With BCPODBC set to FALSE, a datetime value converted to a character string is output as:
1997-01-01 00:00:00.000
With BCPODBC set to TRUE, the same datetime value is output as:
{ts '1997-01-01 00:00:00.000' }
When set to TRUE, specifies that program variables bound to columns in native format, or columns stored in an operating-system file in either native or character format use the SQL Server version 6x format instead of the SQL Server 7.0 format. Columns bound in native format include columns for which bcp_bind was called with type set to 0 and varlen set to SQL_VARLEN_DATA. Columns stored in native format in a data file include columns for which bcp_colfmt was called with file_type set to 0 and file_collen set to SQL_VARLEN_DATA.
When set to TRUE, specifies that bulk copy functions insert data values supplied for columns with identity constraints. If this is not set, new identity values are generated for the inserted rows.
Specifies various bulk copy optimizations. This option cannot be used on 6.5 or earlier versions of SQL Server.
Specifies the code page of the bulk copy file.
Specifies that a character mode bulk copy file is a Unicode file.
The DB-Library versions of the bulk copy functions accept datetime and smalldatetime values in character strings using several formats:
The DB-Library bulk copy functions do not accept the ODBC datetime and smalldatetime formats.
The ODBC bulk copy functions will accept the same datetime formats as the DB-Library versions of the bulk copy functions when BCP6xFILEFMT is specified. If the SQL_SOPT_SS_REGIONALIZE statement attribute is set to SQL_RE_ON, the ODBC bulk copy functions will accept dates in the regional date format defined for the locale setting of the client computer registry.
bcp_colfmt | SQLSetConnectAttr |
bcp_control | Using the bcp Format File |
Bulk-Copy Functions |