Was this helpful?
Data Type Conversion
A Fortran variable declaration must be compatible with the Ingres value it represents. Numeric Ingres values can be set by and retrieved into numeric variables. Ingres character values can be set by and retrieved into character variables.
Data type conversion occurs automatically for different numeric types, such as from floating-point Ingres database column values into integer Fortran variables, and for character strings, such as from varying-length Ingres character fields into fixed-length Fortran character string buffers.
Ingres does not automatically convert between numeric and character types. You must use one of the Ingres type conversion functions or a Fortran conversion routine for this purpose.
The following table shows the specific type correspondences for each Ingres data type.
Ingres and Fortran Data Type Compatibility
Ingres Type
Fortran Type
cN
character*N
text(N)
character*N
char(N)
character*N
varchar(N)
character*N
i1
byte
i2
integer*2
i4
integer*4
f4
real*4
f8
real*8
date
character*25
money
real*8
Runtime Numeric Type Conversion
The Ingres runtime system provides automatic data type conversion between numeric-type values in the database and the forms system and numeric Fortran variables. It follows the standard type conversion rules. For example, if you assign a real variable to an integer-valued field, the digits after the decimal point of the variable's value are truncated. Runtime errors are generated for overflow on conversion when assigning Ingres numeric values to Fortran variables.
The default size of integers in EQUEL/Fortran is four bytes. You can change the default size to two bytes by means of the -i2 preprocessor flag. If you use this flag, you must compile the program with the -i2 flag for UNIX, the noi4 qualifier for VMS, or the /integer_size:16 flag for Windows.
The Ingres money type is represented as an 8-byte real value, compatible with a Fortran real*8.
Runtime Character Conversion
Automatic conversion occurs between Ingres character string values and Fortran character variables. There are four string-valued Ingres objects that can interact with character variables:
Ingres names, such as form and column names
Database columns of type c or char
Database columns of type text or varchar
Form fields of type c
Several considerations apply when dealing with character string conversions, both to and from Ingres.
The conversion of Fortran character string variables that represent Ingres object names is simple: trailing blanks are truncated from the variables, because the blanks make no sense in that context. For example, the string literals "empfrm " and "empfrm" refer to the same form, and "employees " and "employees" refer to the same database table.
The conversion of other Ingres objects is a bit more complicated. First, the storage of character data in Ingres differs according to whether the medium of storage is a database column of type c or char, a database column of type text or varchar, or a character-type form field. Ingres pads columns of type c and char with blanks to their declared length. Conversely, it does not add blanks to the data in columns of type text or varchar or in form fields.
The Fortran convention is to blank-pad fixed-length character strings. For example, the character string "abc" is stored in a Fortran character*5 variable as the string "abc  " followed by two blanks.
When character data is retrieved from a database column or form field into a Fortran character variable and the variable is longer than the value being retrieved, the variable is padded with blanks. If the variable is shorter than the value being retrieved, the value is truncated. You should always ensure that the variable is at least as long as the column or field, in order to avoid truncation of data.
When inserting character data into an Ingres database column or form field from a Fortran variable, note the following conventions:
When data is inserted from a Fortran variable into a database column of type c or char and the column is longer than the variable, the column is padded with blanks. If the column is shorter than the variable, the data is truncated to the length of the column.
When data is inserted from a Fortran variable into a database column of type text or varchar and the column is longer than the variable, no padding of the column takes place. Furthermore, by default, all trailing blanks in the data are truncated before the data is inserted into the text or varchar column. For example, when a string "abc" stored in a Fortran character*5 variable as "abc  " (refer to above) is inserted into the text or varchar column, the two trailing blanks are removed and only the string "abc" is stored in the database column. To retain such trailing blanks, you can use the Ingres notrim function. It has the following syntax:
notrim(charvar)
where charvar is a character variable. An example that demonstrates this feature follows later. If the text or varchar column is shorter than the variable, the data is truncated to the length of the column.
When data is inserted from a Fortran variable into a c form field and the field is longer than the variable, no padding of the field takes place. In addition, all trailing blanks in the data are truncated before the data is inserted into the field. If the field is shorter than the data (even after all trailing blanks have been truncated), the data is truncated to the length of the field.
When comparing character data in a Ingres database column with character data in a Fortran variable, note the following convention:
When comparing data in c, character, or varchar database columns with data in a character variable, all trailing blanks are ignored. Trailing blanks are significant in text. Initial and embedded blanks are significant in character, text, and varchar; they are ignored in c.
IMPORTANT!  As just described, the conversion of character string data between Ingres objects and Fortran variables often involves the trimming or padding of trailing blanks, with resultant change to the data. If trailing blanks have significance in your application, give careful consideration to the effect of any data conversion.
The Ingres date data type is represented as a 25-byte character string.
The following program fragment demonstrates the notrim function and the truncation rules explained above.
C   Program to illustrate significance of trailing 

C   blanks in   TEXT datatype

    program txttype

##  declare
##  integer*2 row
##  character*7 data

C   data will have 'abc' followed by 4 blanks

    data = 'abc  '

##  ingres testdb

C   set up the table for testing

##  create texttype (#row = i2, #data = text(10))

C   The first APPEND adds the string 'abc' (blanks
C   truncated)
##  append to texttype (#row = 1, #data = data)
C   The second APPEND adds the string 'abc ', with 
C   4 trailing  blanks

##  append to texttype (#row = 2, #data = NOTRIM(data))

C   The RETRIEVE will get the second row because the
C   NOTRIM   function in the previous APPEND caused 
C   trailing blanks to be inserted as data.

##  retrieve (row = texttype.#row)

##  where length(texttype.#data) = 7

    print *, 'Row found = ', row
##  destroy texttype
##  exit
    end 
Last modified date: 08/28/2024