SQL Programming Manual for Pascal
Examples of Dynamic NonStop SQL Programs
HP NonStop SQL Programming Manual for Pascal—528614-001
C-13
Detailed Dynamic SQL Program
 153 0 {**********************************************************}
 154 0 {* Copy in external procedures for using large memory model. *}
 155 0 {* PASEXT file contains both MALLOC and FREE.   *}
 156 0 {**********************************************************}
 157 0
 158 0 import begin
 159 0 ?SOURCE $system.system.PASEXT, nolist
 160 0 end;
 161 0
 162 0 {**********************************************************}
 163 0 {* ALLOC_SQLDA : This function allocates contiguous space for
          *}
 164 0 {* a) a SQLDA_HDR (pointer returned in sqlda_p)  *}
 165 0 {* b) numvar SQLVAR structures    *}
 166 0 {* c) a names buffer (pointer returned in nambuf_p) *}
 167 0 {* Returns TRUE if allocation successful, else FALSE *}
 168 0 {**********************************************************}
 169 0 procedure alloc_sqlda(var sqlda_p : P_SQLDA_HDR; numvars :
          integer;
 170 1     var nambuf_p : P_CHAR_BUF; nambuf_size :
          longint);
 171 1 var
 172 1  csz : integer; { size of a character }
 173 1  i : integer; { loop index }
 174 1  alloc_size : longint; { size of heap to be allocd }
 175 1  sqlda_size : longint; { size - SQLDA_HDR+SQLVARs }
 176 1  pheap : P_ANY;
 177 1 begin
 178 2  sqlda_size := sizeof(SQLDA_HDR) + sizeof(SQLVAR_TYPE) *
          numvars;
 179 2  alloc_size := sqlda_size + nambuf_size;
 180 2  pheap.xa := MALLOC(alloc_size);
 181 2  if (pheap.i > 0) then  { if allocated, initialize }
 182 3  begin    { ----1    }
 183 4  {----Initialize the SQLDA_HDR.    }
 184 4  sqlda_p := pheap.sqldap;
 185 4  {----Initialize eye_catcher field to "D1", indicating C30
           }
 186 4  { release:        }
 187 4  sqlda_p^.eye_catcher := SQLDA_EYE_CATCHER;
 188 4  sqlda_p^.num_entries := numvars;
 189 4  pheap.i := pheap.i + sqlda_size; { set ptr to names buffer
           }
 190 4  nambuf_p := pheap.bufp;
 191 4  csz := sizeof(char);
 192 4  end { ----1 }
 193 3  else    { allocation failed  }
 194 3  G_errcb.erc := ERC_NOHEAPSPACE;
       { report a run time error }
 195 2 end;     { of proc alloc_sqlda }
 196 0










