Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 7c6baad

Browse files
author
Neil Conway
committed
Refactor CheckDropPermissions() to move some initialization code for
printing the proper error message out of the common path.
1 parent d905057 commit 7c6baad

File tree

1 file changed

+30
-12
lines changed

1 file changed

+30
-12
lines changed

src/backend/tcop/utility.c

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/backend/tcop/utility.c,v 1.214 2004/05/05 04:48:46 tgl Exp $
13+
* $PostgreSQL: pgsql/src/backend/tcop/utility.c,v 1.215 2004/05/07 19:12:26 neilc Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -99,8 +99,12 @@ static const struct msgstrings msgstringarray[] = {
9999
};
100100

101101

102+
/*
103+
* Emit the right error message for a "DROP" command issued on a
104+
* relation of the wrong type
105+
*/
102106
static void
103-
DropErrorMsg(char *relname, char wrongkind, char rightkind)
107+
DropErrorMsgWrongType(char *relname, char wrongkind, char rightkind)
104108
{
105109
const struct msgstrings *rentry;
106110
const struct msgstrings *wentry;
@@ -121,24 +125,37 @@ DropErrorMsg(char *relname, char wrongkind, char rightkind)
121125
(wentry->kind != '\0') ? errhint(wentry->drophint_msg) : 0));
122126
}
123127

128+
/*
129+
* Emit the right error message for a "DROP" command issued on a
130+
* non-existent relation
131+
*/
124132
static void
125-
CheckDropPermissions(RangeVar *rel, char rightkind)
133+
DropErrorMsgNonExistent(RangeVar *rel, char rightkind)
126134
{
127135
const struct msgstrings *rentry;
128-
Oid relOid;
129-
HeapTuple tuple;
130-
Form_pg_class classform;
131136

132137
for (rentry = msgstringarray; rentry->kind != '\0'; rentry++)
138+
{
133139
if (rentry->kind == rightkind)
134-
break;
135-
Assert(rentry->kind != '\0');
140+
ereport(ERROR,
141+
(errcode(rentry->nonexistent_code),
142+
errmsg(rentry->nonexistent_msg, rel->relname)));
143+
}
144+
145+
Assert(false); /* Should be impossible */
146+
}
147+
148+
static void
149+
CheckDropPermissions(RangeVar *rel, char rightkind)
150+
{
151+
Oid relOid;
152+
HeapTuple tuple;
153+
Form_pg_class classform;
136154

137155
relOid = RangeVarGetRelid(rel, true);
138156
if (!OidIsValid(relOid))
139-
ereport(ERROR,
140-
(errcode(rentry->nonexistent_code),
141-
errmsg(rentry->nonexistent_msg, rel->relname)));
157+
DropErrorMsgNonExistent(rel, rightkind);
158+
142159
tuple = SearchSysCache(RELOID,
143160
ObjectIdGetDatum(relOid),
144161
0, 0, 0);
@@ -148,7 +165,8 @@ CheckDropPermissions(RangeVar *rel, char rightkind)
148165
classform = (Form_pg_class) GETSTRUCT(tuple);
149166

150167
if (classform->relkind != rightkind)
151-
DropErrorMsg(rel->relname, classform->relkind, rightkind);
168+
DropErrorMsgWrongType(rel->relname, classform->relkind,
169+
rightkind);
152170

153171
/* Allow DROP to either table owner or schema owner */
154172
if (!pg_class_ownercheck(relOid, GetUserId()) &&

0 commit comments

Comments
 (0)