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+ */
102106static void
103- DropErrorMsg (char * relname ,char wrongkind ,char rightkind )
107+ DropErrorMsgWrongType (char * relname ,char wrongkind ,char rightkind )
104108{
105109const struct msgstrings * rentry ;
106110const 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+ */
124132static void
125- CheckDropPermissions (RangeVar * rel ,char rightkind )
133+ DropErrorMsgNonExistent (RangeVar * rel ,char rightkind )
126134{
127135const struct msgstrings * rentry ;
128- Oid relOid ;
129- HeapTuple tuple ;
130- Form_pg_class classform ;
131136
132137for (rentry = msgstringarray ;rentry -> kind != '\0' ;rentry ++ )
138+ {
133139if (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
137155relOid = RangeVarGetRelid (rel , true);
138156if (!OidIsValid (relOid ))
139- ereport (ERROR ,
140- (errcode (rentry -> nonexistent_code ),
141- errmsg (rentry -> nonexistent_msg ,rel -> relname )));
157+ DropErrorMsgNonExistent (rel ,rightkind );
158+
142159tuple = SearchSysCache (RELOID ,
143160ObjectIdGetDatum (relOid ),
1441610 ,0 ,0 );
@@ -148,7 +165,8 @@ CheckDropPermissions(RangeVar *rel, char rightkind)
148165classform = (Form_pg_class )GETSTRUCT (tuple );
149166
150167if (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 */
154172if (!pg_class_ownercheck (relOid ,GetUserId ())&&