Dynamic SQL Operations
HP NonStop SQL/MP Programming Manual for C—429847-008
10-42
Detailed Dynamic SQL Program
Detailed Dynamic SQL Program
This program allows the user to enter any statement. The program prepares and runs
the statement in a TMF transaction. The code is independent of any database because
the program does not reference database definitions; only the entered statements
reference a particular database.
The program performs these operations, which characterize dynamic SQL programs:
Declares an SQLSA to determine the number of input parameters or output
variables.
Declares an SQLDA to describe input parameters and another to describe output
variables. Because the program is allocating memory at run time, the SQLDA is
declared as a template and allocated dynamically when the query is run.
182 switch (sel_index)
183 {
184 case 1 : strcpy(column, "EMPNUM ");
185 break;
186 case 2 : strcpy(column, "JOBCODE ");
187 break;
188 case 3 : strcpy(column, "DEPTNUM ");
189 break;
190 }
191
192 printf("\nPlease enter the comparison criteria:\n");
193 printf("(for example: > 500, = 1000, <= 250)\n\n");
194
195 fgets(temp, (int)sizeof(temp), stdin);
196 sscanf(temp, "%[^\n]", predicate);
197
198 /* Construct the SQL statement: */
199 strcat (cmd, column);
200 strcat (cmd, predicate);
201
202 /* Get length of command string and blank out null */
203 /* terminator for transmission to SQL: */
204 len = strlen(cmd);
205 cmd[len] = ' ';
206
207 } /* end of get_cmd */
208
209 /* -------------------------------------------------- */
210
211 main()
212 {
213 /* Initialize command string to blanks: */
214 setmem (cmd, MAXCMD, ' ');
215
216 /* Get SQL statement from the user: */
217 get_cmd(cmd);
218
219 /* Compile the statement, access the SQL database, and */
220 /* report the result: */
221 process_and_execute(cmd);
222
223 } /* end of main */
Example 10-7. Basic Dynamic SQL Program
(page 4 of 4)
Summary of Contents for NonStop SQL/MP
Page 4: ......
Page 14: ...Contents HP NonStop SQL MP Programming Manual for C 429847 008 x ...
Page 60: ...Host Variables HP NonStop SQL MP Programming Manual for C 429847 008 2 26 VARCHAR Data Type ...
Page 294: ...SQL MP Sample Database HP NonStop SQL MP Programming Manual for C 429847 008 A 6 ...