SQL Programming Manual for TAL
Examples of Dynamic NonStop SQL Programs
HP NonStop SQL Programming Manual for TAL—527887-001
C-36
Detailed Dynamic SQL Program
1033. 000022 1 1 PUT^STR ("This is DYNAMIC SQL test.");
1034. 000040 1 1 PRINT^LINE;
1035. 000053 1 1
1036. 000053 1 1 !*****************************************************!
1037. 000053 1 1 ! Input SQL query from terminal. !
1038. 000053 1 1 !*****************************************************!
Page 27 [1] $VOL1.S04.TALDYN 1991-10-15 13:42:28
dyn^tal main procedure
1039. 000053 1 1
1040. 000053 1 1 enter^input:
1041. 000053 1 1 !
1042. 000053 1 1 ! Free the memory taken by the sda^i, sda^o, cname^i,
and cname^o
1043. 000053 1 1 !
1044. 000053 1 1 call cleanup;
1045. 000054 1 1
1046. 000054 1 1 status := read^query ; ! READ^QUERY gets the SQL
statement and
1047. 000056 1 1 ! stores the statement in variable HOST1
1048. 000056 1 1
1049. 000056 1 1 if status < 0 then
1050. 000061 1 1 begin
1051. 000061 1 2 PRINT^BLANK^LINE;
1052. 000071 1 2 PUT^STR ("End of current session");
1053. 000107 1 2 PRINT^LINE;
1054. 000122 1 2 call STOP;
1055. 000127 1 2 end;
1056. 000127 1 1
1057. 000127 1 1 !*****************************************************!
1058. 000127 1 1 ! BEGIN TRANSACTION !
1059. 000127 1 1 !*****************************************************!
1060. 000127 1 1 EXEC SQL BEGIN WORK;
1061. 000200 1 1
1062. 000200 1 1 !*****************************************************!
1063. 000200 1 1 ! PREPARE the SQL statement !
1064. 000200 1 1 !*****************************************************!
1065. 000200 1 1
1066. 000200 1 1 EXEC SQL PREPARE s1 FROM :host1; ! HOST1 is a global
variable that
1067. 000271 1 1 ! contains the SQL statement obtained
1068. 000271 1 1 ! in READ^QUERY
1069. 000271 1 1
1070. 000271 1 1 ! Save the values of some useful SQLSA fields. We must
save these values
1071. 000271 1 1 ! because each SQL statement clears the SQLSA.
1072. 000271 1 1
1073. 000271 1 1 in^numvars := sqlsa.prepare.input^num;
1074. 000274 1 1 in^nameslen := sqlsa.prepare.input^names^len;
1075. 000277 1 1 out^numvars := sqlsa.prepare.output^num;
1076. 000302 1 1 out^nameslen := sqlsa.prepare.output^names^len;
1077. 000305 1 1
1078. 000305 1 1 !*****************************************************!
1079. 000305 1 1 ! Allocate input and output sqlda and names buffers. !
1080. 000305 1 1 !*****************************************************!
1081. 000305 1 1
1082. 000305 1 1 if in^numvars > 0 then
1083. 000310 1 1 begin
1084. 000310 1 2 @sda^i := allocate^sqlda (in^numvars);
1085. 000314 1 2 if @sda^i = NULL^ADDR then
1086. 000321 1 2 begin
1087. 000321 1 3 PUT^STR ("Input SQLDA ");
1088. 000337 1 3 call memory^error^handler(rollback^flag);
1089. 000342 1 3 end;
1090. 000342 1 2 end;
1091. 000342 1 1
1092. 000342 1 1 if out^numvars > 0 then