1- /* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/ecpg.header,v 1.12 2010/01/29 15:57:01 meskes Exp $ */
1+ /* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/ecpg.header,v 1.13 2010/01/29 16:28:13 meskes Exp $ */
22
33/* Copyright comment */
44%{
@@ -227,7 +227,7 @@ create_questionmarks(char *name, bool array)
227227}
228228
229229static char *
230- adjust_outofscope_cursor_vars(struct cursor *cur, bool insert )
230+ adjust_outofscope_cursor_vars(struct cursor *cur)
231231{
232232 /* Informix accepts DECLARE with variables that are out of scope when OPEN is called.
233233 * For instance you can DECLARE a cursor in one function, and OPEN/FETCH/CLOSE
@@ -240,132 +240,137 @@ adjust_outofscope_cursor_vars(struct cursor *cur, bool insert)
240240 * instead of the variable. Do it only for local variables, not for globals.
241241 */
242242
243- struct arguments *list;
244- struct arguments *ptr;
245- struct arguments *newlist = NULL;
246- struct variable *newvar, *newind;
247243 char *result = make_str("");
244+ int insert;
248245
249- list = (insert ? cur->argsinsert : cur->argsresult);
250-
251- for (ptr = list; ptr != NULL; ptr = ptr->next)
246+ for (insert = 1; insert >= 0; insert--)
252247 {
253- char temp[20]; /* this should be sufficient unless you have 8 byte integers */
254- char *original_var;
255- bool skip_set_var = false;
248+ struct arguments *list;
249+ struct arguments *ptr;
250+ struct arguments *newlist = NULL;
251+ struct variable *newvar, *newind;
256252
257- /* change variable name to "ECPGget_var(<counter>)" */
258- original_var = ptr->variable->name;
259- sprintf(temp, "%d))", ecpg_internal_var);
253+ list = (insert ? cur->argsinsert : cur->argsresult);
260254
261- /* Don't emit ECPGset_var() calls for global variables */
262- if (ptr->variable->brace_level == 0)
263- {
264- newvar = ptr->variable;
265- skip_set_var = true;
266- }
267- else if ((ptr->variable->type->type == ECPGt_char_variable) && (!strncmp(ptr->variable->name, "ECPGprepared_statement", strlen("ECPGprepared_statement"))))
268- {
269- newvar = ptr->variable;
270- skip_set_var = true;
271- }
272- else if ((ptr->variable->type->type != ECPGt_varchar && ptr->variable->type->type != ECPGt_char && ptr->variable->type->type != ECPGt_unsigned_char && ptr->variable->type->type != ECPGt_string) && atoi(ptr->variable->type->size) > 1)
255+ for (ptr = list; ptr != NULL; ptr = ptr->next)
273256 {
274- newvar = new_variable(cat_str(4, make_str("("), mm_strdup(ecpg_type_name(ptr->variable->type->u.element->type)), make_str(" *)(ECPGget_var("), mm_strdup(temp)), ECPGmake_array_type(ECPGmake_simple_type(ptr->variable->type->u.element->type, make_str("1"), ptr->variable->type->u.element->lineno), ptr->variable->type->size), 0);
275- sprintf(temp, "%d, (", ecpg_internal_var++);
276- }
277- else if ((ptr->variable->type->type == ECPGt_varchar || ptr->variable->type->type == ECPGt_char || ptr->variable->type->type == ECPGt_unsigned_char || ptr->variable->type->type == ECPGt_string) && atoi(ptr->variable->type->size) > 1)
278- {
279- newvar = new_variable(cat_str(4, make_str("("), mm_strdup(ecpg_type_name(ptr->variable->type->type)), make_str(" *)(ECPGget_var("), mm_strdup(temp)), ECPGmake_simple_type(ptr->variable->type->type, ptr->variable->type->size, ptr->variable->type->lineno), 0);
280- if (ptr->variable->type->type == ECPGt_varchar)
281- sprintf(temp, "%d, &(", ecpg_internal_var++);
282- else
283- sprintf(temp, "%d, (", ecpg_internal_var++);
284- }
285- else if (ptr->variable->type->type == ECPGt_struct || ptr->variable->type->type == ECPGt_union)
286- {
287- sprintf(temp, "%d)))", ecpg_internal_var);
288- newvar = new_variable(cat_str(4, make_str("(*("), mm_strdup(ptr->variable->type->type_name), make_str(" *)(ECPGget_var("), mm_strdup(temp)), ECPGmake_struct_type(ptr->variable->type->u.members, ptr->variable->type->type, ptr->variable->type->type_name, ptr->variable->type->struct_sizeof), 0);
289- sprintf(temp, "%d, &(", ecpg_internal_var++);
290- }
291- else if (ptr->variable->type->type == ECPGt_array)
292- {
293- if (ptr->variable->type->u.element->type == ECPGt_struct || ptr->variable->type->u.element->type == ECPGt_union)
257+ char temp[20];
258+ char *original_var;
259+ bool skip_set_var = false;
260+
261+ /* change variable name to "ECPGget_var(<counter>)" */
262+ original_var = ptr->variable->name;
263+ sprintf(temp, "%d))", ecpg_internal_var);
264+
265+ /* Don't emit ECPGset_var() calls for global variables */
266+ if (ptr->variable->brace_level == 0)
294267 {
295- sprintf(temp, "%d)))", ecpg_internal_var);
296- newvar = new_variable(cat_str(4, make_str("(*("), mm_strdup(ptr->variable->type->u.element->type_name), make_str(" *)(ECPGget_var("), mm_strdup(temp)), ECPGmake_struct_type(ptr->variable->type->u.element->u.members, ptr->variable->type->u.element->type, ptr->variable->type->u.element->type_name, ptr->variable->type->u.element->struct_sizeof), 0);
268+ newvar = ptr->variable;
269+ skip_set_var = true;
270+ }
271+ else if ((ptr->variable->type->type == ECPGt_char_variable) && (!strncmp(ptr->variable->name, "ECPGprepared_statement", strlen("ECPGprepared_statement"))))
272+ {
273+ newvar = ptr->variable;
274+ skip_set_var = true;
275+ }
276+ else if ((ptr->variable->type->type != ECPGt_varchar && ptr->variable->type->type != ECPGt_char && ptr->variable->type->type != ECPGt_unsigned_char && ptr->variable->type->type != ECPGt_string) && atoi(ptr->variable->type->size) > 1)
277+ {
278+ newvar = new_variable(cat_str(4, make_str("("), mm_strdup(ecpg_type_name(ptr->variable->type->u.element->type)), make_str(" *)(ECPGget_var("), mm_strdup(temp)), ECPGmake_array_type(ECPGmake_simple_type(ptr->variable->type->u.element->type, make_str("1"), ptr->variable->type->u.element->lineno), ptr->variable->type->size), 0);
297279 sprintf(temp, "%d, (", ecpg_internal_var++);
298280 }
299- else
281+ else if ((ptr->variable->type->type == ECPGt_varchar || ptr->variable->type->type == ECPGt_char || ptr->variable->type->type == ECPGt_unsigned_char || ptr->variable->type->type == ECPGt_string) && atoi(ptr->variable->type->size) > 1)
300282 {
301- newvar = new_variable(cat_str(4, make_str("("), mm_strdup(ecpg_type_name(ptr->variable->type->type)), make_str(" *)(ECPGget_var("), mm_strdup(temp)), ECPGmake_array_type(ECPGmake_simple_type(ptr->variable->type->u.element->type, ptr->variable->type->u.element->size, ptr->variable->type->u.element->lineno), ptr->variable->type->size), 0);
302- sprintf(temp, "%d, &(", ecpg_internal_var++);
283+ newvar = new_variable(cat_str(4, make_str("("), mm_strdup(ecpg_type_name(ptr->variable->type->type)), make_str(" *)(ECPGget_var("), mm_strdup(temp)), ECPGmake_simple_type(ptr->variable->type->type, ptr->variable->type->size, ptr->variable->type->lineno), 0);
284+ if (ptr->variable->type->type == ECPGt_varchar)
285+ sprintf(temp, "%d, &(", ecpg_internal_var++);
286+ else
287+ sprintf(temp, "%d, (", ecpg_internal_var++);
303288 }
304- }
305- else
306- {
307- newvar = new_variable(cat_str(4, make_str("*("), mm_strdup(ecpg_type_name(ptr->variable->type->type)), make_str(" *)(ECPGget_var("), mm_strdup(temp)), ECPGmake_simple_type(ptr->variable->type->type, ptr->variable->type->size, ptr->variable->type->lineno), 0);
308- sprintf(temp, "%d, &(", ecpg_internal_var++);
309- }
310-
311- /* create call to "ECPGset_var(<counter>, <pointer>, <line number>)" */
312- if (!skip_set_var)
313- result = cat_str(5, result, make_str("ECPGset_var("), mm_strdup(temp), mm_strdup(original_var), make_str("), __LINE__);\n"));
314-
315- /* now the indicator if there is one and it's not a global variable */
316- if ((ptr->indicator->type->type == ECPGt_NO_INDICATOR) || (ptr->indicator->brace_level == 0))
317- {
318- newind = ptr->indicator;
319- }
320- else
321- {
322- /* change variable name to "ECPGget_var(<counter>)" */
323- original_var = ptr->indicator->name;
324- sprintf(temp, "%d))", ecpg_internal_var);
325-
326- if (ptr->indicator->type->type == ECPGt_struct || ptr->indicator->type->type == ECPGt_union)
289+ else if (ptr->variable->type->type == ECPGt_struct || ptr->variable->type->type == ECPGt_union)
327290 {
328291 sprintf(temp, "%d)))", ecpg_internal_var);
329- newind = new_variable(cat_str(4, make_str("(*("), mm_strdup(ptr->indicator ->type->type_name), make_str(" *)(ECPGget_var("), mm_strdup(temp)), ECPGmake_struct_type(ptr->indicator ->type->u.members, ptr->indicator ->type->type, ptr->indicator ->type->type_name, ptr->indicator ->type->struct_sizeof), 0);
292+ newvar = new_variable(cat_str(4, make_str("(*("), mm_strdup(ptr->variable ->type->type_name), make_str(" *)(ECPGget_var("), mm_strdup(temp)), ECPGmake_struct_type(ptr->variable ->type->u.members, ptr->variable ->type->type, ptr->variable ->type->type_name, ptr->variable ->type->struct_sizeof), 0);
330293 sprintf(temp, "%d, &(", ecpg_internal_var++);
331294 }
332- else if (ptr->indicator ->type->type == ECPGt_array)
295+ else if (ptr->variable ->type->type == ECPGt_array)
333296 {
334- if (ptr->indicator ->type->u.element->type == ECPGt_struct || ptr->indicator ->type->u.element->type == ECPGt_union)
297+ if (ptr->variable ->type->u.element->type == ECPGt_struct || ptr->variable ->type->u.element->type == ECPGt_union)
335298 {
336299 sprintf(temp, "%d)))", ecpg_internal_var);
337- newind = new_variable(cat_str(4, make_str("(*("), mm_strdup(ptr->indicator ->type->u.element->type_name), make_str(" *)(ECPGget_var("), mm_strdup(temp)), ECPGmake_struct_type(ptr->indicator ->type->u.element->u.members, ptr->indicator ->type->u.element->type, ptr->indicator ->type->u.element->type_name, ptr->indicator ->type->u.element->struct_sizeof), 0);
300+ newvar = new_variable(cat_str(4, make_str("(*("), mm_strdup(ptr->variable ->type->u.element->type_name), make_str(" *)(ECPGget_var("), mm_strdup(temp)), ECPGmake_struct_type(ptr->variable ->type->u.element->u.members, ptr->variable ->type->u.element->type, ptr->variable ->type->u.element->type_name, ptr->variable ->type->u.element->struct_sizeof), 0);
338301 sprintf(temp, "%d, (", ecpg_internal_var++);
339302 }
340303 else
341304 {
342- newind = new_variable(cat_str(4, make_str("("), mm_strdup(ecpg_type_name(ptr->indicator ->type->u.element-> type)), make_str(" *)(ECPGget_var("), mm_strdup(temp)), ECPGmake_array_type(ECPGmake_simple_type(ptr->indicator ->type->u.element->type, ptr->indicator ->type->u.element->size, ptr->indicator ->type->u.element->lineno), ptr->indicator ->type->size), 0);
305+ newvar = new_variable(cat_str(4, make_str("("), mm_strdup(ecpg_type_name(ptr->variable ->type->type)), make_str(" *)(ECPGget_var("), mm_strdup(temp)), ECPGmake_array_type(ECPGmake_simple_type(ptr->variable ->type->u.element->type, ptr->variable ->type->u.element->size, ptr->variable ->type->u.element->lineno), ptr->variable ->type->size), 0);
343306 sprintf(temp, "%d, &(", ecpg_internal_var++);
344307 }
345308 }
346- else if (atoi(ptr->indicator->type->size) > 1)
309+ else
347310 {
348- newind = new_variable(cat_str(4, make_str("("), mm_strdup(ecpg_type_name(ptr->indicator->type->type)), make_str(" *)(ECPGget_var("), mm_strdup(temp)), ECPGmake_simple_type(ptr->indicator->type->type, ptr->indicator->type->size, ptr->variable->type->lineno), 0);
349- sprintf(temp, "%d, (", ecpg_internal_var++);
311+ newvar = new_variable(cat_str(4, make_str("*("), mm_strdup(ecpg_type_name(ptr->variable->type->type)), make_str(" *)(ECPGget_var("), mm_strdup(temp)), ECPGmake_simple_type(ptr->variable->type->type, ptr->variable->type->size, ptr->variable->type->lineno), 0);
312+ sprintf(temp, "%d, &(", ecpg_internal_var++);
313+ }
314+
315+ /* create call to "ECPGset_var(<counter>, <pointer>. <line number>)" */
316+ if (!skip_set_var)
317+ result = cat_str(5, result, make_str("ECPGset_var("), mm_strdup(temp), mm_strdup(original_var), make_str("), __LINE__);\n"));
318+
319+ /* now the indicator if there is one and it's not a global variable */
320+ if ((ptr->indicator->type->type == ECPGt_NO_INDICATOR) || (ptr->indicator->brace_level == 0))
321+ {
322+ newind = ptr->indicator;
350323 }
351324 else
352325 {
353- newind = new_variable(cat_str(4, make_str("*("), mm_strdup(ecpg_type_name(ptr->indicator->type->type)), make_str(" *)(ECPGget_var("), mm_strdup(temp)), ECPGmake_simple_type(ptr->indicator->type->type, ptr->indicator->type->size, ptr->variable->type->lineno), 0);
354- sprintf(temp, "%d, &(", ecpg_internal_var++);
326+ /* change variable name to "ECPGget_var(<counter>)" */
327+ original_var = ptr->indicator->name;
328+ sprintf(temp, "%d))", ecpg_internal_var);
329+
330+ if (ptr->indicator->type->type == ECPGt_struct || ptr->indicator->type->type == ECPGt_union)
331+ {
332+ sprintf(temp, "%d)))", ecpg_internal_var);
333+ newind = new_variable(cat_str(4, make_str("(*("), mm_strdup(ptr->indicator->type->type_name), make_str(" *)(ECPGget_var("), mm_strdup(temp)), ECPGmake_struct_type(ptr->indicator->type->u.members, ptr->indicator->type->type, ptr->indicator->type->type_name, ptr->indicator->type->struct_sizeof), 0);
334+ sprintf(temp, "%d, &(", ecpg_internal_var++);
335+ }
336+ else if (ptr->indicator->type->type == ECPGt_array)
337+ {
338+ if (ptr->indicator->type->u.element->type == ECPGt_struct || ptr->indicator->type->u.element->type == ECPGt_union)
339+ {
340+ sprintf(temp, "%d)))", ecpg_internal_var);
341+ newind = new_variable(cat_str(4, make_str("(*("), mm_strdup(ptr->indicator->type->u.element->type_name), make_str(" *)(ECPGget_var("), mm_strdup(temp)), ECPGmake_struct_type(ptr->indicator->type->u.element->u.members, ptr->indicator->type->u.element->type, ptr->indicator->type->u.element->type_name, ptr->indicator->type->u.element->struct_sizeof), 0);
342+ sprintf(temp, "%d, (", ecpg_internal_var++);
343+ }
344+ else
345+ {
346+ newind = new_variable(cat_str(4, make_str("("), mm_strdup(ecpg_type_name(ptr->indicator->type->u.element->type)), make_str(" *)(ECPGget_var("), mm_strdup(temp)), ECPGmake_array_type(ECPGmake_simple_type(ptr->indicator->type->u.element->type, ptr->indicator->type->u.element->size, ptr->indicator->type->u.element->lineno), ptr->indicator->type->size), 0);
347+ sprintf(temp, "%d, &(", ecpg_internal_var++);
348+ }
349+ }
350+ else if (atoi(ptr->indicator->type->size) > 1)
351+ {
352+ newind = new_variable(cat_str(4, make_str("("), mm_strdup(ecpg_type_name(ptr->indicator->type->type)), make_str(" *)(ECPGget_var("), mm_strdup(temp)), ECPGmake_simple_type(ptr->indicator->type->type, ptr->indicator->type->size, ptr->variable->type->lineno), 0);
353+ sprintf(temp, "%d, (", ecpg_internal_var++);
354+ }
355+ else
356+ {
357+ newind = new_variable(cat_str(4, make_str("*("), mm_strdup(ecpg_type_name(ptr->indicator->type->type)), make_str(" *)(ECPGget_var("), mm_strdup(temp)), ECPGmake_simple_type(ptr->indicator->type->type, ptr->indicator->type->size, ptr->variable->type->lineno), 0);
358+ sprintf(temp, "%d, &(", ecpg_internal_var++);
359+ }
360+
361+ /* create call to "ECPGset_var(<counter>, <pointer>. <line number>)" */
362+ result = cat_str(5, result, make_str("ECPGset_var("), mm_strdup(temp), mm_strdup(original_var), make_str("), __LINE__);\n"));
355363 }
356364
357- /* create call to "ECPGset_var(<counter>, <pointer>, <line number>)" */
358- result = cat_str(5, result, make_str("ECPGset_var("), mm_strdup(temp), mm_strdup(original_var), make_str("), __LINE__);\n"));
365+ add_variable_to_tail(&newlist, newvar, newind);
359366 }
360367
361- add_variable_to_tail(&newlist, newvar, newind);
368+ if (insert)
369+ cur->argsinsert_oos = newlist;
370+ else
371+ cur->argsresult_oos = newlist;
362372 }
363373
364- if (insert)
365- cur->argsinsert_oos = newlist;
366- else
367- cur->argsresult_oos = newlist;
368-
369374 return result;
370375}
371376
0 commit comments