Commit 577e21b3 authored by Bruce Momjian's avatar Bruce Momjian

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)
parent 51f62d50
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * 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 * INTERFACE ROUTINES
...@@ -45,6 +45,7 @@ ...@@ -45,6 +45,7 @@
#include "catalog/pg_proc.h" #include "catalog/pg_proc.h"
#include "catalog/pg_relcheck.h" #include "catalog/pg_relcheck.h"
#include "catalog/pg_type.h" #include "catalog/pg_type.h"
#include "commands/comment.h"
#include "commands/trigger.h" #include "commands/trigger.h"
#include "optimizer/clauses.h" #include "optimizer/clauses.h"
#include "optimizer/planmain.h" #include "optimizer/planmain.h"
...@@ -1276,146 +1277,18 @@ DeleteAttributeTuples(Relation rel) ...@@ -1276,146 +1277,18 @@ DeleteAttributeTuples(Relation rel)
Int16GetDatum(attnum), Int16GetDatum(attnum),
0, 0))) 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)
{
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 { /*** Delete any comments associated with this attribute ***/
desctuple = heap_formtuple(tupDesc, values, nulls);
heap_insert(description, desctuple);
modified = TRUE;
}
/*** Complete the scan, update indices, if necessary ***/
heap_endscan(scan);
if (modified) { DeleteComments(tup->t_data->t_oid);
if (RelationGetForm(description)->relhasindex) {
Relation idescs[Num_pg_description_indices];
CatalogOpenIndices(Num_pg_description_indices, Name_pg_description_indices, idescs); heap_delete(pg_attribute_desc, &tup->t_self, NULL);
CatalogIndexInsert(idescs, Num_pg_description_indices, description, desctuple); pfree(tup);
CatalogCloseIndices(Num_pg_description_indices, idescs);
}
pfree(desctuple);
} }
heap_close(description, RowExclusiveLock);
}
/* --------------------------------
* 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.
* --------------------------------
*/
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_close(pg_attribute_desc, RowExclusiveLock);
heap_endscan(scan);
heap_close(description, RowExclusiveLock);
} }
/* -------------------------------- /* --------------------------------
...@@ -1529,6 +1402,7 @@ DeleteTypeTuple(Relation rel) ...@@ -1529,6 +1402,7 @@ DeleteTypeTuple(Relation rel)
* we release the read lock on pg_type. -mer 13 Aug 1991 * we release the read lock on pg_type. -mer 13 Aug 1991
* ---------------- * ----------------
*/ */
heap_delete(pg_type_desc, &tup->t_self, NULL); heap_delete(pg_type_desc, &tup->t_self, NULL);
heap_endscan(pg_type_scan); heap_endscan(pg_type_scan);
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.91 1999/09/24 00:24:11 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.92 1999/10/26 03:12:33 momjian Exp $
* *
* *
* INTERFACE ROUTINES * INTERFACE ROUTINES
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include "catalog/pg_index.h" #include "catalog/pg_index.h"
#include "catalog/pg_proc.h" #include "catalog/pg_proc.h"
#include "catalog/pg_type.h" #include "catalog/pg_type.h"
#include "commands/comment.h"
#include "executor/executor.h" #include "executor/executor.h"
#include "miscadmin.h" #include "miscadmin.h"
#include "optimizer/clauses.h" #include "optimizer/clauses.h"
...@@ -1127,6 +1128,13 @@ index_destroy(Oid indexId) ...@@ -1127,6 +1128,13 @@ index_destroy(Oid indexId)
if (IsTransactionBlock() && ! userindexRelation->rd_myxactonly) if (IsTransactionBlock() && ! userindexRelation->rd_myxactonly)
elog(NOTICE, "Caution: DROP INDEX cannot be rolled back, so don't abort now"); elog(NOTICE, "Caution: DROP INDEX cannot be rolled back, so don't abort now");
/* ----------------
* fix DESCRIPTION relation
* ----------------
*/
DeleteComments(indexId);
/* ---------------- /* ----------------
* fix RELATION relation * fix RELATION relation
* ---------------- * ----------------
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
# Makefile for commands # Makefile for commands
# #
# IDENTIFICATION # IDENTIFICATION
# $Header: /cvsroot/pgsql/src/backend/commands/Makefile,v 1.18 1999/02/27 21:42:33 tgl Exp $ # $Header: /cvsroot/pgsql/src/backend/commands/Makefile,v 1.19 1999/10/26 03:12:34 momjian Exp $
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
...@@ -17,7 +17,7 @@ ifdef MULTIBYTE ...@@ -17,7 +17,7 @@ ifdef MULTIBYTE
CFLAGS+= $(MBFLAGS) CFLAGS+= $(MBFLAGS)
endif endif
OBJS = async.o creatinh.o command.o copy.o indexcmds.o define.o \ OBJS = async.o creatinh.o command.o comment.o copy.o indexcmds.o define.o \
remove.o rename.o vacuum.o view.o cluster.o \ remove.o rename.o vacuum.o view.o cluster.o \
explain.o sequence.o trigger.o user.o proclang.o \ explain.o sequence.o trigger.o user.o proclang.o \
dbcommands.o variable.o dbcommands.o variable.o
...@@ -27,6 +27,12 @@ all: SUBSYS.o ...@@ -27,6 +27,12 @@ all: SUBSYS.o
SUBSYS.o: $(OBJS) SUBSYS.o: $(OBJS)
$(LD) -r -o SUBSYS.o $(OBJS) $(LD) -r -o SUBSYS.o $(OBJS)
# The following declares a hard-coded dependency on parse.h since,
# if compiled without make dep, comment.c would get compiled before
# the parser.
comment.o: ../parse.h
depend dep: depend dep:
$(CC) -MM $(CFLAGS) *.c >depend $(CC) -MM $(CFLAGS) *.c >depend
......
This diff is collapsed.
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/creatinh.c,v 1.49 1999/10/15 01:49:39 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/Attic/creatinh.c,v 1.50 1999/10/26 03:12:34 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -234,52 +234,6 @@ TruncateRelation(char *name) ...@@ -234,52 +234,6 @@ TruncateRelation(char *name)
heap_truncate(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 * MergeAttributes
* Returns new schema given initial schema and supers. * Returns new schema given initial schema and supers.
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.42 1999/10/25 03:07:43 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.43 1999/10/26 03:12:34 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "catalog/catname.h" #include "catalog/catname.h"
#include "catalog/pg_database.h" #include "catalog/pg_database.h"
#include "catalog/pg_shadow.h" #include "catalog/pg_shadow.h"
#include "commands/comment.h"
#include "commands/dbcommands.h" #include "commands/dbcommands.h"
#include "miscadmin.h" #include "miscadmin.h"
#include "storage/sinval.h" #include "storage/sinval.h"
...@@ -149,6 +150,10 @@ destroydb(char *dbname, CommandDest dest) ...@@ -149,6 +150,10 @@ destroydb(char *dbname, CommandDest dest)
dbname, db_id); dbname, db_id);
} }
/*** Delete any comments associated with the database ***/
DeleteComments(db_id);
/* /*
* Houston, we have launch commit... * Houston, we have launch commit...
* *
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/remove.c,v 1.37 1999/09/18 19:06:40 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/Attic/remove.c,v 1.38 1999/10/26 03:12:34 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "catalog/pg_language.h" #include "catalog/pg_language.h"
#include "catalog/pg_proc.h" #include "catalog/pg_proc.h"
#include "catalog/pg_type.h" #include "catalog/pg_type.h"
#include "commands/comment.h"
#include "commands/defrem.h" #include "commands/defrem.h"
#include "miscadmin.h" #include "miscadmin.h"
#include "parser/parse_func.h" #include "parser/parse_func.h"
...@@ -93,7 +94,14 @@ RemoveOperator(char *operatorName, /* operator name */ ...@@ -93,7 +94,14 @@ RemoveOperator(char *operatorName, /* operator name */
elog(ERROR, "RemoveOperator: operator '%s': permission denied", elog(ERROR, "RemoveOperator: operator '%s': permission denied",
operatorName); operatorName);
#endif #endif
/*** Delete any comments associated with this operator ***/
DeleteComments(tup->t_data->t_oid);
heap_delete(relation, &tup->t_self, NULL); heap_delete(relation, &tup->t_self, NULL);
} }
else else
{ {
...@@ -147,8 +155,17 @@ SingleOpOperatorRemove(Oid typeOid) ...@@ -147,8 +155,17 @@ SingleOpOperatorRemove(Oid typeOid)
{ {
key[0].sk_attno = attnums[i]; key[0].sk_attno = attnums[i];
scan = heap_beginscan(rel, 0, SnapshotNow, 1, key); scan = heap_beginscan(rel, 0, SnapshotNow, 1, key);
while (HeapTupleIsValid(tup = heap_getnext(scan, 0))) while (HeapTupleIsValid(tup = heap_getnext(scan, 0))) {
/*** This is apparently a routine not in use, but remove ***/
/*** any comments anyways ***/
DeleteComments(tup->t_data->t_oid);
heap_delete(rel, &tup->t_self, NULL); heap_delete(rel, &tup->t_self, NULL);
}
heap_endscan(scan); heap_endscan(scan);
} }
heap_close(rel, RowExclusiveLock); heap_close(rel, RowExclusiveLock);
...@@ -259,6 +276,11 @@ RemoveType(char *typeName) /* type name to be removed */ ...@@ -259,6 +276,11 @@ RemoveType(char *typeName) /* type name to be removed */
} }
typeOid = tup->t_data->t_oid; typeOid = tup->t_data->t_oid;
/*** Delete any comments associated with this type ***/
DeleteComments(typeOid);
heap_delete(relation, &tup->t_self, NULL); heap_delete(relation, &tup->t_self, NULL);
/* Now, Delete the "array of" that type */ /* Now, Delete the "array of" that type */
...@@ -347,6 +369,10 @@ RemoveFunction(char *functionName, /* function name to be removed */ ...@@ -347,6 +369,10 @@ RemoveFunction(char *functionName, /* function name to be removed */
elog(ERROR, "RemoveFunction: function \"%s\" is built-in", functionName); elog(ERROR, "RemoveFunction: function \"%s\" is built-in", functionName);
} }
/*** Delete any comments associated with this function ***/
DeleteComments(tup->t_data->t_oid);
heap_delete(relation, &tup->t_self, NULL); heap_delete(relation, &tup->t_self, NULL);
heap_close(relation, RowExclusiveLock); heap_close(relation, RowExclusiveLock);
...@@ -418,6 +444,11 @@ RemoveAggregate(char *aggName, char *aggType) ...@@ -418,6 +444,11 @@ RemoveAggregate(char *aggName, char *aggType)
aggName); aggName);
} }
} }
/*** Remove any comments related to this aggregate ***/
DeleteComments(tup->t_data->t_oid);
heap_delete(relation, &tup->t_self, NULL); heap_delete(relation, &tup->t_self, NULL);
heap_close(relation, RowExclusiveLock); heap_close(relation, RowExclusiveLock);
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "catalog/pg_language.h" #include "catalog/pg_language.h"
#include "catalog/pg_proc.h" #include "catalog/pg_proc.h"
#include "catalog/pg_trigger.h" #include "catalog/pg_trigger.h"
#include "commands/comment.h"
#include "commands/trigger.h" #include "commands/trigger.h"
#include "executor/executor.h" #include "executor/executor.h"
#include "miscadmin.h" #include "miscadmin.h"
...@@ -297,8 +298,14 @@ DropTrigger(DropTrigStmt *stmt) ...@@ -297,8 +298,14 @@ DropTrigger(DropTrigStmt *stmt)
if (namestrcmp(&(pg_trigger->tgname), stmt->trigname) == 0) if (namestrcmp(&(pg_trigger->tgname), stmt->trigname) == 0)
{ {
/*** Delete any comments associated with this trigger ***/
DeleteComments(tuple->t_data->t_oid);
heap_delete(tgrel, &tuple->t_self, NULL); heap_delete(tgrel, &tuple->t_self, NULL);
tgfound++; tgfound++;
} }
else else
found++; found++;
...@@ -355,9 +362,16 @@ RelationRemoveTriggers(Relation rel) ...@@ -355,9 +362,16 @@ RelationRemoveTriggers(Relation rel)
tgscan = heap_beginscan(tgrel, 0, SnapshotNow, 1, &key); tgscan = heap_beginscan(tgrel, 0, SnapshotNow, 1, &key);
while (HeapTupleIsValid(tup = heap_getnext(tgscan, 0))) while (HeapTupleIsValid(tup = heap_getnext(tgscan, 0))) {
/*** Delete any comments associated with this trigger ***/
DeleteComments(tup->t_data->t_oid);
heap_delete(tgrel, &tup->t_self, NULL); heap_delete(tgrel, &tup->t_self, NULL);
}
heap_endscan(tgscan); heap_endscan(tgscan);
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.109 1999/10/15 01:49:41 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.110 1999/10/26 03:12:34 momjian Exp $
* *
* HISTORY * HISTORY
* AUTHOR DATE MAJOR EVENT * AUTHOR DATE MAJOR EVENT
...@@ -196,7 +196,8 @@ Oid param_type(int t); /* used in parse_expr.c */ ...@@ -196,7 +196,8 @@ Oid param_type(int t); /* used in parse_expr.c */
%type <boolean> opt_cursor %type <boolean> opt_cursor
%type <ival> copy_dirn, def_type, opt_direction, remove_type, %type <ival> copy_dirn, def_type, opt_direction, remove_type,
opt_column, event opt_column, event, comment_type, comment_cl,
comment_ag, comment_fn, comment_op, comment_tg
%type <ival> fetch_how_many %type <ival> fetch_how_many
...@@ -1542,28 +1543,101 @@ TruncateStmt: TRUNCATE TABLE relation_name ...@@ -1542,28 +1543,101 @@ TruncateStmt: TRUNCATE TABLE relation_name
/***************************************************************************** /*****************************************************************************
* *
* QUERY: * The COMMENT ON statement can take different forms based upon the type of
* comment on [ table <relname> | column <relname>.<attribute> ] * the object associated with the comment. The form of the statement is:
* is 'text' *
* COMMENT ON [ [ DATABASE | INDEX | RULE | SEQUENCE | TABLE | TYPE | VIEW ]
* <objname> | AGGREGATE <aggname> <aggtype> | FUNCTION
* <funcname> (arg1, arg2, ...) | OPERATOR <op>
* (leftoperand_typ rightoperand_typ) | TRIGGER <triggername> ON
* <relname> ] IS 'text'
* *
*****************************************************************************/ *****************************************************************************/
CommentStmt: COMMENT ON COLUMN relation_name '.' attr_name IS Sconst CommentStmt: COMMENT ON comment_type name IS Sconst
{ {
CommentStmt *n = makeNode(CommentStmt); CommentStmt *n = makeNode(CommentStmt);
n->relname = $4; n->objtype = $3;
n->attrname = $6; n->objname = $4;
n->objproperty = NULL;
n->objlist = NULL;
n->comment = $6;
$$ = (Node *) n;
}
| COMMENT ON comment_cl relation_name '.' attr_name IS Sconst
{
CommentStmt *n = makeNode(CommentStmt);
n->objtype = $3;
n->objname = $4;
n->objproperty = $6;
n->objlist = NULL;
n->comment = $8; n->comment = $8;
$$ = (Node *) n; $$ = (Node *) n;
} }
| COMMENT ON TABLE relation_name IS Sconst | COMMENT ON comment_ag name aggr_argtype IS Sconst
{ {
CommentStmt *n = makeNode(CommentStmt); CommentStmt *n = makeNode(CommentStmt);
n->relname = $4; n->objtype = $3;
n->attrname = NULL; n->objname = $4;
n->comment = $6; n->objproperty = $5;
n->objlist = NULL;
n->comment = $7;
$$ = (Node *) n; $$ = (Node *) n;
} }
| COMMENT ON comment_fn func_name func_args IS Sconst
{
CommentStmt *n = makeNode(CommentStmt);
n->objtype = $3;
n->objname = $4;
n->objproperty = NULL;
n->objlist = $5;
n->comment = $7;
$$ = (Node *) n;
}
| COMMENT ON comment_op all_Op '(' oper_argtypes ')' IS Sconst
{
CommentStmt *n = makeNode(CommentStmt);
n->objtype = $3;
n->objname = $4;
n->objproperty = NULL;
n->objlist = $6;
n->comment = $9;
$$ = (Node *) n;
}
| COMMENT ON comment_tg name ON relation_name IS Sconst
{
CommentStmt *n = makeNode(CommentStmt);
n->objtype = $3;
n->objname = $4;
n->objproperty = $6;
n->objlist = NULL;
n->comment = $8;
$$ = (Node *) n;
}
;
comment_type: DATABASE { $$ = DATABASE; }
| INDEX { $$ = INDEX; }
| RULE { $$ = RULE; }
| SEQUENCE { $$ = SEQUENCE; }
| TABLE { $$ = TABLE; }
| TYPE_P { $$ = TYPE_P; }
| VIEW { $$ = VIEW; }
;
comment_cl: COLUMN { $$ = COLUMN; }
;
comment_ag: AGGREGATE { $$ = AGGREGATE; }
;
comment_fn: FUNCTION { $$ = FUNCTION; }
;
comment_op: OPERATOR { $$ = OPERATOR; }
;
comment_tg: TRIGGER { $$ = TRIGGER; }
; ;
/***************************************************************************** /*****************************************************************************
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteRemove.c,v 1.29 1999/09/18 19:07:19 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteRemove.c,v 1.30 1999/10/26 03:12:35 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "access/heapam.h" #include "access/heapam.h"
#include "catalog/catname.h" #include "catalog/catname.h"
#include "catalog/pg_rewrite.h" #include "catalog/pg_rewrite.h"
#include "commands/comment.h"
#include "rewrite/rewriteRemove.h" #include "rewrite/rewriteRemove.h"
#include "rewrite/rewriteSupport.h" #include "rewrite/rewriteSupport.h"
#include "utils/syscache.h" #include "utils/syscache.h"
...@@ -119,6 +120,13 @@ RemoveRewriteRule(char *ruleName) ...@@ -119,6 +120,13 @@ RemoveRewriteRule(char *ruleName)
*/ */
prs2_deleteFromRelation(eventRelationOid, ruleId); prs2_deleteFromRelation(eventRelationOid, ruleId);
/*
* Delete any comments associated with this rule
*
*/
DeleteComments(ruleId);
/* /*
* Now delete the tuple... * Now delete the tuple...
*/ */
...@@ -158,9 +166,16 @@ RelationRemoveRules(Oid relid) ...@@ -158,9 +166,16 @@ RelationRemoveRules(Oid relid)
scanDesc = heap_beginscan(RewriteRelation, scanDesc = heap_beginscan(RewriteRelation,
0, SnapshotNow, 1, &scanKeyData); 0, SnapshotNow, 1, &scanKeyData);
while (HeapTupleIsValid(tuple = heap_getnext(scanDesc, 0))) while (HeapTupleIsValid(tuple = heap_getnext(scanDesc, 0))) {
/*** Delete any comments associated with this relation ***/
DeleteComments(tuple->t_data->t_oid);
heap_delete(RewriteRelation, &tuple->t_self, NULL); heap_delete(RewriteRelation, &tuple->t_self, NULL);
}
heap_endscan(scanDesc); heap_endscan(scanDesc);
heap_close(RewriteRelation, RowExclusiveLock); heap_close(RewriteRelation, RowExclusiveLock);
} }
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.70 1999/10/15 01:49:43 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.71 1999/10/26 03:12:36 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "commands/async.h" #include "commands/async.h"
#include "commands/cluster.h" #include "commands/cluster.h"
#include "commands/command.h" #include "commands/command.h"
#include "commands/comment.h"
#include "commands/copy.h" #include "commands/copy.h"
#include "commands/creatinh.h" #include "commands/creatinh.h"
#include "commands/dbcommands.h" #include "commands/dbcommands.h"
...@@ -38,7 +39,6 @@ ...@@ -38,7 +39,6 @@
#include "rewrite/rewriteRemove.h" #include "rewrite/rewriteRemove.h"
#include "tcop/utility.h" #include "tcop/utility.h"
#include "utils/acl.h" #include "utils/acl.h"
#include "utils/acl.h"
#include "utils/ps_status.h" #include "utils/ps_status.h"
#include "utils/syscache.h" #include "utils/syscache.h"
...@@ -242,13 +242,8 @@ ProcessUtility(Node *parsetree, ...@@ -242,13 +242,8 @@ ProcessUtility(Node *parsetree,
PS_SET_STATUS(commandTag = "COMMENT"); PS_SET_STATUS(commandTag = "COMMENT");
CHECK_IF_ABORTED(); CHECK_IF_ABORTED();
CommentObject(statement->objtype, statement->objname,
#ifndef NO_SECURITY statement->objproperty, statement->objlist,
if (!pg_ownercheck(userName, statement->relname, RELNAME))
elog(ERROR, "you do not own class \"%s\"", statement->relname);
#endif
CommentRelation(statement->relname, statement->attrname,
statement->comment); statement->comment);
} }
break; break;
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* *
* Copyright (c) 1994, Regents of the University of California * Copyright (c) 1994, Regents of the University of California
* *
* $Id: heap.h,v 1.23 1999/10/15 01:49:44 momjian Exp $ * $Id: heap.h,v 1.24 1999/10/26 03:12:37 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -25,16 +25,13 @@ extern Oid RelnameFindRelid(char *relname); ...@@ -25,16 +25,13 @@ extern Oid RelnameFindRelid(char *relname);
extern Relation heap_create(char *relname, TupleDesc att, extern Relation heap_create(char *relname, TupleDesc att,
bool isnoname, bool istemp); bool isnoname, bool istemp);
extern Oid heap_create_with_catalog(char *relname, extern Oid heap_create_with_catalog(char *relname, TupleDesc tupdesc,
TupleDesc tupdesc, char relkind, bool istemp); char relkind, bool istemp);
extern void heap_destroy_with_catalog(char *relname); extern void heap_destroy_with_catalog(char *relname);
extern void heap_truncate(char *relname); extern void heap_truncate(char *relname);
extern void heap_destroy(Relation rel); extern void heap_destroy(Relation rel);
extern void CreateComments(Oid object, char *comments);
extern void DeleteComments(Oid object);
extern void AddRelationRawConstraints(Relation rel, extern void AddRelationRawConstraints(Relation rel,
List *rawColDefaults, List *rawColDefaults,
List *rawConstraints); List *rawConstraints);
......
/*-------------------------------------------------------------------------
*
* comment.h
*
* Prototypes for functions in commands/comment.c
*
* Copyright (c) 1999, PostgreSQL Global Development Group
*
*-------------------------------------------------------------------------
*/
#ifndef COMMENT_H
#define COMMENT_H
/*------------------------------------------------------------------
* Function Prototypes --
*
* The following protoypes define the public functions of the comment
* related routines. CreateComments() is used to create/drop a comment
* for any object with a valid oid. DeleteComments() deletes, if any,
* the comments associated with the object. CommentObject() is used to
* create comments to be identified by the specific type.
*------------------------------------------------------------------
*/
void CreateComments(Oid oid, char *comment);
void DeleteComments(Oid oid);
void CommentObject(int objtype, char *objname, char *objproperty,
List *objlist, char *comment);
#endif /* COMMENT_H */
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* *
* Copyright (c) 1994, Regents of the University of California * Copyright (c) 1994, Regents of the University of California
* *
* $Id: creatinh.h,v 1.11 1999/10/15 01:49:46 momjian Exp $ * $Id: creatinh.h,v 1.12 1999/10/26 03:12:38 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -18,6 +18,5 @@ ...@@ -18,6 +18,5 @@
extern void DefineRelation(CreateStmt *stmt, char relkind); extern void DefineRelation(CreateStmt *stmt, char relkind);
extern void RemoveRelation(char *name); extern void RemoveRelation(char *name);
extern void TruncateRelation(char *name); extern void TruncateRelation(char *name);
extern void CommentRelation(char *name, char *attr, char *comment);
#endif /* CREATINH_H */ #endif /* CREATINH_H */
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* *
* Copyright (c) 1994, Regents of the University of California * Copyright (c) 1994, Regents of the University of California
* *
* $Id: parsenodes.h,v 1.85 1999/10/15 01:49:47 momjian Exp $ * $Id: parsenodes.h,v 1.86 1999/10/26 03:12:39 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -317,9 +317,11 @@ typedef struct TruncateStmt ...@@ -317,9 +317,11 @@ typedef struct TruncateStmt
typedef struct CommentStmt typedef struct CommentStmt
{ {
NodeTag type; NodeTag type;
char *relname; /* relation to create/drop comment */ int objtype; /* Object's type */
char *attrname; /* attribute to comment on */ char *objname; /* Name of the object */
char *comment; /* the actual comment */ char *objproperty; /* Property Id (such as column) */
List *objlist; /* Arguments for VAL objects */
char *comment; /* The comment to insert */
} CommentStmt; } CommentStmt;
/* ---------------------- /* ----------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment