From 7acc237744b3e9a697959eec367adb44fff554a7 Mon Sep 17 00:00:00 2001 From: Bruce Momjian Date: Fri, 15 Oct 1999 01:49:49 +0000 Subject: This patch implements ORACLE's COMMENT SQL command. >From the ORACLE 7 SQL Language Reference Manual: ----------------------------------------------------- COMMENT Purpose: To add a comment about a table, view, snapshot, or column into the data dictionary. Prerequisites: The table, view, or snapshot must be in your own schema or you must have COMMENT ANY TABLE system privilege. Syntax: COMMENT ON [ TABLE table ] | [ COLUMN table.column] IS 'text' You can effectively drop a comment from the database by setting it to the empty string ''. ----------------------------------------------------- Example: COMMENT ON TABLE workorders IS 'Maintains base records for workorder information'; COMMENT ON COLUMN workorders.hours IS 'Number of hours the engineer worked on the task'; to drop a comment: COMMENT ON COLUMN workorders.hours IS ''; The current patch will simply perform the insert into pg_description, as per the TODO. And, of course, when the table is dropped, any comments relating to it or any of its attributes are also dropped. I haven't looked at the ODBC source yet, but I do know from an ODBC client standpoint that the standard does support the notion of table and column comments. Hopefully the ODBC driver is already fetching these values from pg_description, but if not, it should be trivial. Hope this makes the grade, Mike Mascari (mascarim@yahoo.com) --- src/backend/commands/creatinh.c | 50 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) (limited to 'src/backend/commands/creatinh.c') diff --git a/src/backend/commands/creatinh.c b/src/backend/commands/creatinh.c index 0b2d2360b3c..9463d55a6a1 100644 --- a/src/backend/commands/creatinh.c +++ b/src/backend/commands/creatinh.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/commands/Attic/creatinh.c,v 1.48 1999/10/03 23:55:27 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/Attic/creatinh.c,v 1.49 1999/10/15 01:49:39 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -16,10 +16,12 @@ #include "access/heapam.h" #include "catalog/catname.h" +#include "catalog/indexing.h" #include "catalog/heap.h" #include "catalog/pg_inherits.h" #include "catalog/pg_ipl.h" #include "catalog/pg_type.h" +#include "catalog/pg_description.h" #include "commands/creatinh.h" #include "utils/syscache.h" @@ -232,6 +234,52 @@ TruncateRelation(char *name) heap_truncate(name); } +/*------------------------------------------------------------------ + * CommentRelation -- + * Adds a comment to pg_description for the associated + * relation or relation attribute. + * + * Note: + * The comment is dropped on the relation or attribute if + * the comment is an empty string. + *------------------------------------------------------------------ + */ +void +CommentRelation(char *relname, char *attrname, char *comments) +{ + + Relation relation; + HeapTuple attrtuple; + Oid oid; + + /*** First ensure relname is valid ***/ + + relation = heap_openr(relname, AccessShareLock); + + /*** Now, if an attribute was specified, fetch its oid, else use relation's oid ***/ + + if (attrname != NULL) { + attrtuple = SearchSysCacheTuple(ATTNAME, ObjectIdGetDatum(relation->rd_id), + PointerGetDatum(attrname), 0, 0); + if (!HeapTupleIsValid(attrtuple)) { + elog(ERROR, "CommentRelation: attribute \"%s\" is not an attribute of relation \"%s\"", + attrname, relname); + } + oid = attrtuple->t_data->t_oid; + } else { + oid = RelationGetRelid(relation); + } + + /*** Call CreateComments() to create/drop the comments ***/ + + CreateComments(oid, comments); + + /*** Now, close the heap relation ***/ + + heap_close(relation, AccessShareLock); + +} + /* * MergeAttributes * Returns new schema given initial schema and supers. -- cgit v1.2.3