SQL Programming Manual for Pascal
Examples of Dynamic NonStop SQL Programs
HP NonStop SQL Programming Manual for Pascal—528614-001
C-21
Detailed Dynamic SQL Program
 570 0 begin
 571 1 {--Define actions to be taken when an error or warning occurs }
 572 1 EXEC SQL WHENEVER SQLWARNING CALL :HANDLE_WARNING;
 573 1 EXEC SQL WHENEVER SQLERROR CALL :HANDLE_ERROR;
 574 1
 575 1 EOI  := false;
 576 1 G_firstpass := true;  { set global flag   }
 577 1
 578 1 sqlvar_size := sizeof(SQLVAR_TYPE);
 579 1
 580 1 isqlda_p  := NIL;   { blank out pointers  }
 581 1 osqlda_p  := NIL;
 582 1 inambuf_p := NIL;
 583 1 onambuf_p := NIL;
 584 1 parp.hp  := NIL;
 585 1 heap  := NIL;
 586 1
 587 1 while not EOI do   { process user's cmd input }
 588 2  begin     { DRIVER LOOP ----1 }
 589 3  G_errcb.erc := ERC_SUCCESS; {initialize global error area}
 590 3  {---Prompt the user to input a SQL statement or a command. }
 591 3  cmd_type := get_cmd(cmdbuf);{ read stdin for cmd input }
 592 3  G_firstpass := false;  { no longer 1st pass }
 593 3  {----Does the user want to terminate processing ? }
 594 3  if (cmd_type = CMD_STOP_TYP) then {if it is a STOP command }
 595 4  EOI := TRUE   { this is the end of input }
 596 4  else     { no, continue processing }
 597 4  begin    { COMMAND PROCESSOR ----2 }
 598 5  if (cmd_type = CMD_PREV_TYP) then
 599 6  cmdbuf := savbuf { reuse previous command }
 600 6  else savbuf := cmdbuf; { else save current cmd }
 601 5
 602 5 {**********************************************************}
 603 5 {* Prepare the SQL statement.     *}
 604 5 {**********************************************************}
 605 5 EXEC SQL PREPARE S1 FROM :cmdbuf; { COMPILE SQL STATEMENT ---3}
 606 5
 607 5 if (G_errcb.erc = ERC_SUCCESS)then {got no errors or warnings }
 608 6 begin
 609 7
 610 7 { Save all the PREPARE information from the SQLSA: }
 611 7 {  nc = number of columns in the output   }
 612 7 {  onambuf_size = size of output names buffer  }
 613 7 {  np = number of input parameters in the statement }
 614 7 {  inambuf_size = size of input names buffer  }
 615 7 {  statement_type = type of statement prepared  }
 616 7
 617 7 nc := sqlsa.prepare.output_num;
 618 7 onambuf_size := sqlsa.prepare.output_names_len;
 619 7 np := sqlsa.prepare.input_num;
 620 7 inambuf_size := sqlsa.prepare.input_names_len;
 621 7 statement_type := sqlsa.prepare.sql_statement_type;
 622 7 if (np > 0) then { are there any parameters? }
 623 8  begin { process parameters ----4 }
 624 9
 625 9 {**********************************************************}
 626 9 {* Allocate the input SQLDA on the heap including the  *}
 627 9 {* required number of SQLVAR structures, the names  *}
 628 9 {* buffer and a data area to store parameter values.  *}
 629 9 {**********************************************************}
 630 9 alloc_sqlda(isqlda_p,np,inambuf_p,inambuf_size);
 631 9










