Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 1a9b061

Browse files
author
Michael Meskes
committed
- Applied error reporting patch by Matthew Vanecek
- Started with an Informix compatibility option.
1 parent e529e9f commit 1a9b061

File tree

9 files changed

+116
-26
lines changed

9 files changed

+116
-26
lines changed

src/interfaces/ecpg/ChangeLog

+10
Original file line numberDiff line numberDiff line change
@@ -1324,3 +1324,13 @@ Tue Jan 21 20:50:58 CET 2003
13241324

13251325
- Set ecpg version to 2.11.0.
13261326
- Synced preproc.y with gram.y.
1327+
1328+
Thu Feb 13 14:06:28 CET 2003
1329+
1330+
- Applied patch by Matthew Vanecek <mevanecek@yahoo.com> for better
1331+
error reporting.
1332+
- Started working on an Informix compatibility mode. With option "-C
1333+
INFORMIX" set, ecpg now accepts "$" as alias for "exec sql" and to
1334+
denote variables inside SQL statements.
1335+
- Set ecpg version to 2.12.0.
1336+

src/interfaces/ecpg/lib/Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55
# Copyright (c) 1994, Regents of the University of California
66
#
7-
# $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/Makefile,v 1.18 2002/12/11 04:07:39 momjian Exp $
7+
# $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/Makefile,v 1.19 2003/02/13 13:11:52 meskes Exp $
88
#
99
#-------------------------------------------------------------------------
1010

@@ -16,7 +16,7 @@ NAME= ecpg
1616
SO_MAJOR_VERSION= 3
1717
SO_MINOR_VERSION= 4.2
1818

19-
override CPPFLAGS := -I$(top_srcdir)/src/interfaces/ecpg/include -I$(libpq_srcdir) $(CPPFLAGS)
19+
override CPPFLAGS := -g -I$(top_srcdir)/src/interfaces/ecpg/include -I$(libpq_srcdir) $(CPPFLAGS)
2020

2121

2222
OBJS= execute.o typename.o descriptor.o data.o error.o prepare.o memory.o \

src/interfaces/ecpg/lib/connect.c

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/connect.c,v 1.19 2002/09/04 20:31:46 momjian Exp $ */
1+
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/connect.c,v 1.20 2003/02/13 13:11:52 meskes Exp $ */
22

33
#include "postgres_fe.h"
44

@@ -419,15 +419,20 @@ ECPGconnect(int lineno, const char *name, const char *user, const char *passwd,
419419

420420
if (PQstatus(this->connection) == CONNECTION_BAD)
421421
{
422+
const char *errmsg = PQerrorMessage(this->connection);
423+
char *db = realname ? realname : "<DEFAULT>";
424+
425+
set_backend_err(errmsg, lineno);
422426
ecpg_finish(this);
423-
ECPGlog("connect: could not open database %s on %s port %s %s%s%s%s in line %d\n",
424-
realname ? realname : "<DEFAULT>",
427+
ECPGlog("connect: could not open database %s on %s port %s %s%s%s%s in line %d\n\t%s\n",
428+
db,
425429
host ? host : "<DEFAULT>",
426430
port ? port : "<DEFAULT>",
427431
options ? "with options " : "", options ? options : "",
428432
user ? "for user " : "", user ? user : "",
429-
lineno);
430-
ECPGraise(lineno, ECPG_CONNECT, realname ? realname : "<DEFAULT>");
433+
lineno, errmsg);
434+
435+
ECPGraise(lineno, ECPG_CONNECT, db);
431436
if (host)
432437
ECPGfree(host);
433438
if (port)

src/interfaces/ecpg/lib/error.c

+28-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/error.c,v 1.16 2002/09/04 20:31:46 momjian Exp $ */
1+
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/error.c,v 1.17 2003/02/13 13:11:52 meskes Exp $ */
22

33
#include "postgres_fe.h"
44

@@ -10,6 +10,10 @@
1010
#include "extern.h"
1111
#include "sqlca.h"
1212

13+
/* This should hold the back-end error message from
14+
* the last back-end operation. */
15+
char *ECPGerr;
16+
1317
void
1418
ECPGraise(int line, int code, const char *str)
1519
{
@@ -162,6 +166,29 @@ ECPGraise(int line, int code, const char *str)
162166
ECPGfree_auto_mem();
163167
}
164168

169+
/* Set the error message string from the backend */
170+
void
171+
set_backend_err(const char *err, int lineno)
172+
{
173+
if (ECPGerr)
174+
ECPGfree(ECPGerr);
175+
176+
if (!err)
177+
{
178+
ECPGerr = NULL;
179+
return;
180+
}
181+
182+
ECPGerr = ECPGstrdup(err, lineno);
183+
}
184+
185+
/* Retrieve the error message from the backend. */
186+
char *
187+
ECPGerrmsg(void)
188+
{
189+
return ECPGerr;
190+
}
191+
165192
/* print out an error message */
166193
void
167194
sqlprint(void)

src/interfaces/ecpg/lib/execute.c

+17-13
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/execute.c,v 1.40 2002/10/21 13:09:31 meskes Exp $ */
1+
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/execute.c,v 1.41 2003/02/13 13:11:52 meskes Exp $ */
22

33
/*
44
* The aim is to get a simpler inteface to the database routines.
@@ -850,6 +850,7 @@ ECPGexecute(struct statement * stmt)
850850
{
851851
bool status = false;
852852
char *copiedquery;
853+
char *errmsg, *cmdstat;
853854
PGresult *results;
854855
PGnotify *notify;
855856
struct variable *var;
@@ -949,9 +950,10 @@ ECPGexecute(struct statement * stmt)
949950

950951
if (results == NULL)
951952
{
952-
ECPGlog("ECPGexecute line %d: error: %s", stmt->lineno,
953-
PQerrorMessage(stmt->connection->connection));
954-
ECPGraise(stmt->lineno, ECPG_PGSQL, PQerrorMessage(stmt->connection->connection));
953+
errmsg = PQerrorMessage(stmt->connection->connection);
954+
ECPGlog("ECPGexecute line %d: error: %s", stmt->lineno, errmsg);
955+
ECPGraise(stmt->lineno, ECPG_PGSQL, errmsg);
956+
set_backend_err(errmsg, stmt->lineno);
955957
}
956958
else
957959

@@ -961,7 +963,9 @@ ECPGexecute(struct statement * stmt)
961963
*/
962964
{
963965
bool clear_result = TRUE;
964-
966+
errmsg = PQresultErrorMessage(results);
967+
set_backend_err(errmsg, stmt->lineno);
968+
965969
var = stmt->outlist;
966970
switch (PQresultStatus(results))
967971
{
@@ -1027,20 +1031,20 @@ ECPGexecute(struct statement * stmt)
10271031
break;
10281032
case PGRES_COMMAND_OK:
10291033
status = true;
1034+
cmdstat = PQcmdStatus(results);
10301035
sqlca.sqlerrd[1] = PQoidValue(results);
10311036
sqlca.sqlerrd[2] = atol(PQcmdTuples(results));
1032-
ECPGlog("ECPGexecute line %d Ok: %s\n", stmt->lineno, PQcmdStatus(results));
1033-
if (!sqlca.sqlerrd[2] && (!strncmp(PQcmdStatus(results), "UPDATE", 6)
1034-
|| !strncmp(PQcmdStatus(results), "INSERT", 6)
1035-
|| !strncmp(PQcmdStatus(results), "DELETE", 6)))
1037+
ECPGlog("ECPGexecute line %d Ok: %s\n", stmt->lineno, cmdstat);
1038+
if (!sqlca.sqlerrd[2] && ( !strncmp(cmdstat, "UPDATE", 6)
1039+
|| !strncmp(cmdstat, "INSERT", 6)
1040+
|| !strncmp(cmdstat, "DELETE", 6)))
10361041
ECPGraise(stmt->lineno, ECPG_NOT_FOUND, NULL);
10371042
break;
10381043
case PGRES_NONFATAL_ERROR:
10391044
case PGRES_FATAL_ERROR:
10401045
case PGRES_BAD_RESPONSE:
1041-
ECPGlog("ECPGexecute line %d: Error: %s",
1042-
stmt->lineno, PQerrorMessage(stmt->connection->connection));
1043-
ECPGraise(stmt->lineno, ECPG_PGSQL, PQerrorMessage(stmt->connection->connection));
1046+
ECPGlog("ECPGexecute line %d: Error: %s", stmt->lineno, errmsg);
1047+
ECPGraise(stmt->lineno, ECPG_PGSQL, errmsg);
10441048
status = false;
10451049
break;
10461050
case PGRES_COPY_OUT:
@@ -1054,7 +1058,7 @@ ECPGexecute(struct statement * stmt)
10541058
default:
10551059
ECPGlog("ECPGexecute line %d: Got something else, postgres error.\n",
10561060
stmt->lineno);
1057-
ECPGraise(stmt->lineno, ECPG_PGSQL, PQerrorMessage(stmt->connection->connection));
1061+
ECPGraise(stmt->lineno, ECPG_PGSQL, errmsg);
10581062
status = false;
10591063
break;
10601064
}

src/interfaces/ecpg/lib/extern.h

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
#include "libpq-fe.h"
66

77
/* Here are some methods used by the lib. */
8+
9+
/* Stores the backend error message for client access */
10+
void set_backend_err(const char *err, int lineon);
11+
812
/* Returns a pointer to a string containing a simple type name. */
913
void ECPGadd_mem(void *ptr, int lineno);
1014

src/interfaces/ecpg/preproc/ecpg.c

+16-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/ecpg.c,v 1.58 2002/10/18 22:05:36 petere Exp $ */
1+
/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/ecpg.c,v 1.59 2003/02/13 13:11:52 meskes Exp $ */
22

33
/* New main for ecpg, the PostgreSQL embedded SQL precompiler. */
44
/* (C) Michael Meskes <meskes@postgresql.org> Feb 5th, 1998 */
@@ -19,6 +19,9 @@ extern char *optarg;
1919
int ret_value = 0,
2020
autocommit = false,
2121
auto_create_c = false;
22+
23+
enum COMPAT_MODE compat = ECPG_COMPAT_PGSQL;
24+
2225
struct _include_path *include_paths = NULL;
2326
struct cursor *cur = NULL;
2427
struct typedefs *types = NULL;
@@ -38,6 +41,8 @@ help(const char *progname)
3841
#ifdef YYDEBUG
3942
printf(" -d generate parser debug output\n");
4043
#endif
44+
printf(" -C <mode> set compatibility mode\n"
45+
" mode may be INFORMIX only at the moment\n");
4146
printf(" -D SYMBOL define SYMBOL\n");
4247
printf(" -I DIRECTORY search DIRECTORY for include files\n");
4348
printf(" -o OUTFILE write result to OUTFILE\n");
@@ -107,7 +112,7 @@ main(int argc, char *const argv[])
107112
add_include_path("/usr/local/include");
108113
add_include_path(".");
109114

110-
while ((c = getopt(argc, argv, "vco:I:tD:d")) != -1)
115+
while ((c = getopt(argc, argv, "vco:I:tD:dC:")) != -1)
111116
{
112117
switch (c)
113118
{
@@ -130,6 +135,15 @@ main(int argc, char *const argv[])
130135
case 'c':
131136
auto_create_c = true;
132137
break;
138+
case 'C':
139+
if (strcmp(optarg, "INFORMIX") == 0)
140+
compat = ECPG_COMPAT_INFORMIX;
141+
else
142+
{
143+
fprintf(stderr, "Try '%s --help' for more information.\n", argv[0]);
144+
return ILLEGAL_OPTION;
145+
}
146+
break;
133147
case 'D':
134148
add_preprocessor_define(optarg);
135149
break;

src/interfaces/ecpg/preproc/extern.h

+3
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,7 @@ extern ScanKeyword *ScanKeywordLookup(char *text);
9393
#define INDICATOR_NOT_STRUCT 6
9494
#define INDICATOR_NOT_SIMPLE 7
9595

96+
enum COMPAT_MODE { ECPG_COMPAT_PGSQL = 0, ECPG_COMPAT_INFORMIX};
97+
extern enum COMPAT_MODE compat;
98+
9699
#endif /* _ECPG_PREPROC_EXTERN_H */

src/interfaces/ecpg/preproc/pgc.l

+26-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*
1313
*
1414
* IDENTIFICATION
15-
* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/pgc.l,v 1.101 2002/11/07 06:06:17 tgl Exp $
15+
* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/pgc.l,v 1.102 2003/02/13 13:11:52 meskes Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
@@ -70,7 +70,6 @@ static struct _if_value
7070

7171
%option 8bit
7272
%option never-interactive
73-
%option nounput
7473
%option noyywrap
7574

7675
%option yylineno
@@ -247,6 +246,10 @@ whitespace ({space}+|{comment})
247246
horiz_whitespace ({horiz_space}|{comment})
248247
whitespace_with_newline ({horiz_whitespace}*{newline}{whitespace}*)
249248

249+
/* special characters for other dbms */
250+
/* we have to react differently in compat mode */
251+
informix_special [\$]
252+
250253
other .
251254

252255
/* some stuff needed for ecpg */
@@ -416,6 +419,16 @@ cppline {space}*#(.*\\{space})*.*
416419
}
417420
<xdc>{xdcinside} { addlit(yytext, yyleng); }
418421
<SQL>{typecast} { return TYPECAST; }
422+
<SQL>{informix_special} {
423+
/* are we simulating Informix? */
424+
if (compat == ECPG_COMPAT_INFORMIX)
425+
{
426+
printf ("unput $\n");
427+
unput(':');
428+
}
429+
else
430+
return yytext[0];
431+
}
419432
<SQL>{self} { /*
420433
* We may find a ';' inside a structure
421434
* definition in a TYPE or VAR statement.
@@ -584,7 +597,17 @@ cppline {space}*#(.*\\{space})*.*
584597
}
585598
<SQL>{other} { return yytext[0]; }
586599
<C>{exec_sql} { BEGIN SQL; return SQL_START; }
587-
<C>{ccomment} { /* ignore */ }
600+
<C>{informix_special} {
601+
/* are we simulating Informix? */
602+
if (compat == ECPG_COMPAT_INFORMIX)
603+
{
604+
BEGIN SQL;
605+
return SQL_START;
606+
}
607+
else
608+
return S_ANYTHING;
609+
}
610+
<C>{ccomment} { /* ignore */ }
588611
<C>{xch} {
589612
char* endptr;
590613

0 commit comments

Comments
 (0)