EasyManua.ls Logo

HP NonStop SQL/MP

HP NonStop SQL/MP
331 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
Dynamic SQL Operations
HP NonStop SQL/MP Programming Manual for C429847-008
10-41
Basic Dynamic SQL Program
122 /* set DATA_TYPE to long: */
123 osqlda.sqlvar[0].data_type = _SQLDT_32BIT_U;
124
125 /* set data_len to 4 bytes; leave scale as 0 in */
126 /* upper byte of data_len: */
127 osqlda.sqlvar[0].data_len = 4;
128
129 /* set VAR_PTR to point to the address of the output value:*/
130 osqlda.sqlvar[0].var_ptr = (long)&average;
131
132 exec sql BEGIN WORK;
133
134 exec sql DECLARE c1 CURSOR FOR dyncmd;
135 exec sql OPEN c1;
136 exec sql FETCH c1 USING DESCRIPTOR :osqlda;
137
138 if (sqlcode >= 0)
139 printf("\nThe average salary is: %ld\n",average);
140
141 exec sql CLOSE c1;
142
143 exec sql COMMIT WORK;
144
145 } /* end of process_and_execute */
146
147 /* ------------------------------------------------------- */
148
149 void get_cmd( char *cmd )
150 /* */
151 /* Assigns a SELECT statement to the statement buffer. */
152 /* Gets the WHERE clause from the user and concatenates it */
153 /* to the SELECT statement. */
154 /* */
155
156 {
157 char column[9]; /* column to be used in WHERE clause */
158 int sel_index; /* selects column for WHERE clause */
159 char predicate[10]; /* comparison predicate for WHERE */
160 /* clause */
161 size_t len; /* for length of command, to use in */
162 /* blanking out null terminator for */
163 /* transmission to SQL */
164
165 strcpy (cmd, "SELECT AVG(SALARY) FROM =EMPLOYEE WHERE ");
166
167 /* Create a simple menu: */
168 printf("\nPlease enter:\n\n");
169 printf("1 -- to find average salary based on employee number\n");
170 printf("2 -- to find average salary based on job code\n");
171 printf("3 -- to find average salary based on department number\n\n");
172
173 fgets(temp, (int)sizeof(temp), stdin);
174 sscanf(temp, "%d", &sel_index);
175
176 /* Initialize column and predicate to blanks: */
177
178 memset(column, ' ', 9);
179
180 memset(predicate, ' ', 10);
181
Example 10-7. Basic Dynamic SQL Program (page 3 of 4)

Table of Contents

Related product manuals