bcp_writefmt

DB Library for C

DB Library for C

bcp_writefmt

Writes a data file format definition to a user file for a bulk copy between a file and Microsoft® SQL Server™ 2000.

Syntax

RETCODE bcp_writefmt ( PDBPROCESS dbproc,
LPCSTR file_name );

Arguments

dbproc

Is the DBPROCESS structure that is the handle for a particular workstation or SQL Server 2000 process. It contains all the information that DB-Library uses to manage communications and data between the workstation and SQL Server.

file_name

Is the full path and file name of the file containing the format definitions.

Returns

SUCCEED or FAIL.

Remarks

The format of the data file reflects previous calls to bcp_columns and bcp_colfmt.

The bulk copy utility (bcp) copies a database table to or from a host file in a user-specified format, which can be saved with bcp in definition files that store the data file format. These files can later automate the process of bulk copying files that share a common format.

Read format-definition files with bcp_readfmt.

Note  The file produced by bcp_writefmt is not compatible with versions of the bcp utility before version 4.2.

Examples

The following example shows how to use bcp_writefmt:

bcp_init(dbproc, "mytable", "bcpdata", "bcperrs", DB_OUT);

bcp_columns(dbproc, 3);
bcp_colfmt(dbproc, 1, SQLCHAR, 0, -1, '\t', 1, 1);
bcp_colfmt(dbproc, 2, SQLCHAR, 0, -1, '\t', 1, 2);
bcp_colfmt(dbproc, 3, SQLCHAR, 0, -1, '\t', 1, 3);

bcp_writefmt(dbproc, "my_fmtfile");

bcp_exec(dbproc, &rows_copied);

See Also

bcp_colfmt

bcp_readfmt

bcp_columns