4. Embedded SQL for Fortran : Fortran Variables and Data Types : Variable and Type Declarations : Data Types
 
Share this page                  
Data Types
The Embedded SQL preprocessor accepts the following elementary Fortran data types and maps them to corresponding Ingres data types. For a description of exact type mapping, see Data Type Conversion in this chapter.
Fortran Data Types
Ingres Data Types
integer*N where N = 2 or 4
integer
logical
integer
logical*N where N = 1, 2 or 4
integer
byte
integer
real
float
real*N where N = 4 or 8
float
double precision
float
character*N where N 0
character
real*8
decimal
integer
integer
Integer Data Type
The Fortran compiler allows the default size of integer variables to be either two or four bytes in length, depending on whether the -i2 compiler flag (UNIX), the noi4 flag (VMS), or the /integer_size:16 or /4I2 (Windows) is set.
This feature is also supported in Embedded SQL/Fortran by means of the preprocessor flag -i2. This flag allows you to change the default size of integer variables to two from the normal default size of four bytes. For detailed information on this flag, see Preprocessor Operation in this chapter.
You can explicitly override the default size when declaring the Fortran variable to the preprocessor. To do so, you must specify a size indicator (*2 or *4) following the integer keyword, as these examples illustrate:
integer*2 smlint 
integer*4 bigint
These declarations create Embedded SQL integer variables of two and four bytes, respectively, regardless of the default setting.
The preprocessor treats byte and logical data type as integer data types. A logical variable has a default size of either 2 or 4 bytes according to whether the -i2 flag has been set. You can override this default size by using a size indicator of 1, 2, or 4. For example:
logical logl*1, log2*2, log4*4
The byte data type has a size of one byte. You cannot override this size.
You can use an integer or byte variable with any numeric-valued object to assign or receive numeric data. For example, you can use such a variable to set a field in a form or to select a column from a database table. It can also specify simple numeric objects, such as table field row numbers. You can use a logical variable to assign or receive integer data, although your program should restrict its value to 1 and 0, which map respectively to the Fortran logical values .TRUE. and .FALSE..
Real Data Type
The preprocessor accepts real and double precision as legal real data types. The preprocessor accepts both 4-byte and 8-byte real variables. It makes no distinction between an 8-byte real variable and a double precision variable. The default size of a real variable is four bytes. However, you can override this size if you use a size indicator (*8) after the real keyword. For example:
C 4-byte real variable
            real salary
C 8-byte real variable
            real*8 yrtoda
C 8-byte real variable
            double precision saltot
You can only use a real variable to assign or receive numeric data (both real, decimal, and integer). You cannot use it to specify numeric objects, such as table field row numbers.
VMS:
The preprocessor expects the internal format of real and double precision variables to be the standard VAX format. For this reason, you should not compile your program with the g_floating qualifier.
Character Data Type
Variables of type character are compatible with all Ingres character string objects. The preprocessor does not need to know the declared length of a character string variable to use it at runtime. Therefore, it does not check the validity of any expression or symbolic name used to declare the length of the string variable. You should ensure that your string variables are long enough to accommodate any possible runtime values. For example:
character*7         first 
character*10        last 
character*1         init 
character*(bufsiz)  msgbuf
For information on the interaction between character string variables and Ingres data at runtime, see Runtime Character and Varchar Type Conversion in this chapter.
Character strings containing embedded single quotes are legal in SQL, for example:
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.