Made sure ecpg deletes output file in case of an error.
/* dynamic SQL support routines
*
- * $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/descriptor.c,v 1.21 2007/04/27 06:56:11 meskes Exp $
+ * $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/descriptor.c,v 1.22 2007/06/11 11:52:08 meskes Exp $
*/
#define POSTGRES_ECPG_INTERNAL
ECPGfree(var);
return false;
}
-
+ ECPGfree(desc_item->data); /* free() takes care of a potential NULL value */
desc_item->data = (char *) tobeinserted;
tobeinserted = NULL;
break;
{
if (!strcmp(name, i->name))
{
+ struct descriptor_item *desc_item;
+
+ for (desc_item = i->items; desc_item;)
+ {
+ struct descriptor_item *di;
+
+ ECPGfree(desc_item->data);
+ di = desc_item;
+ desc_item = desc_item->next;
+ ECPGfree(di);
+ }
+
*lastptr = i->next;
ECPGfree(i->name);
PQclear(i->result);
-/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.66 2007/04/27 06:56:11 meskes Exp $ */
+/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/execute.c,v 1.67 2007/06/11 11:52:08 meskes Exp $ */
/*
* The aim is to get a simpler inteface to the database routines.
* will be quoted once they are inserted in a statement
*/
if (!quote)
- return res = ECPGstrdup(arg, lineno);
+ return arg;
else
{
length = strlen(arg);
-/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/ecpg.c,v 1.98 2007/03/17 19:25:23 meskes Exp $ */
+/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/ecpg.c,v 1.99 2007/06/11 11:52:08 meskes Exp $ */
/* New main for ecpg, the PostgreSQL embedded SQL precompiler. */
/* (C) Michael Meskes <meskes@postgresql.org> Feb 5th, 1998 */
header_mode = false,
regression_mode = false;
+char *output_filename;
+
enum COMPAT_MODE compat = ECPG_COMPAT_PGSQL;
struct _include_path *include_paths = NULL;
find_my_exec(argv[0], my_exec_path);
+ output_filename = NULL;
while ((c = getopt_long(argc, argv, "vcio:I:tD:dC:r:h?", ecpg_options, NULL)) != -1)
{
switch (c)
regression_mode = true;
break;
case 'o':
- if (strcmp(optarg, "-") == 0)
+ output_filename = optarg;
+ if (strcmp(output_filename, "-") == 0)
yyout = stdout;
else
- yyout = fopen(optarg, PG_BINARY_W);
+ yyout = fopen(output_filename, PG_BINARY_W);
- if (yyout == NULL)
+ if (yyout == NULL)
+ {
fprintf(stderr, "%s: could not open file \"%s\": %s\n",
- progname, optarg, strerror(errno));
+ progname, output_filename, strerror(errno));
+ output_filename = NULL;
+ }
else
out_option = 1;
break;
/* after the options there must not be anything but filenames */
for (fnr = optind; fnr < argc; fnr++)
{
- char *output_filename = NULL,
- *ptr2ext;
+ char *ptr2ext;
/* If argv[fnr] is "-" we have to read from stdin */
if (strcmp(argv[fnr], "-") == 0)
fclose(yyout);
}
- if (output_filename)
+ if (output_filename && out_option == 0)
free(output_filename);
free(input_filename);
-/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/extern.h,v 1.65 2007/03/17 19:25:23 meskes Exp $ */
+/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/extern.h,v 1.66 2007/06/11 11:52:08 meskes Exp $ */
#ifndef _ECPG_PREPROC_EXTERN_H
#define _ECPG_PREPROC_EXTERN_H
yyleng;
extern FILE *yyin,
*yyout;
+extern char *output_filename;
extern struct _include_path *include_paths;
extern struct cursor *cur;
extern void scanner_init(const char *);
extern void parser_init(void);
extern void scanner_finish(void);
-int filtered_base_yylex(void);
+extern int filtered_base_yylex(void);
/* return codes */
-/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/preproc.y,v 1.343 2007/05/10 09:53:17 meskes Exp $ */
+/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/preproc.y,v 1.344 2007/06/11 11:52:08 meskes Exp $ */
/* Copyright comment */
%{
ret_value = error_code;
break;
case ET_FATAL:
+ fclose(yyin);
+ fclose(yyout);
+ if (unlink(output_filename) != 0)
+ fprintf(stderr, "Could not remove ourput file %s!\n", output_filename);
exit(error_code);
}
}