Skip to content
Snippets Groups Projects
Commit 7c6baade authored by Neil Conway's avatar Neil Conway
Browse files

Refactor CheckDropPermissions() to move some initialization code for

printing the proper error message out of the common path.
parent d9050578
Branches
Tags
No related merge requests found
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/tcop/utility.c,v 1.214 2004/05/05 04:48:46 tgl Exp $ * $PostgreSQL: pgsql/src/backend/tcop/utility.c,v 1.215 2004/05/07 19:12:26 neilc Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -99,8 +99,12 @@ static const struct msgstrings msgstringarray[] = { ...@@ -99,8 +99,12 @@ static const struct msgstrings msgstringarray[] = {
}; };
/*
* Emit the right error message for a "DROP" command issued on a
* relation of the wrong type
*/
static void static void
DropErrorMsg(char *relname, char wrongkind, char rightkind) DropErrorMsgWrongType(char *relname, char wrongkind, char rightkind)
{ {
const struct msgstrings *rentry; const struct msgstrings *rentry;
const struct msgstrings *wentry; const struct msgstrings *wentry;
...@@ -121,24 +125,37 @@ DropErrorMsg(char *relname, char wrongkind, char rightkind) ...@@ -121,24 +125,37 @@ DropErrorMsg(char *relname, char wrongkind, char rightkind)
(wentry->kind != '\0') ? errhint(wentry->drophint_msg) : 0)); (wentry->kind != '\0') ? errhint(wentry->drophint_msg) : 0));
} }
/*
* Emit the right error message for a "DROP" command issued on a
* non-existent relation
*/
static void static void
CheckDropPermissions(RangeVar *rel, char rightkind) DropErrorMsgNonExistent(RangeVar *rel, char rightkind)
{ {
const struct msgstrings *rentry; const struct msgstrings *rentry;
Oid relOid;
HeapTuple tuple;
Form_pg_class classform;
for (rentry = msgstringarray; rentry->kind != '\0'; rentry++) for (rentry = msgstringarray; rentry->kind != '\0'; rentry++)
{
if (rentry->kind == rightkind) if (rentry->kind == rightkind)
break; ereport(ERROR,
Assert(rentry->kind != '\0'); (errcode(rentry->nonexistent_code),
errmsg(rentry->nonexistent_msg, rel->relname)));
}
Assert(false); /* Should be impossible */
}
static void
CheckDropPermissions(RangeVar *rel, char rightkind)
{
Oid relOid;
HeapTuple tuple;
Form_pg_class classform;
relOid = RangeVarGetRelid(rel, true); relOid = RangeVarGetRelid(rel, true);
if (!OidIsValid(relOid)) if (!OidIsValid(relOid))
ereport(ERROR, DropErrorMsgNonExistent(rel, rightkind);
(errcode(rentry->nonexistent_code),
errmsg(rentry->nonexistent_msg, rel->relname)));
tuple = SearchSysCache(RELOID, tuple = SearchSysCache(RELOID,
ObjectIdGetDatum(relOid), ObjectIdGetDatum(relOid),
0, 0, 0); 0, 0, 0);
...@@ -148,7 +165,8 @@ CheckDropPermissions(RangeVar *rel, char rightkind) ...@@ -148,7 +165,8 @@ CheckDropPermissions(RangeVar *rel, char rightkind)
classform = (Form_pg_class) GETSTRUCT(tuple); classform = (Form_pg_class) GETSTRUCT(tuple);
if (classform->relkind != rightkind) if (classform->relkind != rightkind)
DropErrorMsg(rel->relname, classform->relkind, rightkind); DropErrorMsgWrongType(rel->relname, classform->relkind,
rightkind);
/* Allow DROP to either table owner or schema owner */ /* Allow DROP to either table owner or schema owner */
if (!pg_class_ownercheck(relOid, GetUserId()) && if (!pg_class_ownercheck(relOid, GetUserId()) &&
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment