Data types and data conversion in CLI applications
To facilitate this, CLI provides symbolic names for the various data types, and manages the transfer of data between the DBMS and the application. It also performs data conversion (from a C character string to an SQL INTEGER type, for example) if required. CLI needs to know both the source and target data type. This requires the application to identify both data types using symbolic names.
- The application specified a C type that is not the default C type for the SQL type.
- The application specified an SQL type that does not match the base column SQL type at the server, and there was no describe information available to the CLI driver.
- GRAPHIC and VARGRAPHIC columns are not supported by Informix® data server. Due to this limitation, conversion from sql_c_dbchar (C data type) and sql_graphic (SQL Datatype) are not supported. NCHAR and NVARCHAR datatypes and SQL_C_BINARY and SQL_BINARY conversions may be used instead of GRAPHIC and VARGRAPHIC.
- The SQL_XML data type is not supported for use with an Informix data server.
Example of how to use data types
- The DEPTNUMB column of the ORG table is declared as the SQL data type SMALLINT.
- The application variable which will hold the retrieved data is
declared using C types. Since the DEPTNUMB column is of SQL type
SMALLINT, the application variable needs to be declared using the
C type SQLSMALLINT, which is equivalent to the SQL type SMALLINT.
SQLSMALLINT represents the base C type of short int.struct { SQLINTEGER ind; SQLSMALLINT val; } deptnumb; /* variable to be bound to the DEPTNUMB column */
- The application binds the application variable to the symbolic
C data type of SQL_C_SHORT:
The data types are now consistent, because the result data type SQL_C_SHORT represents the C type SQLSMALLINT.sqlrc = SQLBindCol(hstmt, 1, SQL_C_SHORT, &deptnumb.val, 0, &deptnumb.ind);
Data conversion
CLI manages
the transfer and any required conversion of data between the application
and the DBMS. Before the data transfer actually takes place, either
the source, the target or both data types are indicated when calling SQLBindParameter()
, SQLBindCol()
or SQLGetData()
.
These functions use the symbolic type names to identify the data types
involved.
SQLBindParameter()
call
would look like: SQLBindParameter (hstmt, 1, SQL_PARAM_INPUT, SQL_C_DOUBLE,
SQL_DECIMAL, 5, 3, double_ptr, 0, NULL);
The functions mentioned in the previous paragraph can be used to convert data from the default to other data types, but not all data conversions are supported or make sense.
The
rules that specify limits on precision and scale, as well as truncation
and rounding rules for type conversions apply in CLI,
with the following exception: truncation of values to the right of
the decimal point for numeric values may return a truncation warning,
whereas truncation to the left of the decimal point returns an error.
In cases of error, the application should call SQLGetDiagRec()
to
obtain the SQLSTATE and additional information about the failure.
When moving and converting floating point data values between the
application and CLI,
no correspondence is guaranteed to be exact as the values may change
in precision and scale.