SQL Programming Manual for Pascal
Examples of Dynamic NonStop SQL Programs
HP NonStop SQL Programming Manual for Pascal—528614-001
C-16
Detailed Dynamic SQL Program
 295 2  for i := 1 to nc do
 296 3  begin { process each column ----1 }
 297 4  len := namp.int16p^;
 298 4  namp.i := namp.i + sizeof(int16);
 299 4  {---Move the name of the column into the display buffer.}
 300 4  for j := 1 to len do
 301 5   begin { display column name ----2 }
 302 6   write(namp.charp^);
 303 6   namp.i := namp.i + char_size;
 304 6   end; { display column name ----2 }
 305 4  for j := len+1 to SQL_NAME_SIZE do { clear the
         display buffer }
 306 5   write(' '); { fill with blank character }
 307 4  write(SEPARATOR); { print '<colname> : ' }
 308 4  {----Check the data type of the host variable. }
 309 4  data_type := varp.hvp^.data_type;
 310 4  valp.xa := varp.hvp^.var_ptr;
 311 4  {----CHAR or VARCHAR: }
 312 4  if data_type <= SQLDT_ASCII_V then
 313 5  begin { process char data ----3 }
 314 6  len := varp.hvp^.data_len;
 315 6   {----If the string will fit on the current line,
         display it }
 316 6  if len < LINE_SIZE - SQL_NAME_SIZE then
 317 7   for j := 1 to len do
 318 8   begin { display the string ----4 }
 319 9   write(valp.charp^);
 320 9   valp.i := valp.i + char_size;
 321 9   end; { display the string ----4 }
 322 6  writeln;
 323 6  end { process char data ----3 }
 324 5  {----A 16 bit integer value }
 325 5  else if data_type <= SQLDT_16BIT_U then begin
 326 7   writeln(valp.cardp^)
 327 7   end
 328 6  {----A 32 bit integer value }
 329 6  else if data_type <= SQLDT_32BIT_U then
 330 7   begin
 331 8   writeln(valp.int32p^)
 332 8   end
 333 7  else
 334 7   writeln('****Data type ',data_type,' not supported');
 335 4  varp.i := varp.i + sqlvar_size;
 336 4  end; { process each column ----1 }
 337 2 writeln;
 338 2 end; { of proc display_result }
 339 0
 340 0 {**********************************************************}
 341 0 {* HANDLE_ERROR : If an SQL error has occurred, display the *}
 342 0 {* error and set global error condition. In the call to *}
 343 0 {* SQLCADISPLAY, the XADDR function is used to create an *}
 344 0 {* extended address pointer to the SQLCA record described in *}
 345 0 {* PEXTDECS. This declaration facilitates type matching 
          between *}
 346 0 {* the SQLCA parameter and the corresponding record in
          PEXTDECS.*}
 347 0 {**********************************************************}
 348 0 procedure handle_error;
 349 1 begin
 350 2  sqlcadisplay (xaddr(sqlca)); { display the error message }
 351 2  G_errcb.erc := ERC_SQLERROR;
 352 2 end;
 353 0










