SQL Programming Manual for Pascal
Examples of Dynamic NonStop SQL Programs
HP NonStop SQL Programming Manual for Pascal—528614-001
C-24
Detailed Dynamic SQL Program
 760 15 {**********************************************************}
 761 15 if (np > 0) then { some parameters specified }
 762 16 EXEC SQL OPEN C1 USING DESCRIPTOR :isqlda_p^
 763 16 else EXEC SQL OPEN C1;
 764 15
 765 15 {**********************************************************}
 766 15 {* Fetch records until all records exhausted or error. *}
 767 15 {**********************************************************}
 768 15 while (SQLCODE = 0) do
 769 16 begin { get a record ----15 }
 770 17 {----Fetch a record into the output SQLDA. }
 771 17 EXEC SQL FETCH C1 USING DESCRIPTOR :osqlda_p^;
 772 17 {----Display the record. }
 773 17 if (SQLCODE = 0) then
 774 18 display_result(osqlda_p,onambuf_p);
 775 17 end; { get a record ----15 }
 776 15
 777 15 {**********************************************************}
 778 15 {* Close the cursor. *}
 779 15 {**********************************************************}
 780 15 EXEC SQL CLOSE C1;
 781 15
 782 15 end; { successful open ----14 }
 783 13
 784 13 end { execute SELECT ----13 }
 785 12
 786 12 {**************************************************************}
 787 12 {* Statement not a SELECT. Perform EXECUTE with *}
 788 12 {* USING DESCRIPTOR if there are input variables; *}
 789 12 {* otherwise, perform EXECUTE. *}
 790 12 {**************************************************************}
 791 12 else if (np > 0) then { use the given parameters }
 792 13 begin
 793 14 EXEC SQL EXECUTE S1 USING DESCRIPTOR :isqlda_p^;
 794 14 end
 795 13 else begin { just execute it }
 796 14  EXEC SQL EXECUTE S1;
 797 14  end;
 798 11
 799 11 {**************************************************************}
 800 11 {* Commit the TMF transaction. *}
 801 11 {**************************************************************}
 802 11 EXEC SQL COMMIT WORK;
 803 11
 804 11 end; { execute command ----12 }
 805 9
 806 9 end; { commence execution ----11 }
 807 7
 808 7 {**************************************************************}
 809 7 {* Cleanup. Deallocate the heap.     *}
 810 7 {**************************************************************}
 811 7 if (np > 0) then
 812 8 dealloc_sqlda(isqlda_p);
 813 7 if (nc > 0) then
 814 8 dealloc_sqlda(osqlda_p);
 815 7 if (heap <> NIL) then
 816 8 dealloc_space(heap);
 817 7
 818 7 end; { COMPILE SQL COMMAND ----3 }
 819 5
 820 5 end; { COMMAND PROCESSOR ----2 }
 821 3
 822 3 if (G_errcb.erc = ERC_NOHEAPSPACE) then
 823 4 exit;
 824 3 end; { DRIVER LOOP ----1 }
 825 1 end. { of program DSQLPROC }










