bcp_bind (DBPROCESS *dbproc, BYTE *varaddr, int prefixlen, DBINT varlen, BYTE *terminator, int termlen, int vartype, int table_column)
Bind a program host variable to a database column.
RETCODE
bcp_colfmt (DBPROCESS *dbproc, int host_colnum, int host_type, int host_prefixlen, DBINT host_collen, const BYTE *host_term, int host_termlen, int table_colnum)
Specify the format of a datafile prior to writing to a table.
RETCODE
bcp_colfmt_ps (DBPROCESS *dbproc, int host_colnum, int host_type, int host_prefixlen, DBINT host_collen, BYTE *host_term, int host_termlen, int table_colnum, DBTYPEINFO *typeinfo)
Specify the format of a host file for bulk copy purposes, with precision and scale support for numeric and decimal columns.
Specify the format of a datafile prior to writing to a table.
Parameters:
dbproc
contains all information needed by db-lib to manage communications with the server.
host_colnum
datafile column number (starting with 1, not zero).
host_type
dataype token describing the data type in host_colnum. E.g. SYBCHAR for character data.
host_prefixlen
size of the prefix in the datafile column, if any. For delimited files: zero. May be 0, 1, 2, or 4 bytes. The prefix will be read as an integer (not a character string) from the data file, and will be interpreted the data size of that column, in bytes.
host_collen
maximum size of datafile column, exclusive of any prefix/terminator. Just the data, ma'am. Special values:
0 indicates NULL.
-1 for fixed-length non-null datatypes
-1 for variable-length datatypes (e.g. SYBCHAR) where the length is established by a prefix/terminator.
host_term
the sequence of characters that will serve as a column terminator (delimiter) in the datafile. Often a tab character, but can be any string of any length. Zero indicates no terminator. Special characters:
'\0' terminator is an ASCII NUL.
'\t' terminator is an ASCII TAB.
'\n' terminator is an ASCII NL.
host_termlen
the length of host_term, in bytes.
table_colnum
Nth column, starting at 1, in the table that maps to host_colnum. If there is a column in the datafile that does not map to a table column, set table_colnum to zero.
Remarks:
bcp_colfmt() is called once for each column in the datafile, as specified with bcp_columns(). In so doing, you describe to FreeTDS how to parse each line of your datafile, and where to send each field.
When a prefix or terminator is used with variable-length data, host_collen may have one of three values:
positive indicating the maximum number of bytes to be used
0 indicating NULL
-1 indicating no maximum; all data, as described by the prefix/terminator will be used.
Specify the format of a host file for bulk copy purposes, with precision and scale support for numeric and decimal columns.
Parameters:
dbproc
contains all information needed by db-lib to manage communications with the server.
host_colnum
datafile column number (starting with 1, not zero).
host_type
dataype token describing the data type in host_colnum. E.g. SYBCHAR for character data.
host_prefixlen
size of the prefix in the datafile column, if any. For delimited files: zero. May be 0, 1, 2, or 4 bytes. The prefix will be read as an integer (not a character string) from the data file, and will be interpreted the data size of that column, in bytes.
host_collen
maximum size of datafile column, exclusive of any prefix/terminator. Just the data, ma'am. Special values:
0 indicates NULL.
-1 for fixed-length non-null datatypes
-1 for variable-length datatypes (e.g. SYBCHAR) where the length is established by a prefix/terminator.
host_term
the sequence of characters that will serve as a column terminator (delimiter) in the datafile. Often a tab character, but can be any string of any length. Zero indicates no terminator. Special characters:
'\0' terminator is an ASCII NUL.
'\t' terminator is an ASCII TAB.
'\n' terminator is an ASCII NL.
host_termlen
the length of host_term, in bytes.
table_colnum
Nth column, starting at 1, in the table that maps to host_colnum. If there is a column in the datafile that does not map to a table column, set table_colnum to zero.
Set the length of a host variable to be written to a table.
Parameters:
dbproc
contains all information needed by db-lib to manage communications with the server.
varlen
size of the variable, in bytes, or
0 indicating NULL
-1 indicating size is determined by the prefix or terminator. (If both a prefix and a terminator are present, bcp is supposed to use the smaller of the two. This feature might or might not actually work.)
table_column
the number of the column in the table (starting with 1, not zero).
contains all information needed by db-lib to manage communications with the server.
field
symbolic constant indicating the option to be set, one of:
BCPMAXERRS Maximum errors tolerated before quitting. The default is 10.
BCPFIRST The first row to read in the datafile. The default is 1.
BCPLAST The last row to read in the datafile. The default is to copy all rows. A value of -1 resets this field to its default?
BCPBATCH The number of rows per batch. Default is 0, meaning a single batch.
value
The value for field.
Remarks:
These options control the behavior of bcp_exec(). When writing to a table from application host memory variables, program logic controls error tolerance and batch size.
contains all information needed by db-lib to manage communications with the server.
tblname
the name of the table receiving or providing the data.
hfile
the data file opposite the table, if any.
errfile
the "error file" captures messages and, if errors are encountered, copies of any rows that could not be written to the table.
direction
one of
DB_IN writing to the table
DB_OUT writing to the host file
Remarks:
bcp_init() sets the host file data format and acquires the table metadata. It is called before the other bulk copy functions.
When writing to a table, bcp can use as its data source a data file (hfile), or program data in an application's variables. In the latter case, call bcp_bind() to associate your data with the appropriate table column.