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

Commit0347dcc

Browse files
committed
Okay, I've updated the ecpg parser yet again. Unfortunately it has one
remaining shift/reduce conflict. But the very same conflict is in gram.y, soI don't dig into it very much now.Anyway, I just saw that there were minor changes made to ecpg by others. NowI like that but I would prefer if I was told about that. Otherwise myversion numbering and Changelog maintaining might break. Or simply changethese too. :-)Also I had to add #include <errno.h> to backend/libpq/pqcomprim.c to beable to compile postgresql.Patch is attached. Since my resubscription process is still not finishedyet, I still send them here.Michael
1 parent909c519 commit0347dcc

File tree

7 files changed

+109
-77
lines changed

7 files changed

+109
-77
lines changed

‎src/interfaces/ecpg/ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,4 +371,9 @@ Tue Jan 7 15:19:34 CET 1999
371371

372372
- Synced preproc.y with gram.y for for-update clause and changes in
373373
handling of numerics
374+
375+
Mon Jan 18 11:22:44 CET 1999
376+
377+
- Added INTERSECT, EXCEPT and UNION for Select statements
378+
- Put keywords.c in sync again after forgettimg it the last time.
374379
- Set version to 2.4.6

‎src/interfaces/ecpg/include/ecpglib.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include<c.h>
1+
#include<postgres.h>
22

33
#ifdef__cplusplus
44
extern"C"

‎src/interfaces/ecpg/preproc/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ include $(SRCDIR)/Makefile.global
33

44
MAJOR_VERSION=2
55
MINOR_VERSION=4
6-
PATCHLEVEL=5
6+
PATCHLEVEL=6
77

