Data Types
The embedded SQL/C preprocessor accepts the C data types shown in the following table. This table maps these types to their corresponding Ingres types. For further information on exact type mapping between Ingres and C data, see
Data Type Conversion in this chapter.
Integer Data Type
The embedded SQL preprocessor accepts all C integer data types. Even though some integer types do have C restrictions (for example, a variable of type short must have a value that can fit into two bytes) the preprocessor does not check these restrictions. At runtime, data type conversion is effected according to standard C numeric conversion rules. For details on numeric type conversion, see
Data Type Conversion in this chapter.
The type adjectives long, short, or unsigned can qualify the integer type.
In the type mappings table previously shown, the C data type char has three possible interpretations, one of which is the Ingres integer data type. The adjective unsigned can qualify the char data type when using it as a single-byte integer. If you declare a variable of the char data type without any C indirection, such as an array subscript or a pointer operator (the asterisk), it is considered a single-byte integer variable.
Example: Declare char without C indirection
char age;
The above example is a legal declaration and can be used as an integer variable. If the variable is declared with indirection, then it is considered an Ingres character string.
You can use an integer variable with any numeric-valued object to assign or receive numeric data. For example, you can use it to set a field in a form or to select a column from a database table. You can also specify simple numeric objects, such as table field row numbers as shown here.
Example: Specify table field row numbers
char age; /* Single-byte integer */
short empnums[MAXNUMS]; /* Array of 2-byte integers */
long *global_index; /* Pointer to 4-byte integer */
unsigned int overtime;
Floating-Point Data Type
The preprocessor accepts float and double as legal floating-point data types. The internal format of double variables is the standard C runtime format.
VMS:
If you declare long floating variables to interact with the Ingres runtime routines, you should not compile your program with the g_float command line qualifier (assuming that you are using the VAX C compiler). This qualifier changes the long float internal storage format, causing runtime numeric errors.
You can only use a floating-point variable to assign or receive floating-point numeric data. You cannot use it to specify numeric objects, such as table field row numbers.
The preprocessor accepts long float as a synonym for double.
Example: Long float equivalent to double
float salary;
double sales;
is equivalent to:
float salary;
long float sales;
Both data types are accepted by the preprocessor.
Character String Data Type
Any variables built up from the char data type, except simple variables declared without any C indirection, are compatible with any Ingres character string objects. As previously mentioned, a variable of type char declared without any C indirection is considered an integer variable.
The preprocessor treats an array of characters and a pointer to a character string in the same way. Always null terminate a character string if you are assigning it to an Ingres object. Ingres automatically null terminates any character string values that are retrieved into C character string variables. Consequently, any variable that you use to receive Ingres values should be declared as the maximum object length, plus one extra byte for the C null character. For more information, see
Runtime Character Type Conversion in this chapter.
The following example declares three character variables--one integer and two strings.
Example: Declare char variables
char age /* Single byte integer */
char *name; /* Use as a pointer to a static string */
char buf[16]; /* Use to receive string data */
Character strings containing embedded single quotes are legal in SQL.
Example: Embedded single quotes usage
mary's
User variables may contain embedded single quotes and need no special handling unless the variable represents the entire search condition of a where clause:
where :variable
In this case you must escape the single quote by reconstructing the :variable string so that any embedded single quotes are modified to double single quotes, as in:
mary''s
Otherwise, a runtime error will occur.
For more information on escaping single quotes, see
String Literals in this chapter. For more information on character strings that contain embedded nulls, see
Varying Length String Type in this chapter.