Defines a null substitution value to be used when binding or converting NULL data.
CS_RETCODE cs_setnull(context, datafmt, buffer, buflen) CS_CONTEXT *context; CS_DATAFMT *datafmt; CS_VOID *buffer; CS_INT buflen;
A pointer to a CS_CONTEXT structure. cs_setnull defines a null substitution value for this context.
A pointer to a CS_DATAFMT structure describing the datatype for which a null substitution value is being defined.
A pointer to the null substitution value. *buffer’s datatype must match datafmt−>type.
The length, in bytes, of *buffer.
cs_set_null returns:
Returns |
Indicates |
---|---|
CS_SUCCEED |
The routine completed successfully. |
CS_FAIL |
The routine failed. |
Common reasons for a cs_setnull failure include:
A memory allocation error
An invalid parameter
If ANSI-style binds are in effect, CS-Library does not use null substitution values. To activate ANSI-style binds, an application sets the Client-Library property CS_ANSI_BINDS to CS_TRUE.
When ANSI-style binds are not in effect and source data for a conversion is NULL, CS-Library sets the destination data to the predefined null substitution value for that destination type. For example, converting a NULL value of any type to a CS_CHAR destination results in an empty string.
In a Client-Library application, null substitution values are defined at the context level. When a Client-Library connection is allocated, it picks up null substitution values from its parent context.
When converting a NULL source value to a CS_CHAR or CS_BINARY destination variable, CS-Library first puts 0 bytes into the destination and then uses the format field of the CS_DATAFMT structure that describes the destination to determine whether to pad or null-terminate.
To reinstate CS-Library’s original default null substitution value for a particular datatype, an application can call cs_setnull with buffer as NULL.
CS-Library and Client-Library use the following default null substitution values:
Destination type |
Null substitution value |
---|---|
CS_BINARY_TYPE |
Empty array |
CS_VARBINARY_TYPE |
Empty array |
CS_BIT_TYPE |
0 |
CS_CHAR_TYPE |
Empty string |
CS_VARCHAR_TYPE |
Empty string |
CS_DATE |
4 bytes of zeros |
CS_TIME |
4 bytes of zeros |
CS_DATETIME_TYPE |
8 bytes of zeros |
CS_DATETIME4_TYPE |
4 bytes of zeros |
CS_TINYINT_TYPE |
0 |
CS_SMALLINT_TYPE |
0 |
CS_INT_TYPE |
0 |
CS_DECIMAL_TYPE |
0.0 (with default scale and precision) |
CS_NUMERIC_TYPE |
0.0 (with default scale and precision) |
CS_FLOAT_TYPE |
0.0 |
CS_REAL_TYPE |
0.0 |
CS_MONEY_TYPE |
$0.0 |
CS_MONEY4_TYPE |
$0.0 |
CS_BOUNDARY_TYPE |
Empty string |
CS_SENSITIVITY_TYPE |
Empty string |
CS_TEXT_TYPE |
Empty string |
CS_UNITEXT_TYPE |
Empty string |
CS_IMAGE_TYPE |
Empty array |
CS_XML_TYPE |
Empty string |