head	1.29;
access;
symbols
	release_4_2:1.29
	aix_ok:1.26
	Version_2_1:1.10
	Version_2:1.8
	C_Demo_1:1.5;
locks; strict;
comment	@ * @;


1.29
date	94.02.15.06.12.01;	author aoki;	state Exp;
branches;
next	1.28;

1.28
date	94.02.07.11.50.46;	author aoki;	state Exp;
branches;
next	1.27;

1.27
date	94.02.01.18.49.15;	author aoki;	state Exp;
branches;
next	1.26;

1.26
date	93.06.23.23.01.31;	author avi;	state Exp;
branches;
next	1.25;

1.25
date	93.06.16.04.46.24;	author aoki;	state Exp;
branches;
next	1.24;

1.24
date	93.06.15.23.35.32;	author avi;	state Exp;
branches;
next	1.23;

1.23
date	93.05.16.18.39.38;	author avi;	state Exp;
branches;
next	1.22;

1.22
date	93.03.26.04.57.52;	author aoki;	state Exp;
branches;
next	1.21;

1.21
date	93.01.05.02.31.00;	author aoki;	state Exp;
branches;
next	1.20;

1.20
date	92.03.09.23.06.28;	author mer;	state Exp;
branches;
next	1.19;

1.19
date	91.12.10.19.43.18;	author mer;	state Exp;
branches;
next	1.18;

1.18
date	91.11.16.22.58.21;	author mer;	state Exp;
branches;
next	1.17;

1.17
date	91.11.10.20.48.46;	author clarsen;	state Exp;
branches;
next	1.16;

1.16
date	91.09.11.10.59.24;	author kemnitz;	state Exp;
branches;
next	1.15;

1.15
date	91.08.18.02.02.42;	author caetta;	state Exp;
branches;
next	1.14;

1.14
date	91.08.16.01.09.36;	author kemnitz;	state Exp;
branches;
next	1.13;

1.13
date	91.05.04.01.48.24;	author kemnitz;	state Exp;
branches;
next	1.12;

1.12
date	91.05.01.02.49.39;	author cimarron;	state Exp;
branches;
next	1.11;

1.11
date	91.04.19.05.34.41;	author kemnitz;	state Exp;
branches;
next	1.10;

1.10
date	90.08.13.20.47.03;	author cimarron;	state Exp;
branches;
next	1.9;

1.9
date	90.08.08.08.10.44;	author cimarron;	state Exp;
branches;
next	1.8;

1.8
date	90.06.09.18.35.33;	author kemnitz;	state Version_2;
branches;
next	1.7;

1.7
date	90.06.07.18.19.45;	author cimarron;	state Exp;
branches;
next	1.6;

1.6
date	89.09.28.17.48.27;	author hirohama;	state Exp;
branches;
next	1.5;

1.5
date	89.09.05.16.47.58;	author mao;	state C_Demo_1;
branches;
next	1.4;

1.4
date	89.08.22.20.37.00;	author hirohama;	state Exp;
branches;
next	1.3;

1.3
date	89.08.09.18.09.58;	author cimarron;	state Exp;
branches;
next	1.2;

1.2
date	89.02.02.16.54.29;	author aoki;	state Stab;
branches;
next	1.1;

1.1
date	89.01.17.05.52.56;	author cimarron;	state Exp;
branches;
next	;


desc
@@


1.29
log
@uninit var
@
text
@/*
 * remove.c --
 *	POSTGRES remove (function | type | operator ) utilty code.
 */

#include "tmp/c.h"

RcsId("$Header: /import/faerie/faerie/aoki/postgres/src/backend/commands/RCS/remove.c,v 1.28 1994/02/07 11:50:46 aoki Exp aoki $");

#include "access/attnum.h"
#include "access/heapam.h"
#include "access/htup.h"
#include "access/skey.h"
#include "access/tqual.h"	/* for NowTimeQual */
#include "catalog/catname.h"
#include "commands/defrem.h"
#include "utils/log.h"

#include "tmp/miscadmin.h"

#include "catalog/pg_aggregate.h"
#include "catalog/pg_language.h"
#include "catalog/pg_operator.h"
#include "catalog/pg_proc.h"
#include "catalog/pg_type.h"
#include "catalog/syscache.h"
#include "parser/catalog_utils.h"

void
RemoveOperator(operatorName, typeName1, typeName2)
	Name 	operatorName;		/* operator name */
	Name 	typeName1;		/* first type name */
	Name 	typeName2;		/* optional second type name */
{
	Relation 	relation;
	HeapScanDesc 	scan;
	HeapTuple 	tup;
	ObjectId	typeId1 = InvalidObjectId;
	ObjectId        typeId2 = InvalidObjectId;
	int 		defined;
	ItemPointerData	itemPointerData;
	Buffer          buffer;
	ScanKeyEntryData	operatorKey[3];
	NameData	user;

	Assert(NameIsValid(operatorName));
	Assert(NameIsValid(typeName1) || NameIsValid(typeName2));

	if (NameIsValid(typeName1)) {
	    typeId1 = TypeGet(typeName1, &defined);
	    if (!ObjectIdIsValid(typeId1)) {
		elog(WARN, "RemoveOperator: type \"%-.*s\" does not exist",
		     sizeof(NameData), typeName1);
		return;
	    }
	}
	
	if (NameIsValid(typeName2)) {
	    typeId2 = TypeGet(typeName2, &defined);
	    if (!ObjectIdIsValid(typeId2)) {
		elog(WARN, "RemoveOperator: type \"%-.*s\" does not exist",
		     sizeof(NameData), typeName2);
		return;
	    }
	}
	
	ScanKeyEntryInitialize(&operatorKey[0], 0x0,
			       OperatorNameAttributeNumber,
			       NameEqualRegProcedure,
			       NameGetDatum(operatorName));

	ScanKeyEntryInitialize(&operatorKey[1], 0x0,
			       OperatorLeftAttributeNumber,
			       ObjectIdEqualRegProcedure,
			       ObjectIdGetDatum(typeId1));

	ScanKeyEntryInitialize(&operatorKey[2], 0x0,
			       OperatorRightAttributeNumber,
			       ObjectIdEqualRegProcedure,
			       ObjectIdGetDatum(typeId2));

	relation = RelationNameOpenHeapRelation(OperatorRelationName);
	scan = RelationBeginHeapScan(relation, 0, NowTimeQual, 3,
				      (ScanKey) operatorKey);
	tup = HeapScanGetNextTuple(scan, 0, &buffer);
	if (HeapTupleIsValid(tup)) {
#ifndef NO_SECURITY
		GetUserName(&user);
		if (!pg_ownercheck(user.data,
				   (char *) ObjectIdGetDatum(tup->t_oid),
				   OPROID))
			elog(WARN, "RemoveOperator: operator \"%-.*s\": permission denied",
			     sizeof(NameData), operatorName);
#endif
		ItemPointerCopy(&tup->t_ctid, &itemPointerData);
		RelationDeleteHeapTuple(relation, &itemPointerData);
	} else {
		if (ObjectIdIsValid(typeId1) && ObjectIdIsValid(typeId2)) {
			elog(WARN, "RemoveOperator: binary operator \"%-.*s\" taking \"%-.*s\" and \"%-.*s\" does not exist",
			     sizeof(NameData), operatorName,
			     sizeof(NameData), typeName1,
			     sizeof(NameData), typeName2);
		} else if (ObjectIdIsValid(typeId1)) {
			elog(WARN, "RemoveOperator: right unary operator \"%-.*s\" taking \"%-.*s\" does not exist",
			     sizeof(NameData), operatorName,
			     sizeof(NameData), typeName1);
		} else {
			elog(WARN, "RemoveOperator: left unary operator \"%-.*s\" taking \"%-.*s\" does not exist",
			     sizeof(NameData), operatorName,
			     sizeof(NameData), typeName2);
		}
	}
	HeapScanEnd(scan);
	RelationCloseHeapRelation(relation);
}

#ifdef NOTYET
/*
 * this stuff is to support removing all reference to a type
 * don't use it  - pma 2/1/94
 */
/*
 *  SingleOpOperatorRemove
 *	Removes all operators that have operands or a result of type 'typeOid'.
 */
static
void
SingleOpOperatorRemove(typeOid)
	OID 	typeOid;
{
	Relation 	rdesc;
	struct skey 	key[3];
	HeapScanDesc 	sdesc;
	HeapTuple 	tup;
	ItemPointerData itemPointerData;
	Buffer 		buffer;
	static 		attnums[3] = { 7, 8, 9 }; /* left, right, return */
	register	i;
	
	ScanKeyEntryInitialize((ScanKeyEntry)&key[0],
			       0, 0, ObjectIdEqualRegProcedure, (Datum)typeOid);
	rdesc = heap_openr(OperatorRelationName->data);
	for (i = 0; i < 3; ++i) {
		key[0].sk_attnum = attnums[i];
		sdesc = heap_beginscan(rdesc, 0, NowTimeQual, 1, key);
		while (PointerIsValid(tup = heap_getnext(sdesc, 0, &buffer))) {
			ItemPointerCopy(&tup->t_ctid, &itemPointerData);   
			/* XXX LOCK not being passed */
			heap_delete(rdesc, &itemPointerData);
		}
		heap_endscan(sdesc);
	}
	heap_close(rdesc);
}

/*
 *  AttributeAndRelationRemove
 *	Removes all entries in the attribute and relation relations
 *	that contain entries of type 'typeOid'.
 *      Currently nothing calls this code, it is untested.
 */
static
void
AttributeAndRelationRemove(typeOid)
	OID 	typeOid;
{
	struct oidlist {
		OID		reloid;
		struct oidlist	*next;
	};
	struct oidlist	*oidptr, *optr;
	Relation 	rdesc;
	struct skey	key[1];
	HeapScanDesc 	sdesc;
	HeapTuple 	tup;
	ItemPointerData	itemPointerData;
	Buffer 		buffer;
	
	/*
	 * Get the oid's of the relations to be removed by scanning the
	 * entire attribute relation.
	 * We don't need to remove the attributes here,
	 * because amdestroy will remove all attributes of the relation.
	 * XXX should check for duplicate relations
	 */

	ScanKeyEntryInitialize((ScanKeyEntry)&key[0],
			       0, 3, ObjectIdEqualRegProcedure, (Datum)typeOid);

	oidptr = (struct oidlist *) palloc(sizeof(*oidptr));
	oidptr->next = NULL;
	optr = oidptr; 
	rdesc = heap_openr(AttributeRelationName->data);
	sdesc = heap_beginscan(rdesc, 0, NowTimeQual, 1, key);
	while (PointerIsValid(tup = heap_getnext(sdesc, 0, &buffer))) {
		ItemPointerCopy(&tup->t_ctid, &itemPointerData);   
		optr->reloid = ((AttributeTupleForm)GETSTRUCT(tup))->attrelid;
		optr->next = (struct oidlist *) palloc(sizeof(*oidptr));     
		optr = optr->next;
        }
	optr->next = NULL;
	heap_endscan(sdesc);
	heap_close(rdesc);
	

	ScanKeyEntryInitialize((ScanKeyEntry) &key[0], 0,
            /*bug fix from prototyping, unknown bug ---^ */
			       ObjectIdAttributeNumber,
			       ObjectIdEqualRegProcedure, (Datum)0);
	optr = oidptr;
	rdesc = heap_openr(RelationRelationName->data);
	while (PointerIsValid((char *) optr->next)) {
		key[0].sk_data = (DATUM) (optr++)->reloid;
		sdesc = heap_beginscan(rdesc, 0, NowTimeQual, 1, key);
		tup = heap_getnext(sdesc, 0, &buffer);
		if (PointerIsValid(tup)) {
			Name	name;

			name = &((RelationTupleForm)GETSTRUCT(tup))->relname;
			RelationNameDestroyHeapRelation(name->data);
		}
	}
	heap_endscan(sdesc);
	heap_close(rdesc);
}
#endif /* NOTYET */

