dbconvert

Description

Convert data from one datatype to another.

Syntax

DBINT dbconvert(dbproc, srctype, src, srclen, 
              desttype, dest, destlen)
 
DBPROCESS     *dbproc;
int                        srctype;
BYTE                  *src;
DBINT                 srclen;
int                        desttype;
BYTE                  *dest;
DBINT                 destlen;

Parameters

dbproc

A pointer to the DBPROCESS structure that provides the connection for a particular front-end/server process. It contains all the information that DB-Library uses to manage communications and data between the front end and server. In dbconvert, the DBPROCESS is used only to supply any custom null values that the program may have specified using dbsetnull. If dbproc is NULL, dbconvert uses the default values for null value data conversions.

srctype

The datatype of the data that is to be converted. This parameter can be any of the server datatypes, as listed below in Table 2-7.

src

A pointer to the data which is to be converted. If this pointer is NULL, dbconvert will place an appropriate null value in the destination variable. You can use dbdata to get the server data.

srclen

The length, in bytes, of the data to be converted. If the srclen is 0, the source data is assumed to be null and dbconvert will place an appropriate null value in the destination variable. Otherwise, this length is ignored for all datatypes except char, text, binary, and image. For SYBCHAR, SYBBOUNDARY, and SYBSENSITIVITY data, a length of -1 indicates that the string is null-terminated. You can use dbdatlen to get the length of the server data.

desttype

The datatype that the source data is to be converted into. This parameter can be any of the server datatypes, as listed below in Table 2-7.

dest

A pointer to the destination variable that will receive the converted data. If this pointer is NULL, dbconvert will call the user-supplied error handler (if any) and return -1.

destlen

The length, in bytes, of the destination variable. destlen is ignored for fixed-length datatypes. For a SYBCHAR, SYBBOUNDARY or SYBSENSITIVITY destination, the value of destlen must be the total length of the destination buffer space.

Table 2-5 describes special values for destlen:

Table 2-5: Special values for destlen (dbconvert)

Value of destlen

Applicable to

Meaning

-1

SYBCHAR, SYBBOUNDARY, SBYSENSITIVITY

There is sufficient space available. The string will be trimmed of trailing blanks and given a terminating null.

-2

SYBCHAR

There is sufficient space available. The string will not be trimmed of trailing blanks, but will be given a terminating null.

Returns

The length of the converted data, in bytes, if the datatype conversion succeeds.

If the conversion fails, dbconvert returns either -1 or FAIL, depending on the cause of the failure. dbconvert returns -1 to indicate a NULL destination pointer or an illegal datatype. dbconvert returns FAIL to indicate other types of failures.

If dbconvert fails, it will first call a user-supplied error handler (if any) and set the global DB-Library error value.

This routine may fail for several reasons: the requested conversion was not available; the conversion resulted in truncation, overflow, or loss of precision in the destination variable; or a syntax error occurred in converting a character string to some numeric type.

Usage

See also

dbaltbind, dbaltbind_ps, dbbind, dbbind_ps, dbconvert_ps, dberrhandle, dbsetnull, dbsetversion, dbwillconvert, Errors, Types