SQL Programming Manual for Pascal
Examples of Dynamic NonStop SQL Programs
HP NonStop SQL Programming Manual for Pascal—528614-001
C-20
Detailed Dynamic SQL Program
510 0 {**********************************************************}
511 0 {* GET_CMD : Read the command input by the user into cmdbuf. *}
512 0 {* If the command is not a character string then *}
513 0 {* prompt the user at most three times for a command. *}
514 0 {* Check the type of the command and return in cmd_type. *}
515 0 {**********************************************************}
516 0 function get_cmd(var cmdbuf : CMND_BUF) : integer;
517 1 var
518 1 cmd_typ : integer; { type of the command }
519 1 trials : integer; { number of trials }
520 1 begin
521 2 cmd_typ := CMD_JUNK_TYP; { cmdbuf contains garbage }
522 2 trials := MAXTRIES; { will allow 3 trials }
523 2 while (trials > 0) and { repeat until user inputs }
524 3 (cmd_typ = CMD_JUNK_TYP) do { a recognizeable command }
525 3 begin
526 4 trials := trials - 1; { one less trial remaining }
527 4 read_cmd(cmdbuf); { prompt the user for cmd }
528 4 cmd_typ := parse_cmd(cmdbuf); { check type of the cmd }
529 4 if (G_firstpass) and { will not allow a REPEAT }
530 5 (cmd_typ = CMD_PREV_TYP) then { if this is the first }
531 5 cmd_typ := CMD_JUNK_TYP; { invocation }
532 4 end;
533 2 if cmd_typ = CMD_JUNK_TYP then { if not a valid command }
534 3 cmd_typ := CMD_STOP_TYP; { after 3 trials, STOP }
535 2 get_cmd := cmd_typ;
536 2 end; { of function get_cmd }
537 0
538 0 {**********************************************************}
539 0 {* M A I N L I N E *}
540 0 {**********************************************************}
541 0 var
542 0 EOI : boolean; { T => end of input }
543 0 cmd_type : integer; { type of the cmd SQL/other }
544 0 data_size : integer; { size of the data item }
545 0 data_type : integer; { data type }
546 0 iter : integer; { # iterations to perform }
547 0 nc, np : integer; { # columns, parameters }
548 0 sqlvar_size : integer; { size of a SQLVAR_TYPE }
549 0 inambuf_size : longint := 0; { input names buffer size }
550 0 onambuf_size : longint := 0; { output names buffer size }
551 0 statement_type : integer; { type of sql stmt entered }
552 0 heap : P_HEAP_HDR; { heap pointer }
553 0 namp : P_ANY; { ptr to names buffer }
554 0 parp : P_ANY; { ptr to param data on heap }
555 0 varp : P_ANY; { ptr to a SQLVAR structure }
556 0 savbuf : CMND_BUF; { save a copy of cmd input }
557 0
558 0 {**********************************************************}
559 0 {* Declare SQL Host Variables. *}
560 0 {**********************************************************}
561 0 EXEC SQL BEGIN DECLARE SECTION;
562 0 SQLCODE : integer; { SQL status codes }
563 0 isqlda_p : P_SQLDA_HDR; { ptr to SQLDA for input }
564 0 osqlda_p : P_SQLDA_HDR; { ptr to SQLDA for output }
565 0 inambuf_p : P_CHAR_BUF; { ptr to input name buffer }
566 0 onambuf_p : P_CHAR_BUF; { ptr to output name buffer }
Page 17 $NAP.MLBSQL.PDYN 26Aug91 09:33 Module
_MAIN_MODULE
567 0 cmdbuf : CMND_BUF; { cmd input by the user }
568 0 EXEC SQL END DECLARE SECTION;
569 0