SQL Programming Manual for TAL

Examples of Dynamic NonStop SQL Programs
HP NonStop SQL Programming Manual for TAL527887-001
C-24
Detailed Dynamic SQL Program
Page 13 [1] $VOL1.S04.TALDYN 1991-10-15 13:42:28
read^query
495. 000000 0 0 INT PROC read^query ;
496. 000000 1 0
497. 000000 1 0 !*********************************************************!
498. 000000 1 0 ! PROC read^query !
499. 000000 1 0 ! reads in a complete SQL statement from the input file. !
500. 000000 1 0 ! A SQL statement is terminated by putting a ";" at !
501. 000000 1 0 ! the end of a line. !
502. 000000 1 0 !**********************************************************!
503. 000000 1 0
504. 000000 1 0 BEGIN
505. 000000 1 1 INT count^read; ! number of bytes read
506. 000000 1 1 INT i; ! index variable
507. 000000 1 1
508. 000000 1 1 host1.len := 0;
509. 000003 1 1 host1.str := 0;
510. 000010 1 1
511. 000010 1 1 PRINT^BLANK^LINE;
512. 000020 1 1
513. 000020 1 1 PUT^STR ("Enter SQL statement or SAME to reuse last
statement or END:");
514. 000036 1 1 PRINT^LINE;
515. 000051 1 1
516. 000051 1 1 !
517. 000051 1 1 ! Loop until an entire SQL statement has been found.
518. 000051 1 1 !
519. 000051 1 1
520. 000051 1 1 while host1.str[host1.len-1] <> ";"
521. 000051 1 1 and host1.len < MAX^SQL^STMT^LENGTH do
522. 000066 1 1 begin
523. 000066 1 2 host1.str[host1.len] ':=' ">>";
524. 000102 1 2 call WRITEREADX(term,host1.str[host1.len],2,
525. 000102 1 2 MAX^SQL^STMT^LENGTH-host1.len,count^read);
526. 000131 1 2 if count^read > 0 then
527. 000134 1 2 begin
528. 000134 1 3 while host1.str[host1.len+count^read-1] = " " do !
trim trailing blanks
529. 000147 1 3 count^read := count^read - 1;
530. 000152 1 3 host1.len := host1.len + count^read;
531. 000154 1 3 end;
532. 000154 1 2 end;
533. 000155 1 1
534. 000155 1 1 ! Drop the semicolon terminator
535. 000155 1 1
536. 000155 1 1 host1.len := host1.len - 1;
537. 000157 1 1
538. 000157 1 1 ! Note: to preserve simplicity, this program does only
skeleton
539. 000157 1 1 ! checking on the contents of the input string. Because the
540. 000157 1 1 ! same buffer is used for the SQL statement and for the
exit/repeat
541. 000157 1 1 ! commands, we cannot UPSHIFT before checking the string.
Actual
542. 000157 1 1 ! programs would copy the input string into a separate
buffer, loop
543. 000157 1 1 ! through the string, and check the contents for correctness.
544. 000157 1 1
545. 000157 1 1 if host1.str = "E" or host1.str = "e" then return -1;
546. 000175 1 1
547. 000175 1 1 if host1.str = "SAME" or host1.str = "same" then
548. 000223 1 1 begin
549. 000223 1 2 host1.str ':=' host2.str for host2.len bytes; ! retrieve
saved query
550. 000233 1 2 host1.len := host2.len;
551. 000235 1 2 PRINT^BLANK^LINE;