88
CFLAGS+=-I../include -DMAJOR_VERSION=$(MAJOR_VERSION)\
99
-DMINOR_VERSION=$(MINOR_VERSION) -DPATCHLEVEL=$(PATCHLEVEL)\

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/keywords.c,v 1.7 1998/12/22 18:50:55 scrappy Exp $
10+
* $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/keywords.c,v 1.8 1999/01/18 17:17:01 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -94,6 +94,8 @@ static ScanKeyword ScanKeywords[] = {
9494
{"else",ELSE},
9595
{"encoding",ENCODING},
9696
{"end",END_TRANS},
97+
/***S*I***/
98+
{"except",EXCEPT},
9799
{"execute",EXECUTE},
98100
{"exists",EXISTS},
99101
{"explain",EXPLAIN},
@@ -121,16 +123,20 @@ static ScanKeyword ScanKeywords[] = {
121123
{"insensitive",INSENSITIVE},
122124
{"insert",INSERT},
123125
{"instead",INSTEAD},
126+
/***S*I***/
127+
{"intersect",INTERSECT},
124128
{"interval",INTERVAL},
125129
{"into",INTO},
126130
{"is",IS},
127131
{"isnull",ISNULL},
132+
{"isolation",ISOLATION},
128133
{"join",JOIN},
129134
{"key",KEY},
130135
{"lancompiler",LANCOMPILER},
131136
{"language",LANGUAGE},
132137
{"leading",LEADING},
133138
{"left",LEFT},
139+
{"level",LEVEL},
134140
{"like",LIKE},
135141
{"listen",LISTEN},
136142
{"load",LOAD},

‎src/interfaces/ecpg/preproc/preproc.y

Lines changed: 88 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
*/
2121
staticintstruct_level =0;
2222
staticcharerrortext[128];
23-
staticint QueryIsRule =0;
23+
staticint QueryIsRule =0, ForUpdateNotAllowed =0;
2424
staticenum ECPGttype actual_type[STRUCT_DEPTH];
2525
staticchar *actual_storage[STRUCT_DEPTH];
2626

@@ -536,11 +536,11 @@ output_statement(char * stmt, int mode)
536536
CONSTRAINT,CREATE,CROSS,CURRENT,CURRENT_DATE,CURRENT_TIME,
537537
CURRENT_TIMESTAMP,CURRENT_USER,CURSOR,
538538
DAY_P,DECIMAL,DECLARE,DEFAULT,DELETE,DESC,DISTINCT,DOUBLE,DROP,
539-
ELSE,END_TRANS,EXECUTE,EXISTS,EXTRACT,
539+
ELSE,END_TRANS,EXCEPT,EXECUTE,EXISTS,EXTRACT,
540540
FALSE_P,FETCH,FLOAT,FOR,FOREIGN,FROM,FULL,
541541
GRANT,GROUP,HAVING,HOUR_P,
542-
IN,INNER_P,INSENSITIVE,INSERT,INTERVAL,INTO,IS,ISOLATION,
543-
JOIN,KEY,LANGUAGE,LEADING,LEFT,LEVEL,LIKE,LOCAL,
542+
IN,INNER_P,INSENSITIVE,INSERT,INTERSECT,INTERVAL,INTO,IS,
543+
ISOLATION,JOIN,KEY,LANGUAGE,LEADING,LEFT,LEVEL,LIKE,LOCAL,
544544
MATCH,MINUTE_P,MONTH_P,NAMES,
545545
NATIONAL,NATURAL,NCHAR,NEXT,NO,NOT,NULLIF,NULL_P,NUMERIC,
546546
OF,ON,ONLY,OPTION,OR,ORDER,OUTER_P,
@@ -608,7 +608,7 @@ output_statement(char * stmt, int mode)
608608
%left'.'
609609
%left'['']'
610610
%nonassocTYPECAST
611-
%leftUNION
611+
%leftUNIONINTERSECTEXCEPT
612612

613613
%type<str>IconstFconstSconstTransactionStmtCreateStmtUserId
614614
%type<str>CreateAsElementOptCreateAsCreateAsListCreateAsStmt
@@ -630,15 +630,15 @@ output_statement(char * stmt, int mode)
630630
%type<str>opt_decimalCharactercharacteropt_varyingopt_charset
631631
%type<str>opt_collateDatetimedatetimeopt_timezoneopt_interval
632632
%type<str>numerica_expr_or_nullrow_exprrow_descriptorrow_list
633-
%type<str>SelectStmtunion_clauseselect_listSubSelectresult
633+
%type<str>SelectStmtSubSelectresult
634634
%type<str>opt_tableopt_unionopt_uniquesort_clausesortby_list
635635
%type<str>sortbyOptUseOpopt_inh_starrelation_name_listname_list
636636
%type<str>group_clausehaving_clausefrom_clausec_list
637637
%type<str>from_listfrom_valjoin_exprjoin_outerjoin_specjoin_list
638638
%type<str>join_usingwhere_clauserelation_exprrow_opsub_type
639639
%type<str>opt_column_listinsert_restInsertStmtOptimizableStmt
640640
%type<str>columnListDeleteStmtLockStmtUpdateStmtCursorStmt
641-
%type<str>NotifyStmtcolumnElemcopy_dirnSubUnionc_exprUnlistenStmt
641+
%type<str>NotifyStmtcolumnElemcopy_dirnc_exprUnlistenStmt
642642
%type<str>copy_delimiterListenStmtCopyStmtcopy_file_nameopt_binary
643643
%type<str>opt_with_copyFetchStmtopt_directionfetch_how_manyopt_portal_name
644644
%type<str>ClosePortalStmtDestroyStmtVacuumStmtopt_verbose
@@ -666,6 +666,7 @@ output_statement(char * stmt, int mode)
666666
%type<str>GrantStmtprivilegesoperation_commalistoperation
667667
%type<str>cursor_clauseopt_cursoropt_readonlyopt_ofopt_lmode
668668
%type<str>case_exprwhen_clause_listcase_defaultcase_argwhen_clause
669+
%type<str>select_w_o_sort
669670

670671
%type<str>ECPGWheneverECPGConnectconnection_targetECPGOpenopen_opts
671672
%type<str>indicatorECPGExecuteecpg_exprdotext
@@ -2121,7 +2122,10 @@ RuleStmt: CREATE RULE name AS
21212122
OptStmtList:NOTHING{$$ = make1_str("nothing"); }
21222123
|OptimizableStmt{$$ =$1; }
21232124
|'['OptStmtBlock']'{$$ = cat3_str(make1_str("["),$2, make1_str("]")); }
2124-
|'('OptStmtBlock')'{$$ = cat3_str(make1_str("("),$2, make1_str(")")); }
2125+
/***S*I*D***/
2126+
/* We comment this out because it produces a shift / reduce conflict
2127+
* with the select_w_o_sort rule*/
2128+
/*| '(' OptStmtBlock ')'{ $$ = cat3_str(make1_str("("), $2, make1_str(")")); }*/
21252129
;
21262130

21272131
OptStmtBlock:OptStmtMulti
@@ -2132,8 +2136,13 @@ OptStmtBlock: OptStmtMulti
21322136

21332137
OptStmtMulti:OptStmtMultiOptimizableStmt';'
21342138
{$$ = cat3_str($1,$2, make1_str(";")); }
2135-
|OptStmtMultiOptimizableStmt
2136-
{$$ = cat2_str($1,$2); }
2139+
/***S*I***/
2140+
/* We comment the next rule because it seems to be redundant
2141+
* and produces 16 shift/reduce conflicts with the new SelectStmt rule
2142+
* needed for EXCEPT and INTERSECT. So far I did not notice any
2143+
* violations by removing the rule!*/
2144+
/*| OptStmtMulti OptimizableStmt
2145+
{ $$ = cat2_str($1, $2); }*/
21372146
|OptimizableStmt';'
21382147
{$$ = cat2_str($1, make1_str(";")); }
21392148
;
@@ -2389,9 +2398,15 @@ OptimizableStmt: SelectStmt
23892398
*
23902399
*****************************************************************************/
23912400

2392-
InsertStmt:INSERTINTOrelation_nameopt_column_listinsert_rest
2401+
/***S*I***/
2402+
/* This rule used 'opt_column_list' between 'relation_name' and 'insert_rest'
2403+
* originally. When the second rule of 'insert_rest' was changed to use
2404+
* the new 'SelectStmt' rule (for INTERSECT and EXCEPT) it produced a shift/red uce
2405+
* conflict. So I just changed the rules 'InsertStmt' and 'insert_rest' to accept
2406+
* the same statements without any shift/reduce conflicts*/
2407+
InsertStmt:INSERTINTOrelation_nameinsert_rest
23932408
{
2394-
$$ =cat4_str(make1_str("insert into"),$3,$4,$5);
2409+
$$ =cat3_str(make1_str("insert into"),$3,$4);
23952410
}
23962411
;
23972412

@@ -2403,12 +2418,17 @@ insert_rest: VALUES '(' res_target_list2 ')'
24032418
{
24042419
$$ = make1_str("default values");
24052420
}
2406-
|SELECTopt_uniqueres_target_list2
2407-
from_clausewhere_clause
2408-
group_clausehaving_clause
2409-
union_clause
2421+
|SelectStmt
24102422
{
2411-
$$ = cat4_str(cat5_str(make1_str("select"),$2,$3,$4,$5),$6,$7,$8);
2423+
$$ =$1
2424+
}
2425+
|'('columnList')'VALUES'('res_target_list2')'
2426+
{
2427+
$$ = make5_str(make1_str("("),$2, make1_str(") values ("),$6, make1_str(")"));
2428+
}
2429+
|'('columnList')'SelectStmt
2430+
{
2431+
$$ = make4_str(make1_str("("),$2, make1_str(")"),$4);
24122432
}
24132433
;
24142434

@@ -2546,12 +2566,7 @@ UpdateStmt: UPDATE relation_name
25462566
*CURSOR STATEMENTS
25472567
*
25482568
*****************************************************************************/
2549-
CursorStmt:DECLAREnameopt_cursorCURSORFOR
2550-
SELECTopt_uniqueres_target_list2
2551-
from_clausewhere_clause
2552-
group_clausehaving_clause
2553-
union_clausesort_clause
2554-
cursor_clause
2569+
CursorStmt:DECLAREnameopt_cursorCURSORFORSelectStmtcursor_clause
25552570
{
25562571
structcursor *ptr, *this;
25572572

@@ -2570,7 +2585,7 @@ CursorStmt: DECLARE name opt_cursor CURSOR FOR
25702585
/* initial definition*/
25712586
this->next = cur;
25722587
this->name =$2;
2573-
this->command =cat4_str(cat5_str(cat5_str(make1_str("declare"), mm_strdup($2),$3, make1_str("cursor for select"),$7),$8,$9,$10,$11),$12,$13,$14);
2588+
this->command = cat2_str(cat5_str(make1_str("declare"), mm_strdup($2),$3, make1_str("cursor for"),$6),$7);
25742589
this->argsinsert = argsinsert;
25752590
this->argsresult = argsresult;
25762591
argsinsert = argsresult =NULL;
@@ -2609,54 +2624,60 @@ opt_of: OF columnList { $$ = make2_str(make1_str("of"), $2); }
26092624
*
26102625
*****************************************************************************/
26112626

2612-
SelectStmt:SELECTopt_uniqueres_target_list2
2613-
resultfrom_clausewhere_clause
2614-
group_clausehaving_clause
2615-
union_clausesort_clausefor_update_clause
2627+
/***S*I***/
2628+
/* The new 'SelectStmt' rule adapted for the optional use of INTERSECT EXCEPT a nd UNION
2629+
* accepts the use of '(' and ')' to select an order of set operations.
2630+
*/
2631+
SelectStmt:select_w_o_sortsort_clausefor_update_clause
26162632
{
2617-
$$ = cat3_str(cat5_str(cat5_str(make1_str("select"),$2,$3,$4,$5),$6,$7,$8,$9),$10,$11);
2618-
if (strlen($11) >0)
2619-
{
2620-
if (strlen($9) >0)
2621-
yyerror("SELECT FOR UPDATE is not allowed with UNION clause");
2622-
if (strlen($7) >0)
2623-
yyerror("SELECT FOR UPDATE is not allowed with GROUP BY clause");
2624-
if (strlen($6) >0)
2625-
yyerror("SELECT FOR UPDATE is not allowed with HAVING clause");
2626-
}
2627-
}
2628-
;
2629-
2630-
SubSelect:SELECTopt_uniqueres_target_list2
2631-
from_clausewhere_clause
2632-
group_clausehaving_clause
2633-
union_clause
2634-
{
2635-
$$ =cat4_str(cat5_str(make1_str("select"),$2,$3,$4,$5),$6,$7,$8);
2636-
}
2637-
;
2633+
if (strlen($3) >0 && ForUpdateNotAllowed !=0)
2634+
yyerror("SELECT FOR UPDATE is not allowed in this context");
26382635

2639-
union_clause:UNIONopt_unionselect_list
2640-
{
2641-
$$ = cat3_str(make1_str("union"),$2,$3);
2636+
ForUpdateNotAllowed =0;
2637+
$$ = cat3_str($1,$2,$3);
26422638
}
2643-
|/*EMPTY*/
2644-
{$$ = make1_str(""); }
2645-
;
26462639

2647-
select_list:select_listUNIONopt_unionSubUnion
2648-
{
2649-
$$ = cat4_str($1, make1_str("union"),$3,$4);
2650-
}
2651-
|SubUnion
2652-
{$$ =$1; }
2640+
/***S*I***/
2641+
/* This rule parses Select statements including UNION INTERSECT and EXCEPT.
2642+
* '(' and ')' can be used to specify the order of the operations
2643+
* (UNION EXCEPT INTERSECT). Without the use of '(' and ')' we want the
2644+
* operations to be left associative.
2645+
*
2646+
* The sort_clause is not handled here!
2647+
*/
2648+
select_w_o_sort:'('select_w_o_sort')'
2649+
{
2650+
$$ = make3_str(make1_str("("),$2, make1_str(")"));
2651+
}
2652+
|SubSelect
2653+
{
2654+
$$ =$1;
2655+
}
2656+
|select_w_o_sortEXCEPTselect_w_o_sort
2657+
{
2658+
$$ = cat3_str($1, make1_str("except"),$3);
2659+
ForUpdateNotAllowed =1;
2660+
}
2661+
|select_w_o_sortUNIONopt_unionselect_w_o_sort
2662+
{
2663+
$$ = cat3_str($1, make1_str("union"),$3);
2664+
ForUpdateNotAllowed =1;
2665+
}
2666+
|select_w_o_sortINTERSECTopt_unionselect_w_o_sort
2667+
{
2668+
$$ = cat3_str($1, make1_str("intersect"),$3);
2669+
ForUpdateNotAllowed =1;
2670+
}
26532671
;
26542672

2655-
SubUnion:SELECTopt_uniqueres_target_list2
2656-
from_clausewhere_clause
2657-
group_clausehaving_clause
2673+
/***S*I***/
2674+
SubSelect:SELECTopt_uniqueres_target_list2
2675+
resultfrom_clausewhere_clause
2676+
group_clausehaving_clause
26582677
{
2659-
$$ = cat3_str(cat5_str(make1_str("select"),$2,$3,$4,$5),$6,$7);
2678+
$$ = cat4_str(cat5_str(make1_str("select"),$2,$3,$4,$5),$6,$7,$8);
2679+
if (strlen($7) >0 || strlen($8) >0)
2680+
ForUpdateNotAllowed =1;
26602681
}
26612682
;
26622683

@@ -4416,9 +4437,9 @@ connection_target: database_name opt_server opt_port
44164437
yyerror(errortext);
44174438
}
44184439

4419-
if (strncmp($1,"unix",4) ==0 && strncmp($2,"localhost",9) !=0)
4440+
if (strncmp($1,"unix",4) ==0 && strncmp($2 +3,"localhost",9) !=0)
44204441
{
4421-
sprintf(errortext,"unix domain sockets only work on 'localhost'");
4442+
sprintf(errortext,"unix domain sockets only work on 'localhost' but not on '%9.9s'", $2);
44224443
yyerror(errortext);
44234444
}
44244445

‎src/interfaces/ecpg/test/Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
all: test1 test2 perftest
22

3-
LDFLAGS=-g -I../include -I ../../libpq -L../lib -lecpg -L../../libpq -lpq -lcrypt
3+
LDFLAGS=-g -I/usr/local/pgsql/include -L/usr/local/pgsql/lib -lecpg -lpq -lcrypt
44

55
test1: test1.c
66
test1.c: test1.pgc
7-
../preproc/ecpg$?
7+
/usr/local/pgsql/bin/ecpg$?
88

99
test2: test2.c
1010
test2.c: test2.pgc
11-
../preproc/ecpg$?
11+
/usr/local/pgsql/bin/ecpg$?
1212

1313
perftest: perftest.c
1414
perftest.c:perftest.pgc
15-
../preproc/ecpg$?
15+
/usr/local/pgsql/bin/ecpg$?
1616

1717
clean:
1818
/bin/rm test1 test2 perftest*.c log

‎src/interfaces/ecpg/test/test2.pgc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ exec sql declare cur cursor for
3030
ECPGdebug(1, dbgs);
3131

3232
strcpy(msg, "connect");
33-
exec sql connect totcp:postgresql://localhost:5432/mm;
33+
exec sql connect tounix:postgresql://localhost:5432/mm;
3434

3535
strcpy(msg, "create");
3636
exec sql create table meskes(name char(8), born integer, age smallint, married char(8));
3737

3838
strcpy(msg, "insert");
39-
exec sql insert into meskes(name, born, age, married) values ('Petra', 19661202,31, '19900404');
40-
exec sql insert into meskes(name, born, age, married) values ('Michael', 19660117,32, '19900404');
39+
exec sql insert into meskes(name, born, age, married) values ('Petra', 19661202,32, '19900404');
40+
exec sql insert into meskes(name, born, age, married) values ('Michael', 19660117,33, '19900404');
4141
exec sql insert into meskes(name, born, age) values ('Carsten', 19910103, 7);
4242
exec sql insert into meskes(name, born, age) values ('Marc', 19930907, 4);
4343
exec sql insert into meskes(name, born, age) values ('Chris', 19970923, 0);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp