SQL/MP Programming Manual for C

Host Variables
HP NonStop SQL/MP Programming Manual for C429847-008
2-5
Using Corresponding SQL and C Data Types
Data Conversion
NonStop SQL/MP performs the conversion between SQL and C data types:
When a host variable serves as an input variable (supplies a value to the
database), NonStop SQL/MP first converts the value that the variable contains to a
compatible SQL data type and then uses the value in the SQL operation.
When a host variable serves as an output variable (receives a value from a
database), NonStop SQL/MP converts the value to the data type of the host
variable.
NonStop SQL/MP supports conversion within character types and numeric types, but
not between character and numeric types.
For conversion between character strings of different lengths, NonStop SQL/MP pads
the receiving string on the right with blanks as necessary. If the receiving string is too
short, NonStop SQL/MP truncates the right part of the longer string and returns a
warning code in the SQLCODE variable.
If an input value is too large for an SQL column, NonStop SQL/MP returns error 8300
(file system error encountered). If you are using the SQLCADISPLAY procedure to
obtain an error message, SQLCADISPLAY also returns file-system error number 1031.
For numeric types, NonStop SQL/MP converts data between signed and unsigned
types and between types with different precisions. Use the SETSCALE function to
communicate a number’s scale to and from a database.
CAST Function
The CAST function allows you to convert a parameter from one data type to another
data type (character and numeric data types only) in dynamic SQL statements. For
information about the CAST function, see the SQL/MP Reference Manual.
Note. C programs that contain an embedded SQL/MP code do not support the use of
unsigned long long C variables even if that data type is not used for the SQL query.
C programs containing unsigned long long C variables outside the EXEC SQL statements
cannot be compiled in the Guardian and OSS environments. A workaround is to use the PC
cross compiler. C programs with unsigned long long variables within the EXEC SQL
statements cannot be compiled because NonStop SQL/MP does not support the unsigned long
long data type.
Note. For optimal performance, declare host variables with corresponding data types and the
same lengths as their respective columns in SQL statements (with consideration for the extra
byte required for the null terminator). This programming practice minimizes the data conversion
performed by NonStop SQL/MP and therefore can improve the performance of your program.