* If we are executing a CREATE EXTENSION operation, check that the given * object is a member of the extension, and throw an error if it isn't. * Otherwise, do nothing. * * This must be called whenever a CREATE IF NOT EXISTS operation (for an * object type that can be an extension member) has found that an object of * the desired name already exists. It is insecure for an extension to use
| 250 | * properties. |
| 251 | */ |
| 252 | void |
| 253 | checkMembershipInCurrentExtension(const ObjectAddress *object) |
| 254 | { |
| 255 | /* |
| 256 | * This is actually the same condition tested in |
| 257 | * recordDependencyOnCurrentExtension; but we want to issue a |
| 258 | * differently-worded error, and anyway it would be pretty confusing to |
| 259 | * call recordDependencyOnCurrentExtension in these circumstances. |
| 260 | */ |
| 261 | |
| 262 | /* Only whole objects can be extension members */ |
| 263 | Assert(object->objectSubId == 0); |
| 264 | |
| 265 | if (creating_extension) |
| 266 | { |
| 267 | Oid oldext; |
| 268 | |
| 269 | oldext = getExtensionOfObject(object->classId, object->objectId); |
| 270 | /* If already a member of this extension, OK */ |
| 271 | if (oldext == CurrentExtensionObject) |
| 272 | return; |
| 273 | /* Else complain */ |
| 274 | ereport(ERROR, |
| 275 | (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), |
| 276 | errmsg("%s is not a member of extension \"%s\"", |
| 277 | getObjectDescription(object, false), |
| 278 | get_extension_name(CurrentExtensionObject)), |
| 279 | errdetail("An extension may only use CREATE ... IF NOT EXISTS to skip object creation if the conflicting object is one that it already owns."))); |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | /* |
| 284 | * deleteDependencyRecordsFor -- delete all records with given depender |
no test coverage detected