Specifies the format of a user file for bulk copy into or out of SQL Server.
RETCODE bcp_colfmt (
PDBPROCESS dbproc,
INT file_column,
BYTE file_type,
INT file_ prefixlen,
DBINT file_collen,
LPCBYTE file_term,
INT file_termlen,
INT table_column );
where
For a bulk copy out of SQL Server into a file, when file_type is SQLDECIMAL or SQLNUMERIC:
If more than one means of specifying a user file column length is used (such as a length prefix and a maximum column length, or a length prefix and a terminator sequence), DB-Library chooses the one that results in the shortest amount of data being copied.
Length prefixes simplify the way null data values are specified in a user file. For instance, assume you have a 1-byte length prefix for a 4-byte integer column. Ordinarily, the length prefix contains a value of 4 to indicate that a 4-byte value follows. However, if the value of the column is NULL, the length prefix can be set to 0 to indicate that 0 bytes follow for the column.
For fixed-length datatypes, such as integers, the length of the data is constant, except for the special case of null values. Therefore, for fixed-length datatypes, file_collen must always be -1, except when the data is NULL, in which case file_collen must be 0. For character, text, binary, and image data, file_collen can be -1, 0, or some positive value. If file_collen is -1, the system uses either a length prefix or a terminator sequence to determine the length of the data. (If both are supplied, the system uses the one that results in the shortest amount of data being copied.) If file_collen is -1 and neither a prefix length nor a terminator sequence is specified, the system returns an error message. If file_collen is 0, the system assumes the data is NULL. If file_collen is a positive value, the system uses file_collen as the maximum data length. However, if, in addition to a positive file_collen, a prefix length and/or terminator sequence is provided, the system determines the data length by using the method that results in the shortest amount of data being copied.
If more than one means of specifying a user file column length is used (such as a terminator and a length prefix, or a terminator and a maximum column length), bcp chooses the one that results in the shortest amount of data being copied.
SUCCEED or FAIL.
The bcp_colfmt function allows you to specify the user file format for bulk copies. For bulk copy, a format contains the following parts:
Each call to bcp_colfmt specifies the format for one user file column. For example, to change the default settings for three columns in a five-column table, first call bcp_columns(5), and then call bcp_colfmt five times, with three of those calls setting your custom format. Set file_type of the remaining two calls to 0, and set their file_ prefixlen, file_collen, and file_termlen parameters to -1. This procedure copies all five columns ¾ three with your customized format and two with the default format.
The bcp_columns function must be called before any calls to bcp_colfmt.
You must call bcp_colfmt once and only once for every column in the user file, regardless of whether some of those columns use the default format or are skipped.
To skip a column, set the table_column parameter to 0.
bcp_batch, bcp_bind, bcp_collen, bcp_colptr, bcp_columns, bcp_control, bcp_done, bcp_exec, bcp_init, bcp_sendrow, dbconvert