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

Commit3284758

Browse files
committed
Remove grammar restrictions on order of optional clauses in CREATE GROUP.
From Vince Vielhaber.
1 parent5c4d139 commit3284758

File tree

7 files changed

+126
-81
lines changed

7 files changed

+126
-81
lines changed

‎doc/src/sgml/ref/create_group.sgml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_group.sgml,v 1.2 2000/03/27 17:14:42 thomas Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_group.sgml,v 1.3 2001/07/12 18:02:58 tgl Exp $
33
Postgres documentation
44
-->
55

@@ -23,10 +23,12 @@ Postgres documentation
2323
<date>2000-01-14</date>
2424
</refsynopsisdivinfo>
2525
<synopsis>
26-
CREATE GROUP <replaceable class="PARAMETER">name</replaceable>
27-
[ WITH
28-
[ SYSID <replaceable class="PARAMETER">gid</replaceable> ]
29-
[ USER <replaceable class="PARAMETER">username</replaceable> [, ...] ] ]
26+
CREATE GROUP <replaceable class="PARAMETER">name</replaceable> [ [ WITH ] <replaceable class="PARAMETER">option</replaceable> [ ... ] ]
27+
28+
where <replaceable class="PARAMETER">option</replaceable> can be:
29+
30+
SYSID <replaceable class="PARAMETER">gid</replaceable>
31+
| USER <replaceable class="PARAMETER">username</replaceable> [, ...]
3032
</synopsis>
3133

3234
<refsect2 id="R2-SQL-CREATEGROUP-1">

‎src/backend/commands/user.c

Lines changed: 50 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Header: /cvsroot/pgsql/src/backend/commands/user.c,v 1.78 2001/07/10 22:09:28 tgl Exp $
9+
* $Header: /cvsroot/pgsql/src/backend/commands/user.c,v 1.79 2001/07/12 18:02:59 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -787,13 +787,47 @@ CreateGroup(CreateGroupStmt *stmt)
787787
HeapTupletuple;
788788
TupleDescpg_group_dsc;
789789
boolgroup_exists= false,
790-
sysid_exists= false;
790+
sysid_exists= false,
791+
havesysid= false;
791792
intmax_id=0;
792793
Datumnew_record[Natts_pg_group];
793794
charnew_record_nulls[Natts_pg_group];
794795
List*item,
795-
*newlist=NULL;
796+
*option,
797+
*newlist=NIL;
796798
ArrayType*userarray;
799+
intsysid=0;
800+
List*userElts=NIL;
801+
DefElem*dsysid=NULL;
802+
DefElem*duserElts=NULL;
803+
804+
foreach(option,stmt->options)
805+
{
806+
DefElem*defel= (DefElem*)lfirst(option);
807+
808+
if (strcasecmp(defel->defname,"sysid")==0) {
809+
if (dsysid)
810+
elog(ERROR,"CREATE GROUP: conflicting options");
811+
dsysid=defel;
812+
}
813+
elseif (strcasecmp(defel->defname,"userElts")==0) {
814+
if (duserElts)
815+
elog(ERROR,"CREATE GROUP: conflicting options");
816+
duserElts=defel;
817+
}
818+
else
819+
elog(ERROR,"CREATE GROUP: option \"%s\" not recognized",
820+
defel->defname);
821+
}
822+
823+
if (dsysid)
824+
{
825+
sysid=intVal(dsysid->arg);
826+
havesysid= true;
827+
}
828+
829+
if (duserElts)
830+
userElts= (List*)duserElts->arg;
797831

798832
/*
799833
* Make sure the user can do this.
@@ -819,8 +853,8 @@ CreateGroup(CreateGroupStmt *stmt)
819853
datum=heap_getattr(tuple,Anum_pg_group_grosysid,
820854
pg_group_dsc,&null);
821855
Assert(!null);
822-
if (stmt->sysid >=0)/* customized id wanted */
823-
sysid_exists= (DatumGetInt32(datum)==stmt->sysid);
856+
if (havesysid)/* customized id wanted */
857+
sysid_exists= (DatumGetInt32(datum)==sysid);
824858
else
825859
{
826860
/* pick 1 + max */
@@ -835,19 +869,19 @@ CreateGroup(CreateGroupStmt *stmt)
835869
stmt->name);
836870
if (sysid_exists)
837871
elog(ERROR,"CREATE GROUP: group sysid %d is already assigned",
838-
stmt->sysid);
872+
sysid);
839873

840874
/*
841875
* Translate the given user names to ids
842876
*/
843-
foreach(item,stmt->initUsers)
877+
foreach(item,userElts)
844878
{
845879
constchar*groupuser=strVal(lfirst(item));
846880
Value*v;
847881

848882
v=makeInteger(get_usesysid(groupuser));
849883
if (!member(v,newlist))
850-
newlist=lcons(v,newlist);
884+
newlist=lappend(newlist,v);
851885
}
852886

853887
/* build an array to insert */
@@ -872,14 +906,12 @@ CreateGroup(CreateGroupStmt *stmt)
872906
/*
873907
* Form a tuple to insert
874908
*/
875-
if (stmt->sysid >=0)
876-
max_id=stmt->sysid;
877-
else
878-
max_id++;
909+
if (!havesysid)
910+
sysid=max_id+1;
879911