/*
 *  TypeRemove
 *	Removes the type 'typeName' and all attributes and relations that
 *	use it.
 */
void
RemoveType(typeName)
	Name      typeName;             /* type name to be removed */
{
	Relation 	relation;  
	HeapScanDesc 	scan;      
	HeapTuple 	tup;
	ObjectId	typeOid;
	ItemPointerData	itemPointerData;
	Buffer          buffer;
	static ScanKeyEntryData typeKey[1] = {
		{ 0, TypeNameAttributeNumber, NameEqualRegProcedure }
	};
	NameData arrayNameData;
	Name arrayName = & arrayNameData;
	NameData	user;

	Assert(NameIsValid(typeName));
	
#ifndef NO_SECURITY
	GetUserName(&user);
	if (!pg_ownercheck(user.data, typeName->data, TYPNAME))
		elog(WARN, "RemoveType: type \"%-.*s\": permission denied",
		     sizeof(NameData), typeName);
#endif

	relation = RelationNameOpenHeapRelation(TypeRelationName);
	fmgr_info(typeKey[0].procedure, &typeKey[0].func, &typeKey[0].nargs);

	/* Delete the primary type */

	typeKey[0].argument = NameGetDatum(typeName);

	scan = RelationBeginHeapScan(relation, 0, NowTimeQual,
				     1, (ScanKey) typeKey);
	tup = HeapScanGetNextTuple(scan, 0, (Buffer *) 0);
	if (!HeapTupleIsValid(tup)) {
		HeapScanEnd(scan);
		RelationCloseHeapRelation(relation);
		elog(WARN, "RemoveType: type \"%-.*s\" does not exist",
		     sizeof(NameData), typeName);
	}
	typeOid = tup->t_oid;
	ItemPointerCopy(&tup->t_ctid, &itemPointerData);
        RelationDeleteHeapTuple(relation, &itemPointerData);
	HeapScanEnd(scan);

	/* Now, Delete the "array of" that type */

	arrayName->data[0] = '_';
	arrayName->data[1] = '\0';

	strncat(arrayName, typeName, 15);

	typeKey[0].argument = NameGetDatum(arrayName);

	scan = RelationBeginHeapScan(relation, 0, NowTimeQual,
				     1, (ScanKey) typeKey);
	tup = HeapScanGetNextTuple(scan, 0, (Buffer *) 0);

	if (!HeapTupleIsValid(tup))
	{
	    elog(WARN, "RemoveType: type \"%-.*s\": array stub not found",
		 sizeof(NameData), typeName->data);
	}
	typeOid = tup->t_oid;
	ItemPointerCopy(&tup->t_ctid, &itemPointerData);
        RelationDeleteHeapTuple(relation, &itemPointerData);
	HeapScanEnd(scan);

	RelationCloseHeapRelation(relation);
}

