INFORMIX
Informix-ESQL/C Programmer's Manual
Chapter 2: INFORMIX-ESQL/C Data Types
Home Contents Index Master Index New Book

Data-Type Alignment Library Functions

The following ESQL/C library functions provide machine-independent size and alignment information for different data types and help you work with null database values.

Function Name Description

risnull()

Checks whether a C variable is null

rsetnull()

Sets a C variable to null

rtypalign()

Aligns data on proper type boundaries

rtypmsize()

Gives byte size of SQL data types

rtypname()

Returns the name of a specified SQL data type

rtypwidth()

Returns minimum number of characters that a character data type needs to avoid truncation

When you compile your ESQL/C program with the esql command, esql calls on the linker to link these functions to your program. The following pages describe these functions.

risnull()

The risnull() function checks whether a C or an ESQL/C variable contains a null value.

Syntax

Usage

The risnull() function determines whether ESQL/C variables of all data types except var binary and lvarchar pointer variables contain a null value. To determine whether a var binary or lvarchar pointer host variable contains null, use the ifx_var_isnull() macro. For more information, see page 10-41.

Return Codes

1

The variable does contain a null value.

0

The variable does not contain a null value.

Example

This sample program is in the risnull.ec file in the demo directory.

For a complete listing of the exp_chk() function, see "Guide to the exp_chk.ec File" or refer to the exp_chk.ec file for a listing of this exception-handling function.

Example Output

rsetnull()

The rsetnull() function sets a C variable to a value that corresponds to a database null value.

Syntax

Usage

The rsetnull() function sets to null ESQL/C variables of all data types except var binary and lvarchar pointer host variables. To set a var binary or lvarchar pointer host variable to null, use the ifx_var_setnull() macro. For more information, see page 10-46.

Example

This sample program is in the rsetnull.ec file in the demo directory.

For a complete listing of the exp_chk() function, see "Guide to the exp_chk.ec File" or refer to the exp_chk.ec file for a listing of this exception-handling function.

Example Output

rtypalign()

The rtypalign() function returns the position of the next proper boundary for a variable of the specified data type.

Syntax

Usage

The rtypalign() and rtypmsize() functions are useful when you use an sqlda structure to dynamically fetch data into a buffer. On many hardware platforms, integer and other numeric data types must begin on a work boundary. The C language memory allocation routines allocate memory that is suitably aligned for any data type, including structures. However, these routines do not perform alignment for the constituent components of the structure. The programmer is responsible for performing that alignment with functions such as rtypalign() and rtypmsize(). These functions provide machine independence for storing column data.

After a DESCRIBE statement determines column information, ESQL/C stores the value of type in sqlda.sqlvar->sqltype.

You can see an application of the rtypalign() function in the unload.ec demonstration program.

Return Code

>0

The return value is the offset of the next proper boundary for a variable of type data type.

Example

This sample program is in the rtypalign.ec file in the demo directory.

For a complete listing of the exp_chk() function, see "Guide to the exp_chk.ec File" or refer to the exp_chk.ec file for a listing of this exception-handling function.

Example Output

rtypmsize()

The rtypmsize() function returns the number of bytes you must allocate in memory for the specified ESQL/C or SQL data type.

Syntax

Usage

The rtypalign() and rtypmsize() functions are useful when you use an sqlda structure to dynamically fetch data into a buffer. These functions provide machine independence for the column-data storage.

Informix provides the rtypmsize() function to use with the sqlda structure that a DESCRIBE statement initializes. After a DESCRIBE statement determines column information, the value of sqltype and sqllen components reside in the components of the same name in each sqlda.sqlvar structure.

When rtypmsize() determines sizes for character data, keep the following size information in mind:

You can see an application of the rtypmsize() function in the unload.ec demonstration program.

Return Codes

0

The sqltype is not a valid SQL type.

>0

The return value is the number of bytes that the sqltype data type requires.

Example

This sample program is in the rtypmsize.ec file in the demo directory.

For a complete listing of the exp_chk() function, see "Guide to the exp_chk.ec File" or refer to the exp_chk.ec file for a listing of this exception-handling function.

Example Output

rtypname()

The rtypname() function returns a null-terminated string that contains the name of the specified SQL data type.

Syntax

The rtypname() function converts a constant for an Informix SQL data type (which sqltypes.h defines) to a character string.

Return Codes

The rtypname function returns a pointer to a string that contains the name of the data type specified sqltype. If sqltype is an invalid value, rtypname() returns a null string (" ")

Example

This sample program is in the rtypname.ec file in the demo directory.

For a complete listing of the exp_chk() function, see "Guide to the exp_chk.ec File" or refer to the exp_chk.ec file for a listing of this exception-handling function.

Example Output

rtypwidth()

The rtypwidth() function returns the minimum number of characters that a character data type needs to avoid truncation when you convert a value with an SQL data type to a character data type.

Syntax

Usage

Informix provides the rtypwidth() function for use with the sqlda structure that a DESCRIBE statement initializes. The sqltype and sqllen components correspond to the components of the same name in each sqlda.sqlvar structure.

Return Codes

0

The sqltype is not a valid SQL data type.

> 0

The return value is the minimum number of characters that the sqltype data type requires.

Example

This sample program is in the rtypwidth.ec file in the demo directory.

For a complete listing of the exp_chk() function, see "Guide to the exp_chk.ec File" or refer to the exp_chk.ec file for a listing of this exception-handling function.

Example Output




Informix-ESQL/C Programmer's Manual, version 9.1
Copyright © 1998, Informix Software, Inc. All rights reserved.