Progress
Embedded SQL-92
Guide and Reference


Explicit Data Conversion Using tpe_conv_data( )

To convert data explicitly from one data type to another, use the tpe_conv_data SQL-92 API function. This is the syntax for the tpe_conv_data function:

SYNTAX
tpe_status_t
tpe_conv_data (dtype, buflen, buf, fmt, odtype, obuflen, obuf)

int  dtype;
int  buflen;
void *buf;
char *fmt;
int  odtype;
int  obuflen;
void *obuf; 

dtype

Data type of the INPUT buffer being converted. See the list of supported defined data types.

buflen

The length of the INPUT buffer buf.

buf

A buffer containing the INPUT data and whose type is specified in dtype.

fmt

A format string that specifies the output format. Valid only if dtype is TPE_DT_DATE and odtype is TPE_DT_CHAR. See Chapter 2, “SQL Language Elements,” in the Progress SQL-92 Guide and Reference for information on date-time format strings.

odtype

Data type of the OUTPUT required after conversion.

obuflen

The length of the OUTPUT buffer obuf.

obuf

The target OUTPUT buffer for the converted data.

dtype

Must be one of the data type symbolic names defined in $DLC/include/sql_lib.h. The defined symbolic names include:

EXAMPLE

The following code fragment illustrates how to convert CHARACTER data to INTEGER data:

EXEC SQL BEGIN DECLARE SECTION ;
     char indata[20] ;
     long outval ;
EXEC SQL END DECLARE SECTION ;
 
strcpy (indata, "1234") ;
status = tpe_conv_data (TPE_DT_CHAR, strlen(indata), indata, "",
     TPE_DT_INTEGER, sizeof(long), &outval) ; 

In this example indata[ ] is the buffer containing INPUT data and outval is the buffer where the converted data is returned.

The tpe_conv_data function does perform type conversions between character types and exact or approximate numeric types, unlike the limitation imposed by implicit type conversions.

EXAMPLE

The following code fragment illustrates how to convert NUMERIC Data to CHARACTER data:

EXEC SQL BEGIN DECLARE SECTION ;
     char  var0[52] ;
     numeric var7 ;
EXEC SQL END DECLARE SECTION ;
 
 
EXEC SQL
     SELECT fld2 INTO :var7 FROM compt WHERE fld1=’10’ ;
     tpe_conv_data (TPE_DT_NUMERIC, sizeof(tpe_num_t), &var7,
                   "", TPE_DTCHAR, 52, var0) ;
     printf("var0 = %s\n", var0 ) ; 

This example illustrates using tpe_conv_data( ) to convert NUMERIC data retrieved from the database into character data for use by the host program. In the example var7 is the buffer containing input data and var0 is the target for output data.


Copyright © 2004 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095