void
RemoveFunction(functionName, nargs, argNameList)
	Name 	   functionName;             /* type name to be removed */
        int	   nargs;
        List	   argNameList;
{
	Relation         relation;
	HeapScanDesc         scan;
	HeapTuple        tup;
	Buffer           buffer = InvalidBuffer;
	bool		 bufferUsed = FALSE;
	ObjectId	 argList[8];
	Form_pg_proc	 the_proc;
#ifdef USEPARGS
	ObjectId         oid;
#endif
	ItemPointerData  itemPointerData;
	static ScanKeyEntryData key[3] = {
		{ 0, ProcedureNameAttributeNumber, NameEqualRegProcedure }
	};
	NameData	user;
	NameData	typename;
	int 		i;
	
	Assert(NameIsValid(functionName));

	bzero(argList, 8 * sizeof(ObjectId));
	for (i=0; i<nargs; i++) {
	    (void) namestrcpy(&typename, CString(CAR(argNameList)));
	    argNameList = CDR(argNameList);
	    
	    if (strncmp(typename.data, "any", NAMEDATALEN) == 0)
		argList[i] = 0;
	    else {
		tup = SearchSysCacheTuple(TYPNAME, (char *) &typename,
					  (char *) NULL, (char *) NULL,
					  (char *) NULL);

		if (!HeapTupleIsValid(tup)) {
		    elog(WARN, "RemoveFunction: type \"%-.*s\" not found",
			 sizeof(NameData), &typename);
		}

		argList[i] = tup->t_oid;
	    }
	}

	tup = SearchSysCacheTuple(PRONAME, (char *) functionName,
				  (char *) Int32GetDatum(nargs),
				  (char *) argList, (char *) NULL);
	if (!HeapTupleIsValid(tup))
	        func_error("RemoveFunction", functionName, nargs, argList);

#ifndef NO_SECURITY
	GetUserName(&user);
	if (!pg_func_ownercheck(user.data, (char *) functionName, 
				nargs, argList)) {
		elog(WARN, "RemoveFunction: function \"%-.*s\": permission denied",
		     sizeof(NameData), functionName);
	}
#endif

	key[0].argument = NameGetDatum(functionName);

	fmgr_info(key[0].procedure, &key[0].func, &key[0].nargs);

	relation = RelationNameOpenHeapRelation(ProcedureRelationName);
	scan = RelationBeginHeapScan(relation, 0, NowTimeQual, 1,
		(ScanKey)key);

	do { /* hope this is ok because it's indexed */
	        if (bufferUsed) {
		        ReleaseBuffer(buffer);
			bufferUsed = FALSE;
		}
	        tup = HeapScanGetNextTuple(scan, 0, (Buffer *) &buffer);
		if (!HeapTupleIsValid(tup))
		        break;
		bufferUsed = TRUE;
		the_proc = (Form_pg_proc) GETSTRUCT(tup);
	} while (NameIsEqual(&(the_proc->proname), functionName) &&
		 (the_proc->pronargs != nargs ||
		  !oid8eq(&(the_proc->proargtypes.data[0]), &argList[0])));


	if (!HeapTupleIsValid(tup) || !NameIsEqual(&(the_proc->proname), 
						   functionName))
	        {	
		      HeapScanEnd(scan);
		      RelationCloseHeapRelation(relation);
		      func_error("RemoveFunction", functionName,
				 nargs, argList);
		}

/* ok, function has been found */
#ifdef USEPARGS
	oid = tup->t_oid;
#endif

	if (the_proc->prolang == INTERNALlanguageId)
		elog(WARN, "RemoveFunction: function \"%-.*s\" is built-in",
		     sizeof(NameData), functionName);

	ItemPointerCopy(&tup->t_ctid, &itemPointerData);
        RelationDeleteHeapTuple(relation, &itemPointerData);
	HeapScanEnd(scan);
	RelationCloseHeapRelation(relation);
	
	/*  
	 * Remove associated parameters from PARG catalog
	 *
	 * XXX NOT CURRENTLY DONE
	 */
#ifdef USEPARGS
	ScanKeyEntryInitialize(&typeKey, 0, 1, ObjectIdEqualRegProcedure,
						   ObjectIdGetDatum(oid));
	key[0].argument = NameGetDatum(functionName);
	relation = RelationNameOpenHeapRelation(ProcedureArgumentRelationName);
	scan = RelationBeginHeapScan(relation, 0, NowTimeQual,
				     1, (ScanKey) typeKey);
	tup = HeapScanGetNextTuple(scan, 0, (Buffer *) 0);
	while (PointerIsValid(tup)) {
		ItemPointerCopy(&tup->t_ctid, &itemPointerData);
		RelationDeleteHeapTuple(relation, &itemPointerData);
		tup = HeapScanGetNextTuple(scan, 0, (Buffer *) 0);
	}
	HeapScanEnd(scan);
	RelationCloseHeapRelation(relation);
#endif
}

void
RemoveAggregate(aggName)
	Name	aggName;
{
	Relation 	relation;
	HeapScanDesc	scan;
	HeapTuple	tup;
	Buffer		buffer;
	ItemPointerData	  itemPointerData;
	static ScanKeyEntryData key[3] = {
		{ 0, Anum_pg_aggregate_aggname, NameEqualRegProcedure }
	};

	Assert(NameIsValid(aggName));

#ifndef NO_SECURITY
	/* XXX there's no pg_aggregate.aggowner?? */
#endif

	key[0].argument = NameGetDatum(aggName);

	fmgr_info(key[0].procedure, &key[0].func, &key[0].nargs);
	relation = RelationNameOpenHeapRelation(AggregateRelationName);
	scan = RelationBeginHeapScan(relation, 0, NowTimeQual, 1,
		 (ScanKey)key);
	tup = HeapScanGetNextTuple(scan, 0, (Buffer *) 0);
	if (!HeapTupleIsValid(tup)) {
		HeapScanEnd(scan);
		RelationCloseHeapRelation(relation);
		elog(WARN, "RemoveAggregate: aggregate \"%-.*s\" does not exist",
		     sizeof(NameData), aggName);
	}
	ItemPointerCopy(&tup->t_ctid, &itemPointerData);
	RelationDeleteHeapTuple(relation, &itemPointerData);
	HeapScanEnd(scan);
	RelationCloseHeapRelation(relation);

}
@


1.28
log
@SearchSysCacheTuple called with wrong args
(not enough, not cast right)
name-safing
casting to shut up gcc
@
text
@d8 1
a8 1
RcsId("$Header: /import/faerie/faerie/aoki/postgres/src/backend/commands/RCS/remove.c,v 1.27 1994/02/01 18:49:15 aoki Exp aoki $");
d315 1
a315 1
	Buffer           buffer;
d381 1
a381 1
	        tup = HeapScanGetNextTuple(scan, 0, (Buffer *) 0);
@


1.27
log
@support for unambiguous remove unary operator
@
text
@d8 1
a8 1
RcsId("$Header: /faerie/aoki/postgres/src/backend/commands/RCS/remove.c,v 1.26 1993/06/23 23:01:31 avi Exp aoki $");
d89 3
a91 1
		if (!pg_ownercheck(user.data, (char *) tup->t_oid, OPROID))
d334 1
a334 2
	    strncpy(&typename, CString(CAR(argNameList)),
		    sizeof(NameData));
d337 1
a337 1
	    if (strcmp(&typename, "any") == 0)
d340 3
a342 1
		tup = SearchSysCacheTuple(TYPNAME, &typename, NULL, NULL, NULL);
d353 3
a355 1
	tup = SearchSysCacheTuple(PRONAME, functionName, nargs, argList, NULL);
