Skip to content

Commit 1d6424b

Browse files
committed
From: Michael Meskes <meskes@topsystem.de>
Here's my next patch. this one should fix some more bugs. ecpg now fully understands the whenever statement.
1 parent ed875a4 commit 1d6424b

File tree

11 files changed

+242
-51
lines changed

11 files changed

+242
-51
lines changed

src/interfaces/ecpg/ChangeLog

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,12 @@ Mon Feb 16 16:17:21 CET 1998
2929

3030
- enable initialisation in declare section.
3131
- connect call accepts a variable as well.
32+
33+
Wed Feb 18 21:41:30 CET 1998
34+
35+
- added whenever statement
36+
37+
Thu Feb 19 12:48:14 CET 1998
38+
39+
- added do option to whenever statement
40+

src/interfaces/ecpg/TODO

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ This list is still from Linus. MM
33
The variables should be static.
44

55
Preprocessor cannot do syntax checking on your SQL statements Whatever you
6-
write is copied more or less exactly to the postgres95 and you will not be
6+
write is copied more or less exactly to the PostgreSQL and you will not be
77
able to locate your errors until run-time.
88

99
No restriction to strings only The PQ interface, and most of all the PQexec
@@ -42,4 +42,6 @@ Now comes my list (MM):
4242

4343
What do we do with enum data types?
4444

45-
'signed' isn't understood so far
45+
The cursor is opened when the declare statement is issued.
46+
47+
The is no exec sql prepare statement.

src/interfaces/ecpg/include/ecpglib.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,9 @@ struct ECPGgeneric_varchar {
2424
char arr[1];
2525
};
2626

27+
/* print an error message */
28+
void sqlprint(void);
2729

30+
/* define this for simplicity as well as compatibility */
31+
32+
#define SQLCODE sqlca.sqlcode

src/interfaces/ecpg/lib/ecpglib.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ ECPGdo(int lineno, char *query,...)
232232
return false;
233233
}
234234

235-
/* Now then request is built. */
235+
/* Now the request is built. */
236236

237237
if (committed)
238238
{
@@ -646,3 +646,10 @@ ECPGlog(const char *format,...)
646646
free(f);
647647
}
648648
}
649+
650+
/* print out an error message */
651+
void sqlprint(void)
652+
{
653+
sqlca.sqlerrm.sqlerrmc[sqlca.sqlerrm.sqlerrml] = '\0';
654+
printf ("sql error %s\n", sqlca.sqlerrm.sqlerrmc);
655+
}

src/interfaces/ecpg/preproc/ecpg.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,18 @@ main(int argc, char *const argv[])
5454
for (fnr = optind; fnr < argc; fnr++)
5555
{
5656
char *filename, *ptr2ext;
57+
int ext = 0;
5758

58-
filename = mm_alloc(strlen(argv[fnr]) + 2);
59+
filename = mm_alloc(strlen(argv[fnr]) + 4);
5960

6061
strcpy(filename, argv[fnr]);
6162

6263
ptr2ext = strrchr(filename, '.');
6364
/* no extension or extension not equal .pgc */
6465
if (ptr2ext == NULL || strcmp(ptr2ext, ".pgc") != 0)
6566
{
67+
if (ptr2ext == NULL)
68+
ext = 1; /* we need this information a while later */
6669
ptr2ext = filename + strlen(filename);
6770
ptr2ext[0] = '.';
6871
}
@@ -82,7 +85,19 @@ main(int argc, char *const argv[])
8285
}
8386
}
8487

85-
yyin = fopen(input_filename = argv[fnr], "r");
88+
if (ext == 1)
89+
{
90+
/* no extension => add .pgc */
91+
ptr2ext = strrchr(filename, '.');
92+
ptr2ext[1] = 'p';
93+
ptr2ext[2] = 'g';
94+
ptr2ext[3] = 'c';
95+
ptr2ext[4] = '\0';
96+
input_filename = filename;
97+
}
98+
else
99+
input_filename = argv[fnr];
100+
yyin = fopen(input_filename, "r");
86101
if (yyin == NULL)
87102
perror(argv[fnr]);
88103
else

src/interfaces/ecpg/preproc/extern.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ extern FILE *yyin, *yyout;
1111
extern void lex_init(void);
1212
extern char * input_filename;
1313
extern int yyparse(void);
14-
extern void *mm_alloc(size_t);
14+
extern void *mm_alloc(size_t), *mm_realloc(void *, size_t);

src/interfaces/ecpg/preproc/pgc.l

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,35 @@ letter [A-Za-z_]
1515
digit [0-9]
1616
length {digit}+
1717
symbol {letter}({letter}|{digit})*
18+
label ({letter}|{digit})*
1819
string '[^']*'
1920

20-
exec [eE][xX][eE][cC]
21-
execute [eE][xX][eE][cC][uU][tT][eE]
22-
sql [sS][qQ][lL]
23-
varchar [vV][aA][rR][cC][hH][aA][rR]
24-
varchar2 [vV][aA][rR][cC][hH][aA][rR]2
25-
into [iI][nN][tT][oO]
2621
begin [bB][eE][gG][iI][nN]
27-
end [eE][nN][dD]
22+
break [bB][rR][eE][aA][kK]
23+
commit [cC][oO][mM][mM][iI][tT]
24+
connect [cC][oO][nN][nN][eE][cC][tT]
25+
continue [cC][oO][nN][tT][iI][nN][uU][eE]
2826
declare [dD][eE][cC][lL][aA][rR][eE]
29-
section [sS][eE][cC][tT][iI][oO][nN]
27+
do [dD][oO]
28+
end [eE][nN][dD]
29+
exec [eE][xX][eE][cC]
30+
execute [eE][xX][eE][cC][uU][tT][eE]
31+
found [fF][oO][uU][nN][dD]
32+
goto [gG][oO][tT][oO]
33+
immediate [iI][mM][mM][eE][dD][iI][aA][tT][eE]
3034
include [iI][nN][cC][lL][uU][dD][eE]
31-
connect [cC][oO][nN][nN][eE][cC][tT]
35+
into [iI][nN][tT][oO]
36+
not [nN][oO][tT]
3237
open [oO][pP][eE][nN]
33-
commit [cC][oO][mM][mM][iI][tT]
34-
immediate [iI][mM][mM][eE][dD][iI][aA][tT][eE]
3538
release [rR][eE][lL][eE][aA][sS][eE]
3639
rollback [rR][oO][lL][lL][bB][aA][cC][kK]
40+
section [sS][eE][cC][tT][iI][oO][nN]
41+
sql [sS][qQ][lL]
42+
sqlerror [sS][qQ][lL][eE][rR][rR][oO][rR]
43+
sqlprint [sS][qQ][lL][pP][rR][iI][nN][tT]
44+
varchar [vV][aA][rR][cC][hH][aA][rR]
45+
varchar2 [vV][aA][rR][cC][hH][aA][rR]2
46+
whenever [wW][hH][eE][nN][eE][vV][eE][rR]
3747
work [wW][oO][rR][kK]
3848
%%
3949
<C>{exec}{ws}{sql} { BEGIN SQL; dbg(SQL_START); return SQL_START; }
@@ -51,8 +61,15 @@ work [wW][oO][rR][kK]
5161
<SQL>{release} { dbg(SQL_RELEASE); return SQL_RELEASE; }
5262
<SQL>{work} { dbg(SQL_WORK); return SQL_WORK; }
5363
<SQL>{rollback} { dbg(SQL_ROLLBACK); return SQL_ROLLBACK; }
54-
64+
<SQL>{whenever} { dbg(SQL_WHENEVER); return SQL_WHENEVER; }
65+
<SQL>{sqlerror} { dbg(SQL_SQLERROR); return SQL_SQLERROR; }
66+
<SQL>{sqlprint} { dbg(SQL_SQLPRINT); return SQL_SQLPRINT; }
67+
<SQL>{not}{ws}{found} { dbg(SQL_NOT_FOUND); return SQL_NOT_FOUND; }
68+
<SQL>{break} { dbg(SQL_BREAK); return SQL_BREAK; }
69+
<SQL>{continue} { dbg(SQL_CONTINUE); return SQL_CONTINUE; }
5570
<SQL>{into} { dbg(SQL_INTO); return SQL_INTO; }
71+
<SQL>{goto} { dbg(SQL_GOTO); return SQL_GOTO; }
72+
<SQL>{do} { dbg(SQL_DO); return SQL_DO; }
5673

5774
{length} { dbg(S_LENGTH); return S_LENGTH; }
5875

@@ -67,6 +84,7 @@ double { dbg(S_DOUBLE); return S_DOUBLE; }
6784
bool { dbg(S_BOOL); return S_BOOL; }
6885

6986
static { dbg(S_STATIC); return S_STATIC; }
87+
signed { dbg(S_SIGNED); return S_SIGNED; }
7088
extern { dbg(S_EXTERN); return S_EXTERN; }
7189
auto { dbg(S_AUTO); return S_AUTO; }
7290
const { dbg(S_CONST); return S_CONST; }
@@ -77,6 +95,7 @@ struct { dbg(S_STRUCT); return S_STRUCT; }
7795
{string} { dbg(SQL_STRING); return SQL_STRING; }
7896
<SQL>{ws} ;
7997
{symbol} { dbg(S_SYMBOL); return S_SYMBOL; }
98+
{label} { dbg(S_LABEL); return S_LABEL; }
8099

81100
<SQL>"!<" { dbg(S_SYMBOL); return S_SYMBOL; }
82101
<SQL>"!>" { dbg(S_SYMBOL); return S_SYMBOL; }
@@ -114,8 +133,10 @@ struct { dbg(S_STRUCT); return S_STRUCT; }
114133
";" { dbg(;); return ';'; }
115134
"=" { dbg(=); return '='; }
116135
"," { dbg(komma); return ','; }
136+
\( { dbg(braceopen); return '('; }
137+
\) { dbg(braceclose); return ')'; }
117138
\{ { dbg(blockstart); return '{'; }
118-
\} { dbg(blockend); return'}'; }
139+
\} { dbg(blockend); return '}'; }
119140
\* { dbg(*); return('*'); }
120141

121142
<SQL>":" { dbg(:); return ':'; }

0 commit comments

Comments
 (0)