880912
new_record[Anum_pg_group_groname-1]=
881913
DirectFunctionCall1(namein,CStringGetDatum(stmt->name));
882-
new_record[Anum_pg_group_grosysid-1]=Int32GetDatum(max_id);
914+
new_record[Anum_pg_group_grosysid-1]=Int32GetDatum(sysid);
883915
new_record[Anum_pg_group_grolist-1]=PointerGetDatum(userarray);
884916

885917
new_record_nulls[Anum_pg_group_groname-1]=' ';
@@ -952,7 +984,7 @@ AlterGroup(AlterGroupStmt *stmt, const char *tag)
952984
charnew_record_nulls[Natts_pg_group];
953985
ArrayType*newarray,
954986
*oldarray;
955-
List*newlist=NULL,
987+
List*newlist=NIL,
956988
*item;
957989
HeapTupletuple;
958990
boolnull= false;
@@ -976,7 +1008,7 @@ AlterGroup(AlterGroupStmt *stmt, const char *tag)
9761008
v=makeInteger(arrval);
9771009
/* filter out duplicates */
9781010
if (!member(v,newlist))
979-
newlist=lcons(v,newlist);
1011+
newlist=lappend(newlist,v);
9801012
}
9811013

9821014
/*
@@ -1007,7 +1039,7 @@ AlterGroup(AlterGroupStmt *stmt, const char *tag)
10071039
}
10081040

10091041
if (!member(v,newlist))
1010-
newlist=lcons(v,newlist);
1042+
newlist=lappend(newlist,v);
10111043
else
10121044
/*
10131045
* we silently assume here that this error will only come
@@ -1074,7 +1106,7 @@ AlterGroup(AlterGroupStmt *stmt, const char *tag)
10741106
charnew_record_nulls[Natts_pg_group];
10751107
ArrayType*oldarray,
10761108
*newarray;
1077-
List*newlist=NULL,
1109+
List*newlist=NIL,
10781110
*item;
10791111
inti;
10801112

@@ -1094,7 +1126,7 @@ AlterGroup(AlterGroupStmt *stmt, const char *tag)
10941126
v=makeInteger(arrval);
10951127
/* filter out duplicates */
10961128
if (!member(v,newlist))
1097-
newlist=lcons(v,newlist);
1129+
newlist=lappend(newlist,v);
10981130
}
10991131