d386 1
a386 1
	} while (!strcmp(&(the_proc->proname.data[0]), functionName) &&
d391 2
a392 2
	if (!HeapTupleIsValid(tup) || strcmp(&(the_proc->proname.data[0]), 
					     functionName))
@


1.26
log
@changed wildcard to any
@
text
@d8 1
a8 1
RcsId("$Header: /private/src/postgres/src/backend/commands/RCS/remove.c,v 1.25 1993/06/16 04:46:24 aoki Exp avi $");
d38 2
a39 2
	ObjectId	typeId1;
	ObjectId        typeId2;
d47 1
a47 1
	Assert(NameIsValid(typeName1));
d49 3
a51 2
	typeId1 = TypeGet(typeName1, &defined);
	if (!ObjectIdIsValid(typeId1)) {
d55 1
d57 1
a57 2

	typeId2 = InvalidObjectId;
d59 6
a64 6
		typeId2 = TypeGet(typeName2, &defined);
		if (!ObjectIdIsValid(typeId2)) {
			elog(WARN, "RemoveOperator: type \"%-.*s\" does not exist",
			     sizeof(NameData), typeName2);
			return;
		}
d66 1
a66 1

d96 2
a97 2
		if (ObjectIdIsValid(typeId2)) {
			elog(WARN, "RemoveOperator: operator \"%-.*s\" taking \"%-.*s\" and \"%-.*s\" does not exist",
d101 4
d106 1
a106 1
			elog(WARN, "RemoveOperator: operator \"%-.*s\" taking \"%-.*s\" does not exist",
d108 1
a108 1
			     sizeof(NameData), typeName1);
d117 4
d270 1
a270 1
		elog(WARN, "RemoveOperator: type \"%-.*s\" does not exist",
@


1.25
log
@%-*s -> %-.*s
@
text
@d8 1
a8 1
RcsId("$Header: /home2/aoki/postgres/src/backend/commands/RCS/remove.c,v 1.24 1993/06/15 23:35:32 avi Exp aoki $");
d327 1
a327 1
	    if (strcmp(&typename, "wildcard") == 0)
@


1.24
log
@allowed wildcard as argument type in remove function
@
text
@d8 1
a8 1
RcsId("$Header: /private/src/postgres/src/backend/commands/RCS/remove.c,v 1.23 1993/05/16 18:39:38 avi Exp avi $");
d51 1
a51 1
		elog(WARN, "RemoveOperator: type \"%-*s\" does not exist",
d60 1
a60 1
			elog(WARN, "RemoveOperator: type \"%-*s\" does not exist",
d89 1
a89 1
			elog(WARN, "RemoveOperator: operator \"%-*s\": permission denied",
d96 1
a96 1
			elog(WARN, "RemoveOperator: operator \"%-*s\" taking \"%-*s\" and \"%-*s\" does not exist",
d101 1
a101 1
			elog(WARN, "RemoveOperator: operator \"%-*s\" taking \"%-*s\" does not exist",
d244 1
a244 1
		elog(WARN, "RemoveType: type \"%-*s\": permission denied",
d261 1
a261 1
		elog(WARN, "RemoveOperator: type \"%-*s\" does not exist",
d284 1
a284 1
	    elog(WARN, "RemoveType: type \"%-*s\": array stub not found",
d333 1
a333 1
		    elog(WARN, "RemoveFunction: type \"%-*s\" not found",
d349 1
a349 1
		elog(WARN, "RemoveFunction: function \"%-*s\": permission denied",
d392 1
a392 1
		elog(WARN, "RemoveFunction: function \"%-*s\" is built-in",
d452 1
a452 1
		elog(WARN, "RemoveAggregate: aggregate \"%-*s\" does not exist",
@


1.23
log
@RemoveFunction takes two more arguments :
	int nargs	- number of arguments to function to be removed
	List argNameList - names of the argument types
it processes the names to get the type oids, and then looks up
the function with the specified arguments
@
text
@d8 1
a8 1
RcsId("$Header: /private/src/postgres/src/backend/commands/RCS/remove.c,v 1.22 1993/03/26 04:57:52 aoki Exp avi $");
d323 7
a329 3
	        strncpy(&typename, CString(CAR(argNameList)),
			sizeof(NameData));
		argNameList = CDR(argNameList);
d331 6
a336 3
		if (!HeapTupleIsValid(tup))
		        elog(WARN, "RemoveFunction: type \"%-*s\" not found",
			     sizeof(NameData), &typename);
d338 1
@


1.22
log
@oopsie.  type -*%s instead of %-*s ...
@
text
@d8 1
a8 1
RcsId("$Header: /home2/aoki/postgres/src/backend/commands/RCS/remove.c,v 1.21 1993/01/05 02:31:00 aoki Exp aoki $");
d27 1
d296 4
a299 2
RemoveFunction(functionName)
	Name 	functionName;             /* type name to be removed */
d305 3
d316 2
d321 16
d339 2
a340 1
	if (!pg_ownercheck(user.data, (char *) functionName, PRONAME))
d343 1
d353 26
a378 7
	tup = HeapScanGetNextTuple(scan, 0, (Buffer *) 0);
	if (!HeapTupleIsValid(tup)) {	
		HeapScanEnd(scan);
		RelationCloseHeapRelation(relation);
		elog(WARN, "RemoveFunction: function \"%-*s\" does not exist",
		     sizeof(NameData), functionName);
	}
d383 1
a383 1
	if (((Form_pg_proc) GETSTRUCT(tup))->prolang == INTERNALlanguageId)
@


1.21
log
@added security-checking.
@
text
@d8 1
a8 1
RcsId("$Header: /home2/aoki/postgres/src/backend/commands/RCS/remove.c,v 1.20 1992/03/09 23:06:28 mer Exp aoki $");
d95 1
a95 1
			elog(WARN, "RemoveOperator: operator \"%-*s\" taking \"-*%s\" and \"%-*s\" does not exist",
@


1.20
log
@elog(WARN, ...) when array type stub isn't found
@
text
@d8 1
a8 1
RcsId("$Header: /users/mer/pg/src/commands/RCS/remove.c,v 1.19 1991/12/10 19:43:18 mer Exp mer $");
d19 4
a23 1
#include "catalog/pg_aggregate.h"
d26 1
a27 5
static String	Messages[] = {
#define	NonexistantTypeMessage	(Messages[0])
	"Define: type %s nonexistant",
};

d43 1
d50 2
a51 1
		elog(WARN, NonexistantTypeMessage, typeName1);
d59 2
a60 1
			elog(WARN, NonexistantTypeMessage, typeName2);
d85 6
d95 4
a98 2
			elog(WARN, "Remove: operator %s(%s, %s) nonexistant",
				operatorName, typeName1, typeName2);
d100 3
a102 2
			elog(WARN, "Remove: operator %s(%s) nonexistant",
				operatorName, typeName1);
d109 1
d214 1
a215 1

d236 1
d240 7
d260 2
a261 1
		elog(WARN, NonexistantTypeMessage, typeName);
d283 2
a284 1
	    elog(WARN, "Array stub for type %s not found", typeName->data);
d309 1
d313 7
d331 2
a332 1
		elog(WARN, "Remove: function %s nonexistant", functionName);
d337 5
d380 1
a380 1
		{ 0, AggregateNameAttributeNumber, NameEqualRegProcedure }
d384 5
d399 2
a400 1
		elog(WARN, "Remove: aggregate %s nonexistant", aggName);
a407 2


@


1.19
log
@fix core dump with remove operator query
@
text
@d8 1
a8 1
RcsId("$Header: /users/mer/postgres/src/commands/RCS/remove.c,v 1.18 1991/11/16 22:58:21 mer Exp $");
d249 3
a251 1
	strcpy(arrayName, "_");
d260 4
@


1.18
log
@prototypes again
@
text
@d8 1
a8 1
RcsId("$Header: /users/mer/postgres/src/commands/RCS/remove.c,v 1.17 1991/11/10 20:48:46 clarsen Exp mer $");
d43 1
a43 5
	static ScanKeyEntryData	operatorKey[3] = {
		{ 0, OperatorNameAttributeNumber, NameEqualRegProcedure },
		{ 0, OperatorLeftAttributeNumber, ObjectIdEqualRegProcedure },
		{ 0, OperatorRightAttributeNumber, ObjectIdEqualRegProcedure }
	};
d62 15
a76 3
	operatorKey[0].argument = NameGetDatum(operatorName);
	operatorKey[1].argument = ObjectIdGetDatum(typeId1);
	operatorKey[2].argument = ObjectIdGetDatum(typeId2);
@


1.17
log
@prototypes
@
text
@d8 1
a8 1
RcsId("$Header: RCS/remove.c,v 1.16 91/09/11 10:59:24 kemnitz Exp Locker: clarsen $");
d188 1
a188 1
			RelationNameDestroyHeapRelation(name);
@


1.16
log
@fixed bug in "remove type" - names suck.

@
text
@d8 1
a8 1
RcsId("$Header: RCS/remove.c,v 1.15 91/08/18 02:02:42 caetta Exp Locker: kemnitz $");
d108 2
a109 1
	ScanKeyEntryInitialize(&key[0], 0, 0, ObjectIdEqualRegProcedure, typeOid);
d155 2
a156 1
	ScanKeyEntryInitialize(&key[0], 0, 3, ObjectIdEqualRegProcedure, typeOid);
d174 4
a177 2
	ScanKeyEntryInitialize(&key[0], ObjectIdAttributeNumber,
						   ObjectIdEqualRegProcedure, 0);
@


1.15
log
@...and removal of aggregates.
@
text
@d8 1
a8 1
RcsId("$Header: commands/RCS/remove.c,v 1.14 91/08/16 01:09:36 kemnitz Exp Locker: caetta $");
d210 2
a211 1
	Name bb;
d237 2
a238 2
	strcpy(bb, "_");
	strncat(bb, typeName, 15);
d240 1
a240 1
	typeKey[0].argument = NameGetDatum(bb);
@


1.14
log
@remove type now removes "arrays of" that type.
@
text
@d8 1
a8 1
RcsId("$Header: RCS/remove.c,v 1.13 91/05/04 01:48:24 kemnitz Exp Locker: kemnitz $");
d20 1
d314 35
@


1.13
log
@fixed scankey problem that broke remove type and remove function
@
text
@d8 1
a8 1
RcsId("$Header: src/commands/RCS/remove.c,v 1.12 91/05/01 02:49:39 cimarron Exp $");
d209 1
d213 5
d219 1
a219 2
	fmgr_info(typeKey[0].procedure, &typeKey[0].func, &typeKey[0].nargs);
	relation = RelationNameOpenHeapRelation(TypeRelationName);
a231 8
	RelationCloseHeapRelation(relation);
	
	/*
	 * If the type remove was successful, now need to remove all operators
	 * that have one or more operand of this type.  Need a special
	 * version of OperatorRemove that only requires one operand type
	 * to be specified.
	 */
d233 1
a233 3
	/* It was decided to remove only the type, and nothing else.
	 * Hence the following call is removed
         */
d235 15
a249 10
/*	SingleOpOperatorRemove(typeOid);     */
	
	/*
	 * Also remove any attributes of this type.  However, if an
	 * attribute is removed, the relation it is an attribute
	 * of must also be removed.
	 */
#ifdef CASCADINGTYPEDELETE
	AttributeAndRelationRemove(typeOid);
#endif
@


1.12
log
@round II of converting simple functions to macros + code cleaning in general
@
text
@d8 1
a8 1
RcsId("$Header: RCS/remove.c,v 1.11 91/04/19 05:34:41 kemnitz Exp Locker: cimarron $");
d213 1
d264 1
a264 1
	static ScanKeyEntryData functionKey[3] = {
d270 4
a273 1
	functionKey[0].argument = NameGetDatum(functionName);
d276 1
a276 1
		(ScanKey)functionKey);
d299 1
a299 1
	functionKey[0].argument = NameGetDatum(functionName);
d308 1
a308 1
	}                
@


1.11
log
@uses new scankey stuff
@
text
@d8 1
a8 1
RcsId("$Header: RCS/remove.c,v 1.10 90/08/13 20:47:03 cimarron Exp Locker: kemnitz $");
d108 1
a108 1
	rdesc = amopenr(OperatorRelationName->data);
d111 2
a112 2
		sdesc = ambeginscan(rdesc, 0, NowTimeQual, 1, key);
		while (PointerIsValid(tup = amgetnext(sdesc, 0, &buffer))) {
d115 1
a115 1
			amdelete(rdesc, &itemPointerData);
d117 1
a117 1
		amendscan(sdesc);
d119 1
a119 1
	amclose(rdesc);
d158 3
a160 3
	rdesc = amopenr(AttributeRelationName->data);
	sdesc = ambeginscan(rdesc, 0, NowTimeQual, 1, key);
	while (PointerIsValid(tup = amgetnext(sdesc, 0, &buffer))) {
d167 2
a168 2
	amendscan(sdesc);
	amclose(rdesc);
d174 1
a174 1
	rdesc = amopenr(RelationRelationName->data);
d177 2
a178 2
		sdesc = ambeginscan(rdesc, 0, NowTimeQual, 1, key);
		tup = amgetnext(sdesc, 0, &buffer);
d186 2
a187 2
	amendscan(sdesc);
	amclose(rdesc);
@


1.10
log
@added pathnames to include statements
@
text
@d8 1
a8 1
RcsId("$Header: RCS/remove.c,v 1.9 90/08/08 08:10:44 cimarron Exp Locker: cimarron $");
d107 1
a107 3
	key[0].sk_flags  = 0;
	key[0].sk_opr    = ObjectIdEqualRegProcedure;
	key[0].sk_data   = (char *) typeOid;
d152 3
a154 4
	key[0].sk_flags  = 0;
	key[0].sk_attnum = 3;
	key[0].sk_opr    = ObjectIdEqualRegProcedure;
	key[0].sk_data   = (DATUM) typeOid;
d170 3
a172 3
	key[0].sk_flags  = NULL;
	key[0].sk_attnum = ObjectIdAttributeNumber;
	key[0].sk_opr    = ObjectIdEqualRegProcedure;
d293 2
a294 4
	typeKey[0].flags = 0;
	typeKey[0].attributeNumber = 1; /* place an entry in anum.h if ever used */
	typeKey[0].procedure = ObjectIdEqualRegProcedure;
	typeKey[0].argument = ObjectIdGetDatum(oid);
@


1.9
log
@reorganized some header files
@
text
@d6 1
a6 1
#include "c.h"
d8 1
a8 1
RcsId("$Header: RCS/remove.c,v 1.8 90/06/09 18:35:33 kemnitz Version_2 Locker: cimarron $");
d10 8
a17 9
#include "skey.h"
#include "attnum.h"
#include "catname.h"
#include "heapam.h"
#include "htup.h"
#include "log.h"
#include "tqual.h"	/* for NowTimeQual */

#include "defrem.h"
@


1.8
log
@Got rid of datum indirections - replaces with accessor macro calls.
@
text
@d8 1
a8 1
RcsId("$Header: RCS/remove.c,v 1.6 89/09/28 17:48:27 hirohama Exp $");
a10 1
#include "anum.h"
a11 1
#include "cat.h"
a15 1
#include "rproc.h"
d20 3
@


1.7
log
@made changes to simplify header include files
@
text
@d66 3
a68 3
	operatorKey[0].argument.name.value = operatorName;
	operatorKey[1].argument.objectId.value = typeId1;
	operatorKey[2].argument.objectId.value = typeId2;
d216 1
a216 1
	typeKey[0].argument.name.value = typeName;
d273 1
a273 1
	functionKey[0].argument.name.value = functionName;
d300 2
a301 2
	typeKey[0].argument.objectId.value = oid;
	functionKey[0].argument.name.value = functionName;
@


1.6
log
@TimeRange -> TimeQual
@
text
@d8 1
a8 1
RcsId("$Header: RCS/remove.c,v 1.5 89/09/05 16:47:58 mao C_Demo_1 Locker: hirohama $");
d10 1
a10 1
#include "access.h"		/* XXX for "struct skey" */
@


1.5
log
@Working version of C-only demo
@
text
@d8 1
a8 1
RcsId("$Header: RCS/remove.c,v 1.4 89/08/22 20:37:00 hirohama Exp $");
d19 1
a19 1
#include "tqual.h"
d114 1
a114 1
		sdesc = ambeginscan(rdesc, 0, DefaultTimeRange, 1, key);
d163 1
a163 1
	sdesc = ambeginscan(rdesc, 0, DefaultTimeRange, 1, key);
d181 1
a181 1
		sdesc = ambeginscan(rdesc, 0, DefaultTimeRange, 1, key);
@


1.4
log
@lispified version
@
text
@d8 1
a8 1
RcsId("$Header: RCS/remove.c,v 1.3 89/08/09 18:09:58 cimarron Exp Locker: hirohama $");
@


1.3
log
@"retrieve(x=1)"
@
text
@d3 1
a3 1
 *	remove {procedure, operator, type} system commands
d6 5
a10 2
#include <strings.h>
#include "access.h"
d13 1
a14 1
#include "fmgr.h"
d16 1
a16 1
#include "ftup.h"
d18 1
a18 1
#include "syscache.h"
d21 1
a21 1
RcsId("$Header: /usr6/postgres/cimarron/postgres3/src/commands/RCS/remove.c,v 1.2 89/02/02 16:54:29 aoki Stab $");
a22 3
extern           TypeRemove();
extern           OperatorRemove();
extern           ProcedureRemove();
d24 4
d29 5
a33 8
/*
 *  OperatorRemove
 */

OperatorRemove(operatorName, firstTypeName, lastTypeName)
	Name 	operatorName;             /* operator name */
	Name 	firstTypeName;            /* first type name */
	Name 	lastTypeName;             /* last type name  */
d38 2
a39 2
	ObjectId	firstTypeId = InvalidObjectId;
	ObjectId        lastTypeId  = InvalidObjectId;
d44 3
a46 3
		{ 0, OperatorNameAttributeNumber, F_CHAR16EQ },
		{ 0, OperatorLeftAttributeNumber, F_OIDEQ },
		{ 0, OperatorRightAttributeNumber, F_OIDEQ }
d50 1
a50 1
	Assert(PointerIsValid(firstTypeName) || PointerIsValid(lastTypeName));
d52 3
a54 5
	
	firstTypeId = TypeGet(firstTypeName, &defined);
	if (!ObjectIdIsValid(firstTypeId)) {
		elog(WARN, "OperatorRemove: type %s does not exist",
		     firstTypeName);
d58 5
a62 5
	if (PointerIsValid(lastTypeName)) {
		lastTypeId = TypeGet(lastTypeName, &defined);
		if (!ObjectIdIsValid(lastTypeId)) {
			elog(WARN, "OperatorRemove: type %s does not exist",
			     lastTypeName);
d67 2
a68 2
	operatorKey[1].argument.objectId.value = firstTypeId;
	operatorKey[2].argument.objectId.value = lastTypeId;
d78 7
a84 3
		elog(DEBUG,
		     "OperatorRemove: no such operator %s with types %s, %s",
		     operatorName, firstTypeName, lastTypeName);		
a89 1

d94 2
d109 1
a109 1
	key[0].sk_opr    = F_OIDEQ;
d131 2
d157 1
a157 1
	key[0].sk_opr    = F_OIDEQ;
d166 1
a166 1
		optr->reloid = ((struct attribute *) GETSTRUCT(tup))->attrelid;
d175 2
a176 2
	key[0].sk_attnum = T_OID;
	key[0].sk_opr    = F_OIDEQ;
d183 6
a188 3
		if (PointerIsValid(tup))
			amdestroy(((struct relation *)
				   GETSTRUCT(tup))->relname);
d200 2
a201 1
TypeRemove(typeName)
d211 1
a211 1
		{ 0, TypeNameAttributeNumber, F_CHAR16EQ }
d224 1
a224 1
		elog(WARN, "TypeRemove: type %s nonexistant",  typeName);
d255 3
a257 7

/*
 * ProcedureRemove
 *	Removes a procedure.
 */
ProcedureRemove(procedureName)
	Name 	procedureName;             /* type name to be removed */
d267 2
a268 2
	static ScanKeyEntryData procedureKey[3] = {
		{ 0, ProcedureNameAttributeNumber, F_CHAR16EQ }
d271 1
a271 1
	Assert(NameIsValid(procedureName));
d273 1
a273 1
	procedureKey[0].argument.name.value = procedureName;
d275 2
a276 2
	scan = RelationBeginHeapScan(relation, 0, NowTimeQual,
				     1, (ScanKey) procedureKey);
d281 1
a281 2
		elog(WARN, "ProcedureRemove: procedure %s nonexistant",
		     procedureName);
d299 1
a299 1
	typeKey[0].procedure = F_OIDEQ;
d301 1
a301 1
	procedureKey[0].argument.name.value = procedureName;
@


1.2
log
@MERGE WITH OLD TREE
@
text
@d18 1
a18 1
RcsId("$Header: remove.c,v 1.5 88/09/14 14:30:41 aoki Locked $");
d35 1
a35 1
	HeapScan 	scan;
d97 1
a97 1
	HeapScan 	sdesc;
d137 1
a137 1
	HeapScan 	sdesc;
d195 1
a195 1
	HeapScan 	scan;      
d254 1
a254 1
	HeapScan         scan;
@


1.1
log
@Initial revision
@
text
@a0 1

a1 26
 * 
 * POSTGRES Data Base Management System
 * 
 * Copyright (c) 1988 Regents of the University of California
 * 
 * Permission to use, copy, modify, and distribute this software and its
 * documentation for educational, research, and non-profit purposes and
 * without fee is hereby granted, provided that the above copyright
 * notice appear in all copies and that both that copyright notice and
 * this permission notice appear in supporting documentation, and that
 * the name of the University of California not be used in advertising
 * or publicity pertaining to distribution of the software without
 * specific, written prior permission.  Permission to incorporate this
 * software into commercial products can be obtained from the Campus
 * Software Office, 295 Evans Hall, University of California, Berkeley,
 * Ca., 94720 provided only that the the requestor give the University
 * of California a free licence to any derived software for educational
 * and research purposes.  The University of California makes no
 * representations about the suitability of this software for any
 * purpose.  It is provided "as is" without express or implied warranty.
 * 
 */



/*
d18 1
a18 1
RcsId("$Header: remove.c,v 1.1 88/11/11 16:42:23 postgres Exp $");
@
