Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1a9b061

Browse files
author
Michael Meskes
committed
- Applied error reporting patch by Matthew Vanecek
- Started with an Informix compatibility option.
1 parente529e9f commit1a9b061

File tree

9 files changed

+116
-26
lines changed

9 files changed

+116
-26
lines changed

‎src/interfaces/ecpg/ChangeLog

Lines changed: 10 additions & 0 deletions
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

Lines changed: 2 additions & 2 deletions
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-
overrideCPPFLAGS := -I$(top_srcdir)/src/interfaces/ecpg/include -I$(libpq_srcdir)$(CPPFLAGS)
19+
overrideCPPFLAGS := -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

Lines changed: 10 additions & 5 deletions
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+
constchar*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

Lines changed: 28 additions & 1 deletion
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(intline,intcode,constchar*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(constchar*err,intlineno)
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+
returnECPGerr;
190+
}
191+
165192
/* print out an error message */
166193
void
167194
sqlprint(void)

‎src/interfaces/ecpg/lib/execute.c

Lines changed: 17 additions & 13 deletions
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
boolstatus= false;
852852
char*copiedquery;
853+
char*errmsg,*cmdstat;
853854
PGresult*results;
854855
PGnotify*notify;
855856
structvariable*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
boolclear_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
casePGRES_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
casePGRES_NONFATAL_ERROR:
10391044
casePGRES_FATAL_ERROR:
10401045
casePGRES_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
casePGRES_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

Lines changed: 4 additions & 0 deletions
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+
voidset_backend_err(constchar*err,intlineon);
11+
812
/* Returns a pointer to a string containing a simple type name. */
913
voidECPGadd_mem(void*ptr,intlineno);
1014

‎src/interfaces/ecpg/preproc/ecpg.c

Lines changed: 16 additions & 2 deletions
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
intret_value=0,
2020
autocommit= false,
2121
auto_create_c= false;
22+
23+
enumCOMPAT_MODEcompat=ECPG_COMPAT_PGSQL;
24+
2225
struct_include_path*include_paths=NULL;
2326
structcursor*cur=NULL;
2427
structtypedefs*types=NULL;
@@ -38,6 +41,8 @@ help(const char *progname)
3841
#ifdefYYDEBUG
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+
returnILLEGAL_OPTION;
145+
}
146+
break;
133147
case'D':
134148
add_preprocessor_define(optarg);
135149
break;

‎src/interfaces/ecpg/preproc/extern.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,7 @@ extern ScanKeyword *ScanKeywordLookup(char *text);
9393
#defineINDICATOR_NOT_STRUCT6
9494
#defineINDICATOR_NOT_SIMPLE7
9595

96+
enumCOMPAT_MODE {ECPG_COMPAT_PGSQL=0,ECPG_COMPAT_INFORMIX};
97+
externenumCOMPAT_MODEcompat;
98+
9699
#endif/* _ECPG_PREPROC_EXTERN_H */

‎src/interfaces/ecpg/preproc/pgc.l

Lines changed: 26 additions & 3 deletions
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
%option8bit
7272
%optionnever-interactive
73-
%optionnounput
7473
%optionnoyywrap
7574

7675
%optionyylineno
@@ -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)

[8]ページ先頭

©2009-2025 Movatter.jp