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

Commit7c6baad

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 parentd905057 commit7c6baad

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
staticvoid
103-
DropErrorMsg(char*relname,charwrongkind,charrightkind)
107+
DropErrorMsgWrongType(char*relname,charwrongkind,charrightkind)
104108
{
105109
conststructmsgstrings*rentry;
106110
conststructmsgstrings*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
staticvoid
125-
CheckDropPermissions(RangeVar*rel,charrightkind)
133+
DropErrorMsgNonExistent(RangeVar*rel,charrightkind)
126134
{
127135
conststructmsgstrings*rentry;
128-
OidrelOid;
129-
HeapTupletuple;
130-
Form_pg_classclassform;
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+
staticvoid
149+
CheckDropPermissions(RangeVar*rel,charrightkind)
150+
{
151+
OidrelOid;
152+
HeapTupletuple;
153+
Form_pg_classclassform;
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)

[8]ページ先頭

©2009-2025 Movatter.jp