* Find the extension containing the specified object, if any * * Returns the OID of the extension, or InvalidOid if the object does not * belong to any extension. * * Extension membership is marked by an EXTENSION dependency from the object * to the extension. Note that the result will be indeterminate if pg_depend * contains links from this object to more than one extension ... but that
| 762 | * should never happen. |
| 763 | */ |
| 764 | Oid |
| 765 | getExtensionOfObject(Oid classId, Oid objectId) |
| 766 | { |
| 767 | Oid result = InvalidOid; |
| 768 | Relation depRel; |
| 769 | ScanKeyData key[2]; |
| 770 | SysScanDesc scan; |
| 771 | HeapTuple tup; |
| 772 | |
| 773 | depRel = table_open(DependRelationId, AccessShareLock); |
| 774 | |
| 775 | ScanKeyInit(&key[0], |
| 776 | Anum_pg_depend_classid, |
| 777 | BTEqualStrategyNumber, F_OIDEQ, |
| 778 | ObjectIdGetDatum(classId)); |
| 779 | ScanKeyInit(&key[1], |
| 780 | Anum_pg_depend_objid, |
| 781 | BTEqualStrategyNumber, F_OIDEQ, |
| 782 | ObjectIdGetDatum(objectId)); |
| 783 | |
| 784 | scan = systable_beginscan(depRel, DependDependerIndexId, true, |
| 785 | NULL, 2, key); |
| 786 | |
| 787 | while (HeapTupleIsValid((tup = systable_getnext(scan)))) |
| 788 | { |
| 789 | Form_pg_depend depform = (Form_pg_depend) GETSTRUCT(tup); |
| 790 | |
| 791 | if (depform->refclassid == ExtensionRelationId && |
| 792 | depform->deptype == DEPENDENCY_EXTENSION) |
| 793 | { |
| 794 | result = depform->refobjid; |
| 795 | break; /* no need to keep scanning */ |
| 796 | } |
| 797 | } |
| 798 | |
| 799 | systable_endscan(scan); |
| 800 | |
| 801 | table_close(depRel, AccessShareLock); |
| 802 | |
| 803 | return result; |
| 804 | } |
| 805 | |
| 806 | /* |
| 807 | * Return (possibly NIL) list of extensions that the given object depends on |
no test coverage detected