diff options
| author | Bruce Momjian <bruce@momjian.us> | 1999-10-26 03:12:39 +0000 |
|---|---|---|
| committer | Bruce Momjian <bruce@momjian.us> | 1999-10-26 03:12:39 +0000 |
| commit | 577e21b34f8629ce76651a6388298891f81be99a (patch) | |
| tree | f03a048bca5a17f70e4fa4337629d2ca52af6b34 /src/backend/catalog/heap.c | |
| parent | 51f62d505e2aba66bf7870c7bd005cd32e7d0953 (diff) | |
| download | postgresql-577e21b34f8629ce76651a6388298891f81be99a.tar.gz | |
Hello.
The following patch extends the COMMENT ON functionality to the
rest of the database objects beyond just tables, columns, and views. The
grammer of the COMMENT ON statement now looks like:
COMMENT ON [
[ DATABASE | INDEX | RULE | SEQUENCE | TABLE | TYPE | VIEW ] <objname>
|
COLUMN <relation>.<attribute> |
AGGREGATE <aggname> <aggtype> |
FUNCTION <funcname> (arg1, arg2, ...) |
OPERATOR <op> (leftoperand_typ rightoperand_typ) |
TRIGGER <triggername> ON relname>
Mike Mascari
(mascarim@yahoo.com)
Diffstat (limited to 'src/backend/catalog/heap.c')
| -rw-r--r-- | src/backend/catalog/heap.c | 148 |
1 files changed, 11 insertions, 137 deletions
diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index bd0a8668d0..eb934f6d3d 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.104 1999/10/15 01:49:39 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.105 1999/10/26 03:12:33 momjian Exp $ * * * INTERFACE ROUTINES @@ -45,6 +45,7 @@ #include "catalog/pg_proc.h" #include "catalog/pg_relcheck.h" #include "catalog/pg_type.h" +#include "commands/comment.h" #include "commands/trigger.h" #include "optimizer/clauses.h" #include "optimizer/planmain.h" @@ -1276,146 +1277,18 @@ DeleteAttributeTuples(Relation rel) Int16GetDatum(attnum), 0, 0))) { - DeleteComments(tup->t_data->t_oid); - heap_delete(pg_attribute_desc, &tup->t_self, NULL); - pfree(tup); - } - } - - heap_close(pg_attribute_desc, RowExclusiveLock); -} - -/* ---------------------------------------------------------- - * CreateComments - * - * This routine is handed the oid and the command associated - * with that id and will insert, update, or delete (if the - * comment is an empty string or a NULL pointer) the associated - * comment from the system cataloge, pg_description. - * - * ---------------------------------------------------------- - */ - -void -CreateComments(Oid oid, char *comment) -{ + + /*** Delete any comments associated with this attribute ***/ - Relation description; - TupleDesc tupDesc; - HeapScanDesc scan; - ScanKeyData entry; - HeapTuple desctuple, searchtuple; - Datum values[Natts_pg_description]; - char nulls[Natts_pg_description]; - char replaces[Natts_pg_description]; - bool modified = false; - int i; - - /*** Open pg_description, form a new tuple, if necessary ***/ - - description = heap_openr(DescriptionRelationName, RowExclusiveLock); - tupDesc = description->rd_att; - if ((comment != NULL) && (strlen(comment) > 0)) { - for (i = 0; i < Natts_pg_description; i++) { - nulls[i] = ' '; - replaces[i] = 'r'; - values[i] = (Datum) NULL; - } - i = 0; - values[i++] = ObjectIdGetDatum(oid); - values[i++] = (Datum) fmgr(F_TEXTIN, comment); - } - - /*** Now, open pg_description and attempt to find the old tuple ***/ - - ScanKeyEntryInitialize(&entry, 0x0, Anum_pg_description_objoid, F_OIDEQ, - ObjectIdGetDatum(oid)); - scan = heap_beginscan(description, false, SnapshotNow, 1, &entry); - searchtuple = heap_getnext(scan, 0); - - /*** If a previous tuple exists, either delete it or prepare a replacement ***/ - - if (HeapTupleIsValid(searchtuple)) { - - /*** If the comment is blank, call heap_delete, else heap_replace ***/ - - if ((comment == NULL) || (strlen(comment) == 0)) { - heap_delete(description, &searchtuple->t_self, NULL); - } else { - desctuple = heap_modifytuple(searchtuple, description, values, nulls, replaces); - setheapoverride(true); - heap_replace(description, &searchtuple->t_self, desctuple, NULL); - setheapoverride(false); - modified = TRUE; - } - - } else { - desctuple = heap_formtuple(tupDesc, values, nulls); - heap_insert(description, desctuple); - modified = TRUE; - } - - /*** Complete the scan, update indices, if necessary ***/ - - heap_endscan(scan); - - if (modified) { - if (RelationGetForm(description)->relhasindex) { - Relation idescs[Num_pg_description_indices]; - - CatalogOpenIndices(Num_pg_description_indices, Name_pg_description_indices, idescs); - CatalogIndexInsert(idescs, Num_pg_description_indices, description, desctuple); - CatalogCloseIndices(Num_pg_description_indices, idescs); - } - pfree(desctuple); - - } - - heap_close(description, RowExclusiveLock); + DeleteComments(tup->t_data->t_oid); -} - -/* -------------------------------- - * DeleteComments - * - * This routine is used to purge any comments - * associated with the Oid handed to this routine, - * regardless of the actual object type. It is - * called, for example, when a relation is destroyed. - * -------------------------------- - */ + heap_delete(pg_attribute_desc, &tup->t_self, NULL); + pfree(tup); -void -DeleteComments(Oid oid) -{ + } + } - Relation description; - TupleDesc tupDesc; - ScanKeyData entry; - HeapScanDesc scan; - HeapTuple searchtuple; - - description = heap_openr(DescriptionRelationName, RowExclusiveLock); - tupDesc = description->rd_att; - - /*** Now, open pg_description and attempt to find the old tuple ***/ - - ScanKeyEntryInitialize(&entry, 0x0, Anum_pg_description_objoid, F_OIDEQ, - ObjectIdGetDatum(oid)); - scan = heap_beginscan(description, false, SnapshotNow, 1, &entry); - searchtuple = heap_getnext(scan, 0); - - /*** If a previous tuple exists, delete it ***/ - - if (HeapTupleIsValid(searchtuple)) { - heap_delete(description, &searchtuple->t_self, NULL); - } - - /*** Complete the scan, update indices, if necessary ***/ - - heap_endscan(scan); - heap_close(description, RowExclusiveLock); - + heap_close(pg_attribute_desc, RowExclusiveLock); } /* -------------------------------- @@ -1529,6 +1402,7 @@ DeleteTypeTuple(Relation rel) * we release the read lock on pg_type. -mer 13 Aug 1991 * ---------------- */ + heap_delete(pg_type_desc, &tup->t_self, NULL); heap_endscan(pg_type_scan); |
