Header And Logo

PostgreSQL
| The world's most advanced open source database.

Defines | Typedefs | Functions | Variables

pg_largeobject.h File Reference

#include "catalog/genbki.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.

Defines

#define LargeObjectRelationId   2613
#define Natts_pg_largeobject   3
#define Anum_pg_largeobject_loid   1
#define Anum_pg_largeobject_pageno   2
#define Anum_pg_largeobject_data   3

Typedefs

typedef FormData_pg_largeobjectForm_pg_largeobject

Functions

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

Variables

 FormData_pg_largeobject

Define Documentation

#define Anum_pg_largeobject_data   3

Definition at line 54 of file pg_largeobject.h.

Referenced by inv_truncate(), and inv_write().

#define Anum_pg_largeobject_loid   1

Definition at line 52 of file pg_largeobject.h.

Referenced by inv_getsize(), inv_read(), inv_truncate(), inv_write(), and LargeObjectDrop().

#define Anum_pg_largeobject_pageno   2

Definition at line 53 of file pg_largeobject.h.

Referenced by inv_read(), inv_truncate(), and inv_write().

#define LargeObjectRelationId   2613
#define Natts_pg_largeobject   3

Definition at line 51 of file pg_largeobject.h.


Typedef Documentation

Definition at line 45 of file pg_largeobject.h.


Function Documentation

CATALOG ( pg_largeobject  ,
2613   
)

Definition at line 31 of file pg_largeobject.h.

{
    Oid         loid;           /* Identifier of large object */
    int32       pageno;         /* Page number (starting from 0) */

    /* data has variable length, but we allow direct access; see inv_api.c */
    bytea       data;           /* Data for page (may be zero-length) */
} FormData_pg_largeobject;

Oid LargeObjectCreate ( Oid  loid  ) 

Definition at line 40 of file pg_largeobject.c.

References Anum_pg_largeobject_metadata_lomacl, Anum_pg_largeobject_metadata_lomowner, Assert, CatalogUpdateIndexes(), GetUserId(), heap_close, heap_form_tuple(), heap_freetuple(), heap_open(), HeapTupleSetOid, LargeObjectMetadataRelationId, ObjectIdGetDatum, OidIsValid, RelationGetDescr, RowExclusiveLock, simple_heap_insert(), and values.

Referenced by inv_create().

{
    Relation    pg_lo_meta;
    HeapTuple   ntup;
    Oid         loid_new;
    Datum       values[Natts_pg_largeobject_metadata];
    bool        nulls[Natts_pg_largeobject_metadata];

    pg_lo_meta = heap_open(LargeObjectMetadataRelationId,
                           RowExclusiveLock);

    /*
     * Insert metadata of the largeobject
     */
    memset(values, 0, sizeof(values));
    memset(nulls, false, sizeof(nulls));

    values[Anum_pg_largeobject_metadata_lomowner - 1]
        = ObjectIdGetDatum(GetUserId());
    nulls[Anum_pg_largeobject_metadata_lomacl - 1] = true;

    ntup = heap_form_tuple(RelationGetDescr(pg_lo_meta),
                           values, nulls);
    if (OidIsValid(loid))
        HeapTupleSetOid(ntup, loid);

    loid_new = simple_heap_insert(pg_lo_meta, ntup);
    Assert(!OidIsValid(loid) || loid == loid_new);

    CatalogUpdateIndexes(pg_lo_meta, ntup);

    heap_freetuple(ntup);

    heap_close(pg_lo_meta, RowExclusiveLock);

    return loid_new;
}

void LargeObjectDrop ( Oid  loid  ) 

Definition at line 83 of file pg_largeobject.c.

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

Referenced by doDeletion().

{
    Relation    pg_lo_meta;
    Relation    pg_largeobject;
    ScanKeyData skey[1];
    SysScanDesc scan;
    HeapTuple   tuple;

    pg_lo_meta = heap_open(LargeObjectMetadataRelationId,
                           RowExclusiveLock);

    pg_largeobject = heap_open(LargeObjectRelationId,
                               RowExclusiveLock);

    /*
     * Delete an entry from pg_largeobject_metadata
     */
    ScanKeyInit(&skey[0],
                ObjectIdAttributeNumber,
                BTEqualStrategyNumber, F_OIDEQ,
                ObjectIdGetDatum(loid));

    scan = systable_beginscan(pg_lo_meta,
                              LargeObjectMetadataOidIndexId, true,
                              SnapshotNow, 1, skey);

    tuple = systable_getnext(scan);
    if (!HeapTupleIsValid(tuple))
        ereport(ERROR,
                (errcode(ERRCODE_UNDEFINED_OBJECT),
                 errmsg("large object %u does not exist", loid)));

    simple_heap_delete(pg_lo_meta, &tuple->t_self);

    systable_endscan(scan);

    /*
     * Delete all the associated entries from pg_largeobject
     */
    ScanKeyInit(&skey[0],
                Anum_pg_largeobject_loid,
                BTEqualStrategyNumber, F_OIDEQ,
                ObjectIdGetDatum(loid));

    scan = systable_beginscan(pg_largeobject,
                              LargeObjectLOidPNIndexId, true,
                              SnapshotNow, 1, skey);
    while (HeapTupleIsValid(tuple = systable_getnext(scan)))
    {
        simple_heap_delete(pg_largeobject, &tuple->t_self);
    }

    systable_endscan(scan);

    heap_close(pg_largeobject, RowExclusiveLock);

    heap_close(pg_lo_meta, RowExclusiveLock);
}

bool LargeObjectExists ( Oid  loid  ) 

Variable Documentation

Definition at line 38 of file pg_largeobject.h.