PostgreSQL Source Code  git master
pg_largeobject.h File Reference
#include "catalog/genbki.h"
#include "catalog/pg_largeobject_d.h"
Include dependency graph for pg_largeobject.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef FormData_pg_largeobjectForm_pg_largeobject
 

Functions

 CATALOG (pg_largeobject, 2613, LargeObjectRelationId) BKI_WITHOUT_OIDS
 
Oid LargeObjectCreate (Oid loid)
 
void LargeObjectDrop (Oid loid)
 
bool LargeObjectExists (Oid loid)
 

Variables

 FormData_pg_largeobject
 

Typedef Documentation

◆ Form_pg_largeobject

Function Documentation

◆ CATALOG()

CATALOG ( pg_largeobject  ,
2613  ,
LargeObjectRelationId   
)

Definition at line 29 of file pg_largeobject.h.

References BKI_FORCE_NOT_NULL.

30 {
31  Oid loid; /* Identifier of large object */
32  int32 pageno; /* Page number (starting from 0) */
33 
34  /* data has variable length, but we allow direct access; see inv_api.c */
35  bytea data BKI_FORCE_NOT_NULL; /* Data for page (may be
36  * zero-length) */
FormData_pg_largeobject
unsigned int Oid
Definition: postgres_ext.h:31
signed int int32
Definition: c.h:313
#define BKI_FORCE_NOT_NULL
Definition: genbki.h:34
Definition: c.h:516

◆ LargeObjectCreate()

Oid LargeObjectCreate ( Oid  loid)

Definition at line 40 of file pg_largeobject.c.

References Assert, CatalogTupleInsert(), GetUserId(), heap_close, heap_form_tuple(), heap_freetuple(), heap_open(), HeapTupleSetOid, ObjectIdGetDatum, OidIsValid, RelationGetDescr, RowExclusiveLock, and values.

Referenced by inv_create().

41 {
42  Relation pg_lo_meta;
43  HeapTuple ntup;
44  Oid loid_new;
45  Datum values[Natts_pg_largeobject_metadata];
46  bool nulls[Natts_pg_largeobject_metadata];
47 
48  pg_lo_meta = heap_open(LargeObjectMetadataRelationId,
50 
51  /*
52  * Insert metadata of the largeobject
53  */
54  memset(values, 0, sizeof(values));
55  memset(nulls, false, sizeof(nulls));
56 
57  values[Anum_pg_largeobject_metadata_lomowner - 1]
59  nulls[Anum_pg_largeobject_metadata_lomacl - 1] = true;
60 
61  ntup = heap_form_tuple(RelationGetDescr(pg_lo_meta),
62  values, nulls);
63  if (OidIsValid(loid))
64  HeapTupleSetOid(ntup, loid);
65 
66  loid_new = CatalogTupleInsert(pg_lo_meta, ntup);
67  Assert(!OidIsValid(loid) || loid == loid_new);
68 
69  heap_freetuple(ntup);
70 
71  heap_close(pg_lo_meta, RowExclusiveLock);
72 
73  return loid_new;
74 }
#define RelationGetDescr(relation)
Definition: rel.h:433
Oid GetUserId(void)
Definition: miscinit.c:379
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:1074
#define heap_close(r, l)
Definition: heapam.h:97
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1773
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:605
#define HeapTupleSetOid(tuple, oid)
Definition: htup_details.h:710
#define ObjectIdGetDatum(X)
Definition: postgres.h:492
Oid CatalogTupleInsert(Relation heapRel, HeapTuple tup)
Definition: indexing.c:163
#define RowExclusiveLock
Definition: lockdefs.h:38
uintptr_t Datum
Definition: postgres.h:367
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1294
#define Assert(condition)
Definition: c.h:699
static Datum values[MAXATTR]
Definition: bootstrap.c:164

◆ LargeObjectDrop()

void LargeObjectDrop ( Oid  loid)

Definition at line 81 of file pg_largeobject.c.

References BTEqualStrategyNumber, CatalogTupleDelete(), ereport, errcode(), errmsg(), ERROR, heap_close, heap_open(), HeapTupleIsValid, LargeObjectLOidPNIndexId, LargeObjectMetadataOidIndexId, ObjectIdAttributeNumber, ObjectIdGetDatum, RowExclusiveLock, ScanKeyInit(), systable_beginscan(), systable_endscan(), systable_getnext(), and HeapTupleData::t_self.

Referenced by doDeletion().

82 {
83  Relation pg_lo_meta;
84  Relation pg_largeobject;
85  ScanKeyData skey[1];
86  SysScanDesc scan;
87  HeapTuple tuple;
88 
89  pg_lo_meta = heap_open(LargeObjectMetadataRelationId,
91 
92  pg_largeobject = heap_open(LargeObjectRelationId,
94 
95  /*
96  * Delete an entry from pg_largeobject_metadata
97  */
98  ScanKeyInit(&skey[0],
100  BTEqualStrategyNumber, F_OIDEQ,
101  ObjectIdGetDatum(loid));
102 
103  scan = systable_beginscan(pg_lo_meta,
105  NULL, 1, skey);
106 
107  tuple = systable_getnext(scan);
108  if (!HeapTupleIsValid(tuple))
109  ereport(ERROR,
110  (errcode(ERRCODE_UNDEFINED_OBJECT),
111  errmsg("large object %u does not exist", loid)));
112 
113  CatalogTupleDelete(pg_lo_meta, &tuple->t_self);
114 
115  systable_endscan(scan);
116 
117  /*
118  * Delete all the associated entries from pg_largeobject
119  */
120  ScanKeyInit(&skey[0],
121  Anum_pg_largeobject_loid,
122  BTEqualStrategyNumber, F_OIDEQ,
123  ObjectIdGetDatum(loid));
124 
125  scan = systable_beginscan(pg_largeobject,
127  NULL, 1, skey);
128  while (HeapTupleIsValid(tuple = systable_getnext(scan)))
129  {
130  CatalogTupleDelete(pg_largeobject, &tuple->t_self);
131  }
132 
133  systable_endscan(scan);
134 
135  heap_close(pg_largeobject, RowExclusiveLock);
136 
137  heap_close(pg_lo_meta, RowExclusiveLock);
138 }
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:502
#define ObjectIdAttributeNumber
Definition: sysattr.h:22
int errcode(int sqlerrcode)
Definition: elog.c:575
void CatalogTupleDelete(Relation heapRel, ItemPointer tid)
Definition: indexing.c:256
#define heap_close(r, l)
Definition: heapam.h:97
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:331
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:419
#define ObjectIdGetDatum(X)
Definition: postgres.h:492
#define ERROR
Definition: elog.h:43
ItemPointerData t_self
Definition: htup.h:65
#define LargeObjectLOidPNIndexId
Definition: indexing.h:181
#define RowExclusiveLock
Definition: lockdefs.h:38
#define ereport(elevel, rest)
Definition: elog.h:122
#define LargeObjectMetadataOidIndexId
Definition: indexing.h:184
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1294
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
int errmsg(const char *fmt,...)
Definition: elog.c:797
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
#define BTEqualStrategyNumber
Definition: stratnum.h:31

◆ LargeObjectExists()

bool LargeObjectExists ( Oid  loid)

Definition at line 153 of file pg_largeobject.c.

References AccessShareLock, BTEqualStrategyNumber, heap_close, heap_open(), HeapTupleIsValid, LargeObjectMetadataOidIndexId, ObjectIdAttributeNumber, ObjectIdGetDatum, ScanKeyInit(), systable_beginscan(), systable_endscan(), and systable_getnext().

Referenced by get_object_address(), and objectNamesToOids().

154 {
155  Relation pg_lo_meta;
156  ScanKeyData skey[1];
157  SysScanDesc sd;
158  HeapTuple tuple;
159  bool retval = false;
160 
161  ScanKeyInit(&skey[0],
163  BTEqualStrategyNumber, F_OIDEQ,
164  ObjectIdGetDatum(loid));
165 
166  pg_lo_meta = heap_open(LargeObjectMetadataRelationId,
168 
169  sd = systable_beginscan(pg_lo_meta,
171  NULL, 1, skey);
172 
173  tuple = systable_getnext(sd);
174  if (HeapTupleIsValid(tuple))
175  retval = true;
176 
177  systable_endscan(sd);
178 
179  heap_close(pg_lo_meta, AccessShareLock);
180 
181  return retval;
182 }
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:502
#define ObjectIdAttributeNumber
Definition: sysattr.h:22
#define AccessShareLock
Definition: lockdefs.h:36
#define heap_close(r, l)
Definition: heapam.h:97
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:331
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:419
#define ObjectIdGetDatum(X)
Definition: postgres.h:492
#define LargeObjectMetadataOidIndexId
Definition: indexing.h:184
Relation heap_open(Oid relationId, LOCKMODE lockmode)
Definition: heapam.c:1294
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
#define BTEqualStrategyNumber
Definition: stratnum.h:31

Variable Documentation

◆ FormData_pg_largeobject

FormData_pg_largeobject

Definition at line 37 of file pg_largeobject.h.