4. Embedded SQL for Fortran : Dynamic Programming for Fortran : SQLVAR Array Usage : Pointer Usage with Fortran Variables
 
Share this page                  
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.