11001132
/*

‎src/backend/nodes/copyfuncs.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* Portions Copyright (c) 1994, Regents of the University of California
1616
*
1717
* IDENTIFICATION
18-
* $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.146 2001/07/10 22:09:28 tgl Exp $
18+
* $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.147 2001/07/12 18:02:59 tgl Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -2462,8 +2462,7 @@ _copyCreateGroupStmt(CreateGroupStmt *from)
24622462

24632463
if (from->name)
24642464
newnode->name=pstrdup(from->name);
2465-
newnode->sysid=from->sysid;
2466-
Node_Copy(from,newnode,initUsers);
2465+
Node_Copy(from,newnode,options);
24672466

24682467
returnnewnode;
24692468
}
@@ -2476,7 +2475,6 @@ _copyAlterGroupStmt(AlterGroupStmt *from)
24762475
if (from->name)
24772476
newnode->name=pstrdup(from->name);
24782477
newnode->action=from->action;
2479-
newnode->sysid=from->sysid;
24802478
Node_Copy(from,newnode,listUsers);
24812479

24822480
returnnewnode;

‎src/backend/nodes/equalfuncs.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* Portions Copyright (c) 1994, Regents of the University of California
2121
*
2222
* IDENTIFICATION
23-
* $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.94 2001/07/10 22:09:28 tgl Exp $
23+
* $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.95 2001/07/12 18:02:59 tgl Exp $
2424
*
2525
*-------------------------------------------------------------------------
2626
*/
@@ -1320,9 +1320,7 @@ _equalCreateGroupStmt(CreateGroupStmt *a, CreateGroupStmt *b)
13201320
{
13211321
if (!equalstr(a->name,b->name))
13221322
return false;
1323-
if (a->sysid!=b->sysid)
1324-
return false;
1325-
if (!equal(a->initUsers,b->initUsers))
1323+
if (!equal(a->options,b->options))
13261324
return false;
13271325

13281326
return true;
@@ -1335,8 +1333,6 @@ _equalAlterGroupStmt(AlterGroupStmt *a, AlterGroupStmt *b)
13351333
return false;
13361334
if (a->action!=b->action)
13371335
return false;
1338-
if (a->sysid!=b->sysid)
1339-
return false;
13401336
if (!equal(a->listUsers,b->listUsers))
13411337
return false;
13421338

‎src/backend/parser/gram.y

Lines changed: 43 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* IDENTIFICATION
14-
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.235 2001/07/10 22:09:28 tgl Exp $
14+
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.236 2001/07/12 18:02:59 tgl Exp $
1515
*
1616
* HISTORY
1717
* AUTHORDATEMAJOR EVENT
@@ -155,7 +155,10 @@ static void doNegateFloat(Value *v);
155155
%type<ival>opt_lock,lock_type
156156
%type<boolean>opt_force
157157

158-
%type<list>user_list,users_in_new_group_clause
158+
%type<list>user_list
159+
160+
%type<list>OptGroupList
161+
%type<defelt>OptGroupElem
159162

160163
%type<list>OptUserList
161164
%type<defelt>OptUserElem
@@ -489,19 +492,19 @@ stmt :AlterSchemaStmt
489492
*****************************************************************************/
490493

491494
CreateUserStmt:CREATEUSERUserIdOptUserList
492-
{
495+
{
493496
CreateUserStmt *n = makeNode(CreateUserStmt);
494497
n->user =$3;
495498
n->options =$4;
496499
$$ = (Node *)n;
497-
}
498-
|CREATEUSERUserIdWITHOptUserList
499-
{
500+
}
501+
|CREATEUSERUserIdWITHOptUserList
502+
{
500503
CreateUserStmt *n = makeNode(CreateUserStmt);
501504
n->user =$3;
502505
n->options =$5;
503506
$$ = (Node *)n;
504-
}
507+
}
505508
;
506509

507510
/*****************************************************************************
@@ -512,19 +515,19 @@ CreateUserStmt: CREATE USER UserId OptUserList
512515
*****************************************************************************/
513516

514517
AlterUserStmt:ALTERUSERUserIdOptUserList
515-
{
518+
{
516519
AlterUserStmt *n = makeNode(AlterUserStmt);
517520
n->user =$3;
518521
n->options =$4;
519522
$$ = (Node *)n;
520-
}
521-
|ALTERUSERUserIdWITHOptUserList
522-
{
523+
}
524+
|ALTERUSERUserIdWITHOptUserList
525+
{
523526
AlterUserStmt *n = makeNode(AlterUserStmt);
524527
n->user =$3;
525528
n->options =$5;
526529
$$ = (Node *)n;
527-
}
530+
}
528531
;
529532

530533
/*****************************************************************************
@@ -618,35 +621,43 @@ user_list: user_list ',' UserId
618621
*
619622
*****************************************************************************/
620623

621-
CreateGroupStmt:CREATEGROUPUserId
622-
{
624+
CreateGroupStmt:CREATEGROUPUserIdOptGroupList
625+
{
623626
CreateGroupStmt *n = makeNode(CreateGroupStmt);
624627
n->name =$3;
625-
n->sysid = -1;
626-
n->initUsers = NIL;
628+
n->options =$4;
627629
$$ = (Node *)n;
628-
}
629-
|CREATEGROUPUserIdWITHusers_in_new_group_clause
630-
{
630+
}
631+
|CREATEGROUPUserIdWITHOptGroupList
632+
{
631633
CreateGroupStmt *n = makeNode(CreateGroupStmt);
632634
n->name =$3;
633-
n->sysid = -1;
634-
n->initUsers =$5;
635+
n->options =$5;
635636
$$ = (Node *)n;
637+
}
638+
;
639+
640+
/*
641+
* Options for CREATE GROUP
642+
*/
643+
OptGroupList:OptGroupListOptGroupElem{$$ = lappend($1,$2); }
644+
|/* EMPTY*/{$$ = NIL; }
645+
;
646+
647+
OptGroupElem:USERuser_list
648+
{
649+
$$ = makeNode(DefElem);
650+
$$->defname ="userElts";
651+
$$->arg = (Node *)$2;
636652
}
637-
|CREATEGROUPUserIdWITHSYSIDIconstusers_in_new_group_clause
653+
|SYSIDIconst
638654
{
639-
CreateGroupStmt *n = makeNode(CreateGroupStmt);
640-
n->name =$3;
641-
n->sysid =$6;
642-
n->initUsers =$7;
643-
$$ = (Node *)n;
655+
$$ = makeNode(DefElem);
656+
$$->defname ="sysid";
657+
$$->arg = (Node *)makeInteger($2);
644658
}
645-
;
659+
;
646660

647-
users_in_new_group_clause:USERuser_list{$$ =$2; }
648-
|/* EMPTY*/{$$ = NIL; }
649-
;
650661

651662
/*****************************************************************************
652663
*
@@ -659,7 +670,6 @@ AlterGroupStmt: ALTER GROUP UserId ADD USER user_list
659670
{
660671
AlterGroupStmt *n = makeNode(AlterGroupStmt);
661672
n->name =$3;
662-
n->sysid = -1;
663673
n->action = +1;
664674
n->listUsers =$6;
665675
$$ = (Node *)n;
@@ -668,13 +678,13 @@ AlterGroupStmt: ALTER GROUP UserId ADD USER user_list
668678
{
669679
AlterGroupStmt *n = makeNode(AlterGroupStmt);
670680
n->name =$3;
671-
n->sysid = -1;
672681
n->action = -1;
673682
n->listUsers =$6;
674683
$$ = (Node *)n;
675684
}
676685
;
677686

687+
678688
/*****************************************************************************
679689
*
680690
* Drop a postgresql group

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp