Skip to content

Commit e91600d

Browse files
author
Michael Meskes
committed
Changed lexer to no longer use the default rule.
Synced parser and keyword list. Fixed parsing of CONNECT statement so it accepts a C string again.
1 parent 45436a4 commit e91600d

File tree

6 files changed

+55
-46
lines changed

6 files changed

+55
-46
lines changed

src/interfaces/ecpg/ChangeLog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2095,5 +2095,11 @@ Mo Aug 14 10:39:59 CEST 2006
20952095
- Fixed broken newline on Windows.
20962096
- Fixed a nasty buffer underrun that only occured when using Informix
20972097
no_indicator NULL setting on timestamps and intervals.
2098+
2099+
Fr 18. Aug 17:32:54 CEST 2006
2100+
2101+
- Changed lexer to no longer use the default rule.
2102+
- Synced parser and keyword list.
2103+
- Fixed parsing of CONNECT statement so it accepts a C string again.
20982104
- Set ecpg library version to 5.2.
20992105
- Set ecpg version to 4.2.1.

src/interfaces/ecpg/preproc/keywords.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/keywords.c,v 1.74 2006/08/02 13:43:23 meskes Exp $
11+
* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/keywords.c,v 1.75 2006/08/18 15:59:35 meskes Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -277,6 +277,7 @@ static ScanKeyword ScanKeywords[] = {
277277
{"reset", RESET},
278278
{"restart", RESTART},
279279
{"restrict", RESTRICT},
280+
{"returning", RETURNING},
280281
{"returns", RETURNS},
281282
{"revoke", REVOKE},
282283
{"right", RIGHT},

src/interfaces/ecpg/preproc/pgc.l

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*
1313
*
1414
* IDENTIFICATION
15-
* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/pgc.l,v 1.148 2006/08/02 13:43:23 meskes Exp $
15+
* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/pgc.l,v 1.149 2006/08/18 15:59:35 meskes Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
@@ -79,7 +79,7 @@ static struct _if_value
7979

8080
%option yylineno
8181

82-
%s C SQL incl def def_ident undef
82+
%x C SQL incl def def_ident undef
8383

8484
/*
8585
* OK, here is a short description of lex/flex rules behavior.
@@ -109,7 +109,6 @@ static struct _if_value
109109
%x xe
110110
%x xq
111111
%x xdolq
112-
%x xpre
113112
%x xcond
114113
%x xskip
115114

@@ -327,7 +326,7 @@ cppline {space}*#(.*\\{space})*.*{newline}
327326

328327
<SQL>{whitespace} { /* ignore */ }
329328

330-
{xcstart} {
329+
<C,SQL>{xcstart} {
331330
token_start = yytext;
332331
state_before = YYSTATE;
333332
xcdepth = 0;
@@ -545,7 +544,7 @@ cppline {space}*#(.*\\{space})*.*{newline}
545544
* This is not an EOL marker.
546545
*/
547546
if (yytext[0] == ';' && struct_level == 0)
548-
BEGIN C;
547+
BEGIN(C);
549548
return yytext[0];
550549
}
551550
<SQL>{operator} {
@@ -720,12 +719,12 @@ cppline {space}*#(.*\\{space})*.*{newline}
720719
}
721720
}
722721
<SQL>{other} { return yytext[0]; }
723-
<C>{exec_sql} { BEGIN SQL; return SQL_START; }
722+
<C>{exec_sql} { BEGIN(SQL); return SQL_START; }
724723
<C>{informix_special} {
725724
/* are we simulating Informix? */
726725
if (INFORMIX_MODE)
727726
{
728-
BEGIN SQL;
727+
BEGIN(SQL);
729728
return SQL_START;
730729
}
731730
else
@@ -896,7 +895,7 @@ cppline {space}*#(.*\\{space})*.*{newline}
896895

897896
BEGIN(C);
898897
}
899-
<undef>{other} {
898+
<undef>{other}|\n {
900899
mmerror(PARSE_ERROR, ET_FATAL, "Missing identifier in 'EXEC SQL UNDEF' command");
901900
yyterminate();
902901
}
@@ -1077,24 +1076,24 @@ cppline {space}*#(.*\\{space})*.*{newline}
10771076
}
10781077

10791078
if (stacked_if_value[preproc_tos].condition)
1080-
BEGIN C;
1079+
BEGIN(C);
10811080
else
10821081
BEGIN(xskip);
10831082
}
10841083

