SQL Programming Manual for Pascal

Examples of Dynamic NonStop SQL Programs
HP NonStop SQL Programming Manual for Pascal528614-001
C-23
Detailed Dynamic SQL Program
696 9 if (G_errcb.erc = ERC_SUCCESS) then
697 10 begin { alloc output SQLDA ----8 }
698 11
699 11 {**********************************************************}
700 11 {* Get the number of columns and the description of *}
701 11 {* each column in the output SQLDA. The names of the *}
702 11 {* columns will appear in the names buffer. *}
703 11 {**********************************************************}
704 11 EXEC SQL DESCRIBE S1 INTO :osqlda_p^
705 11 NAMES INTO :onambuf_p^;
706 11
707 11 if (G_errcb.erc = ERC_SUCCESS) then
708 12 begin { DESCRIBE succeeded ----9 }
709 13
710 13 {************************************************************}
711 13 {* Initialize the field var_ptr of the SQLDA to point *}
712 13 {* to the output data buffer. *}
713 13 {************************************************************}
714 13 iter := nc; { # iterations to perform }
715 13 {----Set pointer to first SQLVAR element }
716 13 varp.sqldap := osqlda_p;
717 13 varp.i := varp.i + sizeof(SQLDA_HDR);
718 13 while (iter > 0) do
719 14 begin { set up data area ----10 }
720 15 iter := iter - 1;
721 15 {----Allocate space for the data to be read. }
722 15 varp.hvp^.var_ptr := alloc_space(heap,varp.hvp^.data_len);
723 15
724 15 { Initialize ind_ptr field to nil }
725 15 varp.hvp^.ind_ptr := RETYPE(nil, EXTADDR );
726 15 varp.i := varp.i + sqlvar_size;
727 15
728 15 end; { set up data area ----10 }
729 13
730 13 end; { DESCRIBE succeeded ----9 }
731 11
732 11 end; { alloc output SQLDA ----8 }
733 9
734 9 end; { must be a SELECT ----7 }
735 7
736 7 if (G_errcb.erc = ERC_SUCCESS) then { all's well so far ? }
737 8 begin { commence execution ----11 }
738 9
739 9 {**********************************************************}
740 9 {* Begin a TMF transaction to process database request. *}
741 9 {**********************************************************}
742 9 EXEC SQL BEGIN WORK;
743 9
744 9 if (G_errcb.erc = ERC_SUCCESS) then { txn begun successfully }
745 10 begin { execute command ----12 }
746 11
747 11 {**********************************************************}
748 11 {* If the statement is a SELECT, declare a cursor. *}
749 11 {**********************************************************}
750 11 if (nc > 0) then { some output expected }
751 12 begin { execute SELECT ----13 }
752 13
753 13 EXEC SQL DECLARE C1 CURSOR FOR S1;
754 13
755 13 if (G_errcb.erc = ERC_SUCCESS) then
756 14 begin { successful open ----14 }
757 15
758 15 {**********************************************************}
759 15 {* Open the cursor. *}