Was this helpful?
SQLVAR Array Usage
The SQL Reference Guide discusses the legal values of the sqlvar array. The describe and prepare into statements assign type, length, and name information into the SQLDA. This information refers to the result columns of a prepared select statement, the fields of a form, or the columns of a table field. When the program uses the SQLDA to retrieve or set Ingres data, it must assign the type and length information that now refers to the variables being pointed at by the SQLDA.
Fortran Variable Type Codes
The type codes listed below are the types that describe Ingres result fields and columns. For example, the SQL types date, long varchar, money, and decimal do not describe program variables, but rather data types that are compatible with Fortran types character and real*8. When these types are returned by the describe statement, the type code must be changed to a compatible SQL/Fortran type.
The following table describes the type codes to use with Fortran variables that will be pointed at by the sqldata pointers.
Embedded SQL/Fortran Type Codes (sqltype)
Length (sqllen)
Fortran Variable Type
IISQ_INT_TYPE
1
byte
IISQ_INT_TYPE
2
integer*2
IISQ_INT_TYPE
4
integer*4
IISQ_FLT_TYPE
4
real*4
IISQ_FLT_TYPE
8
real*8
IISQ_CHA_TYPE
LEN
character*LEN
IISQ_VCH_TYPE
LEN
character*LEN
IISQ_HDLR_TYPE
0
IISQHDLR
To retrieve a decimal value from the DBMS, you must use a float because Fortran does not have decimal variables.
Nullable data types (those variables that are associated with a null indicator) are specified by assigning the negative of the type code to the sqltype field. If the type is negative, a null indicator must be pointed at by the sqlind field.
Character data and the SQLDA have exactly the same rules as character data in regular Embedded SQL statements.
Pointer Usage with Fortran Variables
In order to fill an element of the sqlvar array, you must set the type information and assign a valid address to sqldata. The address must be that of a legal variable address.
For example, the following code fragment sets the type information of and points at a 4-byte integer variable, an 8-byte nullable floating-point variable, and an sqllen-specified character substring. The following example demonstrates how a program can maintain a pool of available variables, such as large arrays of the few different typed variables, and a large string space. The next available spot is chosen from the pool.
UNIX:
On UNIX the Fortran function "loc" may be provided. If your UNIX Fortran library does not contain a function for obtaining the address of variables, the Ingres functions "IInum" and "IIsadr" can be used to return the address of number and character strings respectively.
It has the following usage:
    sqlda.sqlvar(i).sqldata = IInum(current_integer)
    sqlda.sqlvar(i).sqldata = IIsadr (current_string)
C Assume sqlda has been declared
           sqlda.sqlvar(1).sqltype = IISQ_INT_TYPE
           sqlda.sqlvar(1).sqllen = 4
           sqlda.sqlvar(1).sqldata 
            1             = loc(integer_array(current_integer))
           sqlda.sqlvar(1).sqlind = 0
           current_integer = current_integer + 1
           sqlda.sqlvar(2).sqltype = -IISQ_FLT_TYPE
           sqlda.sqlvar(2).sqllen = 8
           sqlda.sqlvar(2).sqldata 
            1                = loc(real_array(current_real))
           sqlda.sqlvar(2).sqlind 
            1                = loc(indicator_array(current_ind))
           current_real = current_real + 1
           current_ind = current_ind + 1
C
C SQLLEN has been assigned by DESCRIBE to be the 
C length of a specific result column. This length 
C is used to pick off
C a substring out of a large string space.
C
           needlen = sqlda.sqlvar(3).sqllen
           sqlda.sqlvar(3).sqltype = IISQ_CHA_TYPE
           sqlda.sqlvar(3).sqldata = 
            1            loc(large_string(current_string:needlen))
           sqlda.sqlvar(3).sqlind = 0
           current_string = current_string + needlen 
VMS:
On VMS, the Fortran function "%loc" is used to access the address of variables.
! Assume sqlda has been declared
    sqlda.sqlvar(1).sqltype = IISQ_INT_TYPE
    sqlda.sqlvar(1).sqllen = 4
    sqlda.sqlvar(1).sqldata 
         1             = %loc(integer_array(current_integer))
    sqlda.sqlvar(1).sqlind = 0
    current_integer = current_integer + 1
    sqlda.sqlvar(2).sqltype = -IISQ_FLT_TYPE
    sqlda.sqlvar(2).sqllen = 8
    sqlda.sqlvar(2).sqldata 
   1                = %loc(real_array(current_real))
    sqlda.sqlvar(2).sqlind
         1             = %loc(indicator_array(current_ind))
    current_integer = current_real + 1
    current_integer = current_ind + 1
!
! SQLLEN has been assigned by DESCRIBE to be the length
! of a specific result column. This length is used to
! pick off a substring out of a large string space.
!
    needlen = sqlda.sqlvar(3).sqllen
    sqlda.sqlvar(3).sqltype = IISQ_CHA_TYPE
    sqlda.sqlvar(3).sqldata
         1          = %loc(large_string(current_string:needlen))
    sqlda.sqlvar(3).sqlind = 0
    current_string = current_string + needlen 
Windows:
On Windows, the "loc" intrinsic function (or the "%loc" built-in function) is used to access the address of variables.
C Assume sqlda has been declared
    sqlda.sqlvar(1).sqltype = IISQ_INT_TYPE
    sqlda.sqlvar(1).sqllen = 4
    sqlda.sqlvar(1).sqldata 
         1             = %loc(integer_array(current_integer))
    sqlda.sqlvar(1).sqlind = 0
    current_integer = current_integer + 1
    sqlda.sqlvar(2).sqltype = -IISQ_FLT_TYPE
    sqlda.sqlvar(2).sqllen = 8
    sqlda.sqlvar(2).sqldata 
   1                = %loc(real_array(current_real))
    sqlda.sqlvar(2).sqlind
         1             = %loc(indicator_array(current_ind))
    current_integer = current_real + 1
    current_integer = current_ind + 1
C
C SQLLEN has been assigned by DESCRIBE to be the length
C of a specific result column. This length is used to
C pick off a substring out of a large string space.
C
    needlen = sqlda.sqlvar(3).sqllen
    sqlda.sqlvar(3).sqltype = IISQ_CHA_TYPE
    sqlda.sqlvar(3).sqldata
         1          = %loc(large_string(current_string:needlen))
    sqlda.sqlvar(3).sqlind = 0
    current_string = current_string + needlen 
You may also set the SQLVAR to point to a datahandler for large object columns. For details, see Advanced Processing in this chapter.
Last modified date: 08/28/2024