bcp_bind

Description

Bind data from a program variable to an Adaptive Server table.

Syntax

RETCODE bcp_bind (dbproc, varaddr, prefixlen, varlen,
                terminator, termlen, type, 
                table_column)
 
DBPROCESS     *dbproc;
BYTE                  *varaddr;
int                         prefixlen;
DBINT                  varlen;
BYTE                  *terminator;
int                         termlen;
int                         type;
int                         table_column;

Parameters

dbproc

A pointer to the DBPROCESS structure that provides the connection for a particular front-end/Adaptive Server process. It contains all the information that DB-Library uses to manage communications and data between the front end and Adaptive Server.

varaddr

The address of the program variable from which the data will be copied. If type is SYBTEXT or SYBIMAGE, varaddr can be NULL. A NULL varaddr indicates that text and image values will be sent to Adaptive Server in chunks by bcp_moretext, rather than all at once by bcp_sendrow.

prefixlen

The length, in bytes, of any length prefix this column may have. For example, strings in some non-C programming languages are made up of a one-byte length prefix, followed by the string data itself. If the data does not have a length prefix, set prefixlen to 0.

varlen

The length of the data in the program variable, not including the length of any length prefix and/or terminator. Setting varlen to 0 signifies that the data is null. Setting varlen to -1 indicates that the system should ignore this parameter.

For fixed-length datatypes, such as integer, the datatype itself indicates to the system the length of the data. Therefore, for fixed-length datatypes, varlen must always be -1, except when the data is null, in which case varlen must be 0.

For char, text, binary, and image datatypes, varlen can be -1, 0, or some positive value. If varlen is -1, the system will use either a length prefix or a terminator sequence to determine the length. (If both are supplied, the system will use the one that results in the shortest amount of data being copied.) If varlen is -1 and neither a prefix length nor a terminator sequence is specified, the system will return an error message. If varlen is 0, the system assumes the data is null. If varlen is some positive value, the system uses varlen as the data length. However, if, in addition to a positive varlen, 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.

terminator

A pointer to the byte pattern, if any, that marks the end of this program variable. For example, C strings usually have a 1-byte terminator whose value is 0. If there is no terminator for the variable, set terminator to NULL.

If you want to designate the C null terminator as the program variable terminator, the simplest way is to use an empty string ("") as terminator and set termlen to 1, since the null terminator constitutes a single byte. For instance, the second bcp_bind call in the “Example” section below uses two tabs as the program variable terminator. It could be rewritten to use a C null terminator instead, as follows:

bcp_bind (dbproc, co_name, 0, -1, "", 1, 0, 2) 
termlen

The length of this program variable’s terminator, if any. If there is no terminator for the variable, set termlen to 0.

type

The datatype of your program variable, expressed as an Adaptive Server datatype. The data in the program variable will be automatically converted to the type of the database column. If this parameter is 0, no conversion will be performed. See the dbconvert reference page for a list of supported conversions. That reference page also contains a list of Adaptive Server datatypes.

table_column

The column in the database table to which the data will be copied. Column numbers start at 1.

Returns

SUCCEED or FAIL.

Examples

Example 1

Usage

See also

bcp_batch, bcp_colfmt, bcp_collen, bcp_colptr, bcp_columns, bcp_control, bcp_done, bcp_exec, bcp_init, bcp_moretext, bcp_sendrow