10
10
*
11
11
*
12
12
* 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 $
14
14
*
15
15
*-------------------------------------------------------------------------
16
16
*/
@@ -99,8 +99,12 @@ static const struct msgstrings msgstringarray[] = {
99
99
};
100
100
101
101
102
+ /*
103
+ * Emit the right error message for a "DROP" command issued on a
104
+ * relation of the wrong type
105
+ */
102
106
static void
103
- DropErrorMsg (char * relname , char wrongkind , char rightkind )
107
+ DropErrorMsgWrongType (char * relname , char wrongkind , char rightkind )
104
108
{
105
109
const struct msgstrings * rentry ;
106
110
const struct msgstrings * wentry ;
@@ -121,24 +125,37 @@ DropErrorMsg(char *relname, char wrongkind, char rightkind)
121
125
(wentry -> kind != '\0' ) ? errhint (wentry -> drophint_msg ) : 0 ));
122
126
}
123
127
128
+ /*
129
+ * Emit the right error message for a "DROP" command issued on a
130
+ * non-existent relation
131
+ */
124
132
static void
125
- CheckDropPermissions (RangeVar * rel , char rightkind )
133
+ DropErrorMsgNonExistent (RangeVar * rel , char rightkind )
126
134
{
127
135
const struct msgstrings * rentry ;
128
- Oid relOid ;
129
- HeapTuple tuple ;
130
- Form_pg_class classform ;
131
136
132
137
for (rentry = msgstringarray ; rentry -> kind != '\0' ; rentry ++ )
138
+ {
133
139
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 ;
136
154
137
155
relOid = RangeVarGetRelid (rel , true);
138
156
if (!OidIsValid (relOid ))
139
- ereport (ERROR ,
140
- (errcode (rentry -> nonexistent_code ),
141
- errmsg (rentry -> nonexistent_msg , rel -> relname )));
157
+ DropErrorMsgNonExistent (rel , rightkind );
158
+
142
159
tuple = SearchSysCache (RELOID ,
143
160
ObjectIdGetDatum (relOid ),
144
161
0 , 0 , 0 );
@@ -148,7 +165,8 @@ CheckDropPermissions(RangeVar *rel, char rightkind)
148
165
classform = (Form_pg_class ) GETSTRUCT (tuple );
149
166
150
167
if (classform -> relkind != rightkind )
151
- DropErrorMsg (rel -> relname , classform -> relkind , rightkind );
168
+ DropErrorMsgWrongType (rel -> relname , classform -> relkind ,
169
+ rightkind );
152
170
153
171
/* Allow DROP to either table owner or schema owner */
154
172
if (!pg_class_ownercheck (relOid , GetUserId ()) &&
0 commit comments