1085-
<xcond>{other} {
1086-
mmerror(PARSE_ERROR, ET_FATAL, "Missing identifier in 'EXEC SQL IFDEF' command");
1087-
yyterminate();
1088-
}
1084+
<xcond>{other}|\n {
1085+
mmerror(PARSE_ERROR, ET_FATAL, "Missing identifier in 'EXEC SQL IFDEF' command");
1086+
yyterminate();
1087+
}
10891088
<def_ident>{identifier} {
10901089
old = mm_strdup(yytext);
10911090
BEGIN(def);
10921091
startlit();
10931092
}
1094-
<def_ident>{other} {
1095-
mmerror(PARSE_ERROR, ET_FATAL, "Missing identifier in 'EXEC SQL DEFINE' command");
1096-
yyterminate();
1097-
}
1093+
<def_ident>{other}|\n {
1094+
mmerror(PARSE_ERROR, ET_FATAL, "Missing identifier in 'EXEC SQL DEFINE' command");
1095+
yyterminate();
1096+
}
10981097
<def>{space}*";" {
10991098
struct _defines *ptr, *this;
11001099

@@ -1124,10 +1123,10 @@ cppline {space}*#(.*\\{space})*.*{newline}
11241123
<incl>\<[^\>]+\>{space}*";"? { parse_include(); }
11251124
<incl>{dquote}{xdinside}{dquote}{space}*";"? { parse_include(); }
11261125
<incl>[^;\<\>\"]+";" { parse_include(); }
1127-
<incl>{other} {
1128-
mmerror(PARSE_ERROR, ET_FATAL, "Incorrect 'EXEC SQL INCLUDE' command");
1129-
yyterminate();
1130-
}
1126+
<incl>{other}|\n {
1127+
mmerror(PARSE_ERROR, ET_FATAL, "Incorrect 'EXEC SQL INCLUDE' command");
1128+
yyterminate();
1129+
}
11311130

11321131
<<EOF>> {
11331132
if (yy_buffer == NULL)
@@ -1174,6 +1173,7 @@ cppline {space}*#(.*\\{space})*.*{newline}
11741173

11751174
}
11761175
}
1176+
<INITIAL>{other}|\n { mmerror(PARSE_ERROR, ET_FATAL, "Internal error: unreachable state, please inform pgsql-bugs@postgresql.org"); }
11771177
%%
11781178
void
11791179
lex_init(void)
@@ -1194,7 +1194,7 @@ lex_init(void)
11941194
}
11951195
startlit();
11961196

1197-
BEGIN C;
1197+
BEGIN(C);
11981198
}
11991199

12001200
static void
@@ -1318,7 +1318,7 @@ parse_include(void)
13181318
yylineno = 1;
13191319
output_line_number();
13201320

1321-
BEGIN C;
1321+
BEGIN(C);
13221322
}
13231323

13241324
static void

src/interfaces/ecpg/preproc/preproc.y

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/preproc.y,v 1.328 2006/08/08 11:51:24 meskes Exp $ */
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/preproc.y,v 1.329 2006/08/18 15:59:35 meskes Exp $ */
22

33
/* Copyright comment */
44
%{
@@ -407,7 +407,7 @@ add_additional_variables(char *name, bool insert)
407407
QUOTE
408408

409409
READ REAL REASSIGN RECHECK REFERENCES REINDEX RELATIVE_P RELEASE RENAME
410-
REPEATABLE REPLACE RESET RESTART RESTRICT RETURNS REVOKE RIGHT
410+
REPEATABLE REPLACE RESET RESTART RESTRICT RETURNING RETURNS REVOKE RIGHT
411411
ROLE ROLLBACK ROW ROWS RULE
412412

413413
SAVEPOINT SCHEMA SCROLL SECOND_P SECURITY SELECT SEQUENCE
@@ -497,7 +497,7 @@ add_additional_variables(char *name, bool insert)
497497
%type <str> columnList DeleteStmt UpdateStmt DeclareCursorStmt
498498
%type <str> NotifyStmt columnElem UnlistenStmt TableElement
499499
%type <str> copy_delimiter ListenStmt CopyStmt copy_file_name opt_binary
500-
%type <str> FetchStmt from_in CreateOpClassStmt
500+
%type <str> FetchStmt from_in CreateOpClassStmt returning_clause
501501
%type <str> ClosePortalStmt DropStmt VacuumStmt AnalyzeStmt opt_verbose
502502
%type <str> opt_full func_arg OptWith opt_freeze alter_table_cmd
503503
%type <str> analyze_keyword opt_name_list ExplainStmt index_params
@@ -3090,8 +3090,8 @@ DeallocateStmt: DEALLOCATE name { $$ = cat2_str(make_str("deallocate"), $2); }
30903090
*
30913091
*****************************************************************************/
30923092

3093-
InsertStmt: INSERT INTO qualified_name insert_rest
3094-
{ $$ = cat_str(3, make_str("insert into"), $3, $4); }
3093+
InsertStmt: INSERT INTO qualified_name insert_rest returning_clause
3094+
{ $$ = cat_str(4, make_str("insert into"), $3, $4, $5); }
30953095
;
30963096

30973097
insert_rest:
@@ -3113,6 +3113,9 @@ insert_column_item: ColId opt_indirection
31133113
{ $$ = cat2_str($1, $2); }
31143114
;
31153115

3116+
returning_clause: RETURNING target_list { $$ = cat2_str(make_str("returning"), $2); }
3117+
| /* EMPTY */ { $$ = EMPTY; }
3118+
;
31163119

31173120
/*****************************************************************************
31183121
*
@@ -3121,8 +3124,8 @@ insert_column_item: ColId opt_indirection
31213124
*
31223125
*****************************************************************************/
31233126

3124-
DeleteStmt: DELETE_P FROM relation_expr_opt_alias using_clause where_clause
3125-
{ $$ = cat_str(4, make_str("delete from"), $3, $4, $5); }
3127+
DeleteStmt: DELETE_P FROM relation_expr_opt_alias using_clause where_clause returning_clause
3128+
{ $$ = cat_str(5, make_str("delete from"), $3, $4, $5, $6); }
31263129
;
31273130

31283131
using_clause: USING from_list { cat2_str(make_str("using"), $2); }
@@ -3164,7 +3167,8 @@ UpdateStmt: UPDATE relation_expr_opt_alias
31643167
SET update_target_list
31653168
from_clause
31663169
where_clause
3167-
{$$ = cat_str(6, make_str("update"), $2, make_str("set"), $4, $5, $6); }
3170+
returning_clause
3171+
{$$ = cat_str(7, make_str("update"), $2, make_str("set"), $4, $5, $6, $7); }
31683172
;
31693173

31703174

@@ -4615,8 +4619,12 @@ connection_target: database_name opt_server opt_port
46154619
/* old style: dbname[@server][:port] */
46164620
if (strlen($2) > 0 && *($2) != '@')
46174621
mmerror(PARSE_ERROR, ET_ERROR, "Expected '@', found '%s'", $2);
4618-
4619-
$$ = make3_str(make_str("\""), make3_str($1, $2, $3), make_str("\""));
4622+
4623+
/* C strings need to be handled differently */
4624+
if ($1[0] == '\"')
4625+
$$ = $1;
4626+
else
4627+
$$ = make3_str(make_str("\""), make3_str($1, $2, $3), make_str("\""));
46204628
}
46214629
| db_prefix ':' server opt_port '/' database_name opt_options
46224630
{
@@ -4634,13 +4642,6 @@ connection_target: database_name opt_server opt_port
46344642

46354643
$$ = make3_str(make3_str(make_str("\""), $1, make_str(":")), $3, make3_str(make3_str($4, make_str("/"), $6), $7, make_str("\"")));
46364644
}
4637-
| Sconst
4638-
{
4639-
if ($1[0] == '\"')
4640-
$$ = $1;
4641-
else
4642-
$$ = make3_str(make_str("\""), $1, make_str("\""));
4643-
}
46444645
| char_variable
46454646
{
46464647
$$ = $1;
@@ -6509,9 +6510,10 @@ reserved_keyword:
65096510
| OR { $$ = make_str("or"); }
65106511
| ORDER { $$ = make_str("order"); }
65116512
| PRIMARY { $$ = make_str("primary"); }
6512-
| REFERENCES { $$ = make_str("references"); }
6513+
| REFERENCES { $$ = make_str("references"); }
6514+
| RETURNING { $$ = make_str("returning"); }
65136515
| SELECT { $$ = make_str("select"); }
6514-
| SESSION_USER { $$ = make_str("session_user"); }
6516+
| SESSION_USER { $$ = make_str("session_user"); }
65156517
| SOME { $$ = make_str("some"); }
65166518
| SYMMETRIC { $$ = make_str("symmetric"); }
65176519
| TABLE { $$ = make_str("table"); }
@@ -6604,7 +6606,7 @@ cvariable: CVARIABLE
66046606
}
66056607
;
66066608
ident: IDENT { $$ = $1; }
6607-
| CSTRING { $$ = make3_str(make_str("\""), $1, make_str("\"")); }
6609+
| CSTRING { $$ = make3_str(make_str("\""), $1, make_str("\"")); }
66086610
;
66096611

66106612
quoted_ident_stringvar: name

src/interfaces/ecpg/test/connect/test3.pgc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ exec sql end declare section;
3434
/* will close "second" */
3535
exec sql disconnect DEFAULT;
3636

37-
exec sql connect to REGRESSDB1 as second;
37+
exec sql connect to "connectdb" as second;
3838
exec sql disconnect ALL;
3939

4040
exec sql disconnect CURRENT;

src/interfaces/ecpg/test/expected/connect-test3.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ main(void)
7878
#line 35 "test3.pgc"
7979

8080

81-
{ ECPGconnect(__LINE__, 0, "regress1" , NULL,NULL , "second", 0); }
81+
{ ECPGconnect(__LINE__, 0, "connectdb" , NULL,NULL , "second", 0); }
8282
#line 37 "test3.pgc"
8383

8484
{ ECPGdisconnect(__LINE__, "ALL");}

0 commit comments

Comments
 (0)