PostgreSQL Source Code git master
Functions
pg_largeobject.c File Reference
#include "postgres.h"
#include "access/htup_details.h"
#include "access/table.h"
#include "catalog/catalog.h"
#include "catalog/indexing.h"
#include "catalog/pg_largeobject.h"
#include "catalog/pg_largeobject_metadata.h"
#include "miscadmin.h"
#include "utils/acl.h"
#include "utils/fmgroids.h"
#include "utils/rel.h"
Include dependency graph for pg_largeobject.c:

Go to the source code of this file.

Functions

 
void  LargeObjectDrop (Oid loid)
 
bool  LargeObjectExists (Oid loid)
 
bool  LargeObjectExistsWithSnapshot (Oid loid, Snapshot snapshot)
 

Function Documentation

LargeObjectCreate()

Oid LargeObjectCreate ( Oid  loid )

Definition at line 37 of file pg_largeobject.c.

38{
39 Relation pg_lo_meta;
40 HeapTuple ntup;
41 Oid loid_new;
42 Datum values[Natts_pg_largeobject_metadata];
43 bool nulls[Natts_pg_largeobject_metadata];
44 Oid ownerId;
45 Acl *lomacl;
46
47 pg_lo_meta = table_open(LargeObjectMetadataRelationId,
49
50 /*
51 * Insert metadata of the largeobject
52 */
53 memset(values, 0, sizeof(values));
54 memset(nulls, false, sizeof(nulls));
55
56 if (OidIsValid(loid))
57 loid_new = loid;
58 else
59 loid_new = GetNewOidWithIndex(pg_lo_meta,
60 LargeObjectMetadataOidIndexId,
61 Anum_pg_largeobject_metadata_oid);
62 ownerId = GetUserId();
64
65 values[Anum_pg_largeobject_metadata_oid - 1] = ObjectIdGetDatum(loid_new);
66 values[Anum_pg_largeobject_metadata_lomowner - 1]
67 = ObjectIdGetDatum(ownerId);
68
69 if (lomacl != NULL)
70 values[Anum_pg_largeobject_metadata_lomacl - 1]
71 = PointerGetDatum(lomacl);
72 else
73 nulls[Anum_pg_largeobject_metadata_lomacl - 1] = true;
74
75 ntup = heap_form_tuple(RelationGetDescr(pg_lo_meta),
76 values, nulls);
77
78 CatalogTupleInsert(pg_lo_meta, ntup);
79
80 heap_freetuple(ntup);
81
82 table_close(pg_lo_meta, RowExclusiveLock);
83
84 /* dependencies on roles mentioned in default ACL */
85 recordDependencyOnNewAcl(LargeObjectRelationId, loid_new, 0,
86 ownerId, lomacl);
87
88 return loid_new;
89}
void recordDependencyOnNewAcl(Oid classId, Oid objectId, int32 objsubId, Oid ownerId, Acl *acl)
Definition: aclchk.c:4325
Acl * get_user_default_acl(ObjectType objtype, Oid ownerId, Oid nsp_oid)
Definition: aclchk.c:4245
static Datum values[MAXATTR]
Definition: bootstrap.c:153
#define OidIsValid(objectId)
Definition: c.h:774
Oid GetNewOidWithIndex(Relation relation, Oid indexId, AttrNumber oidcolumn)
Definition: catalog.c:448
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
Definition: heaptuple.c:1117
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1435
void CatalogTupleInsert(Relation heapRel, HeapTuple tup)
Definition: indexing.c:233
#define RowExclusiveLock
Definition: lockdefs.h:38
Oid GetUserId(void)
Definition: miscinit.c:469
@ OBJECT_LARGEOBJECT
Definition: parsenodes.h:2347
static Datum PointerGetDatum(const void *X)
Definition: postgres.h:332
static Datum ObjectIdGetDatum(Oid X)
Definition: postgres.h:262
uint64_t Datum
Definition: postgres.h:70
#define InvalidOid
Definition: postgres_ext.h:37
unsigned int Oid
Definition: postgres_ext.h:32
#define RelationGetDescr(relation)
Definition: rel.h:540
Definition: array.h:93
Definition: rel.h:56
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:126
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:40

References CatalogTupleInsert(), get_user_default_acl(), GetNewOidWithIndex(), GetUserId(), heap_form_tuple(), heap_freetuple(), InvalidOid, OBJECT_LARGEOBJECT, ObjectIdGetDatum(), OidIsValid, PointerGetDatum(), recordDependencyOnNewAcl(), RelationGetDescr, RowExclusiveLock, table_close(), table_open(), and values.

Referenced by inv_create().

LargeObjectDrop()

void LargeObjectDrop ( Oid  loid )

Definition at line 96 of file pg_largeobject.c.

97{
98 Relation pg_lo_meta;
99 Relation pg_largeobject;
100 ScanKeyData skey[1];
101 SysScanDesc scan;
102 HeapTuple tuple;
103
104 pg_lo_meta = table_open(LargeObjectMetadataRelationId,
106
107 pg_largeobject = table_open(LargeObjectRelationId,
109
110 /*
111 * Delete an entry from pg_largeobject_metadata
112 */
113 ScanKeyInit(&skey[0],
114 Anum_pg_largeobject_metadata_oid,
115 BTEqualStrategyNumber, F_OIDEQ,
116 ObjectIdGetDatum(loid));
117
118 scan = systable_beginscan(pg_lo_meta,
119 LargeObjectMetadataOidIndexId, true,
120 NULL, 1, skey);
121
122 tuple = systable_getnext(scan);
123 if (!HeapTupleIsValid(tuple))
125 (errcode(ERRCODE_UNDEFINED_OBJECT),
126 errmsg("large object %u does not exist", loid)));
127
128 CatalogTupleDelete(pg_lo_meta, &tuple->t_self);
129
130 systable_endscan(scan);
131
132 /*
133 * Delete all the associated entries from pg_largeobject
134 */
135 ScanKeyInit(&skey[0],
136 Anum_pg_largeobject_loid,
137 BTEqualStrategyNumber, F_OIDEQ,
138 ObjectIdGetDatum(loid));
139
140 scan = systable_beginscan(pg_largeobject,
141 LargeObjectLOidPNIndexId, true,
142 NULL, 1, skey);
143 while (HeapTupleIsValid(tuple = systable_getnext(scan)))
144 {
145 CatalogTupleDelete(pg_largeobject, &tuple->t_self);
146 }
147
148 systable_endscan(scan);
149
150 table_close(pg_largeobject, RowExclusiveLock);
151
152 table_close(pg_lo_meta, RowExclusiveLock);
153}
int errcode(int sqlerrcode)
Definition: elog.c:854
int errmsg(const char *fmt,...)
Definition: elog.c:1071
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:150
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:603
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:514
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:388
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
void CatalogTupleDelete(Relation heapRel, ItemPointer tid)
Definition: indexing.c:365
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
#define BTEqualStrategyNumber
Definition: stratnum.h:31
ItemPointerData t_self
Definition: htup.h:65
Definition: skey.h:65

References BTEqualStrategyNumber, CatalogTupleDelete(), ereport, errcode(), errmsg(), ERROR, HeapTupleIsValid, ObjectIdGetDatum(), RowExclusiveLock, ScanKeyInit(), systable_beginscan(), systable_endscan(), systable_getnext(), HeapTupleData::t_self, table_close(), and table_open().

Referenced by doDeletion().

LargeObjectExists()

bool LargeObjectExists ( Oid  loid )

Definition at line 168 of file pg_largeobject.c.

169{
170 return LargeObjectExistsWithSnapshot(loid, NULL);
171}
bool LargeObjectExistsWithSnapshot(Oid loid, Snapshot snapshot)

References LargeObjectExistsWithSnapshot().

Referenced by be_lo_unlink(), get_object_address(), getObjectDescription(), and getObjectIdentityParts().

LargeObjectExistsWithSnapshot()

bool LargeObjectExistsWithSnapshot ( Oid  loid,
Snapshot  snapshot 
)

Definition at line 177 of file pg_largeobject.c.

178{
179 Relation pg_lo_meta;
180 ScanKeyData skey[1];
181 SysScanDesc sd;
182 HeapTuple tuple;
183 bool retval = false;
184
185 ScanKeyInit(&skey[0],
186 Anum_pg_largeobject_metadata_oid,
187 BTEqualStrategyNumber, F_OIDEQ,
188 ObjectIdGetDatum(loid));
189
190 pg_lo_meta = table_open(LargeObjectMetadataRelationId,
192
193 sd = systable_beginscan(pg_lo_meta,
194 LargeObjectMetadataOidIndexId, true,
195 snapshot, 1, skey);
196
197 tuple = systable_getnext(sd);
198 if (HeapTupleIsValid(tuple))
199 retval = true;
200
202
203 table_close(pg_lo_meta, AccessShareLock);
204
205 return retval;
206}
#define AccessShareLock
Definition: lockdefs.h:36

References AccessShareLock, BTEqualStrategyNumber, HeapTupleIsValid, ObjectIdGetDatum(), ScanKeyInit(), systable_beginscan(), systable_endscan(), systable_getnext(), table_close(), and table_open().

Referenced by has_lo_priv_byid(), inv_open(), and LargeObjectExists().

AltStyle によって変換されたページ (->オリジナル) /