Disallow empty passwords in LDAP authentication, the same way
[PostgreSQL.git] / src / backend / catalog / pg_largeobject.c
blobc92ab024e5c97b6780b947bf63152c9ea5617528
1 /*-------------------------------------------------------------------------
3 * pg_largeobject.c
4 * routines to support manipulation of the pg_largeobject relation
6 * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
10 * IDENTIFICATION
11 * $PostgreSQL$
13 *-------------------------------------------------------------------------
15 #include "postgres.h"
17 #include "access/genam.h"
18 #include "access/heapam.h"
19 #include "catalog/indexing.h"
20 #include "catalog/pg_largeobject.h"
21 #include "utils/builtins.h"
22 #include "utils/fmgroids.h"
23 #include "utils/rel.h"
24 #include "utils/tqual.h"
28 * Create a large object having the given LO identifier.
30 * We do this by inserting an empty first page, so that the object will
31 * appear to exist with size 0. Note that the unique index will reject
32 * an attempt to create a duplicate page.
34 void
35 LargeObjectCreate(Oid loid)
37 Relation pg_largeobject;
38 HeapTuple ntup;
39 Datum values[Natts_pg_largeobject];
40 bool nulls[Natts_pg_largeobject];
41 int i;
43 pg_largeobject = heap_open(LargeObjectRelationId, RowExclusiveLock);
46 * Form new tuple
48 for (i = 0; i < Natts_pg_largeobject; i++)
50 values[i] = (Datum) NULL;
51 nulls[i] = false;
54 i = 0;
55 values[i++] = ObjectIdGetDatum(loid);
56 values[i++] = Int32GetDatum(0);
57 values[i++] = DirectFunctionCall1(byteain,
58 CStringGetDatum(""));
60 ntup = heap_form_tuple(pg_largeobject->rd_att, values, nulls);
63 * Insert it
65 simple_heap_insert(pg_largeobject, ntup);
67 /* Update indexes */
68 CatalogUpdateIndexes(pg_largeobject, ntup);
70 heap_close(pg_largeobject, RowExclusiveLock);
72 heap_freetuple(ntup);
75 void
76 LargeObjectDrop(Oid loid)
78 bool found = false;
79 Relation pg_largeobject;
80 ScanKeyData skey[1];
81 SysScanDesc sd;
82 HeapTuple tuple;
84 ScanKeyInit(&skey[0],
85 Anum_pg_largeobject_loid,
86 BTEqualStrategyNumber, F_OIDEQ,
87 ObjectIdGetDatum(loid));
89 pg_largeobject = heap_open(LargeObjectRelationId, RowExclusiveLock);
91 sd = systable_beginscan(pg_largeobject, LargeObjectLOidPNIndexId, true,
92 SnapshotNow, 1, skey);
94 while ((tuple = systable_getnext(sd)) != NULL)
96 simple_heap_delete(pg_largeobject, &tuple->t_self);
97 found = true;
100 systable_endscan(sd);
102 heap_close(pg_largeobject, RowExclusiveLock);
104 if (!found)
105 ereport(ERROR,
106 (errcode(ERRCODE_UNDEFINED_OBJECT),
107 errmsg("large object %u does not exist", loid)));
110 bool
111 LargeObjectExists(Oid loid)
113 bool retval = false;
114 Relation pg_largeobject;
115 ScanKeyData skey[1];
116 SysScanDesc sd;
119 * See if we can find any tuples belonging to the specified LO
121 ScanKeyInit(&skey[0],
122 Anum_pg_largeobject_loid,
123 BTEqualStrategyNumber, F_OIDEQ,
124 ObjectIdGetDatum(loid));
126 pg_largeobject = heap_open(LargeObjectRelationId, AccessShareLock);
128 sd = systable_beginscan(pg_largeobject, LargeObjectLOidPNIndexId, true,
129 SnapshotNow, 1, skey);
131 if (systable_getnext(sd) != NULL)
132 retval = true;
134 systable_endscan(sd);
136 heap_close(pg_largeobject, AccessShareLock);
138 return retval;