mirror of
https://github.com/postgres/postgres.git
synced 2025-04-22 23:02:54 +03:00
Move renametrig() from tablecmds.c to trigger.c --- if we're going to
divide backend/commands by object type, let's try to pay at least minimal attention to respecting that structure, eh? Also reorder the contents of tablecmds.c; it seems odd to me to put ALTER commands before creation/deletion commands.
This commit is contained in:
parent
e90dbd27b1
commit
7de307f96c
File diff suppressed because it is too large
Load Diff
@ -7,7 +7,7 @@
|
|||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/commands/trigger.c,v 1.114 2002/04/19 16:36:08 tgl Exp $
|
* $Header: /cvsroot/pgsql/src/backend/commands/trigger.c,v 1.115 2002/04/26 19:29:47 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -503,6 +503,123 @@ RelationRemoveTriggers(Relation rel)
|
|||||||
heap_close(tgrel, RowExclusiveLock);
|
heap_close(tgrel, RowExclusiveLock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* renametrig - changes the name of a trigger on a relation
|
||||||
|
*
|
||||||
|
* trigger name is changed in trigger catalog.
|
||||||
|
* No record of the previous name is kept.
|
||||||
|
*
|
||||||
|
* get proper relrelation from relation catalog (if not arg)
|
||||||
|
* scan trigger catalog
|
||||||
|
* for name conflict (within rel)
|
||||||
|
* for original trigger (if not arg)
|
||||||
|
* modify tgname in trigger tuple
|
||||||
|
* insert modified trigger in trigger catalog
|
||||||
|
* delete original trigger from trigger catalog
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
renametrig(Oid relid,
|
||||||
|
const char *oldname,
|
||||||
|
const char *newname)
|
||||||
|
{
|
||||||
|
Relation targetrel;
|
||||||
|
Relation tgrel;
|
||||||
|
HeapTuple tuple;
|
||||||
|
SysScanDesc tgscan;
|
||||||
|
ScanKeyData key;
|
||||||
|
bool found = FALSE;
|
||||||
|
Relation idescs[Num_pg_trigger_indices];
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Grab an exclusive lock on the target table, which we will NOT
|
||||||
|
* release until end of transaction.
|
||||||
|
*/
|
||||||
|
targetrel = heap_open(relid, AccessExclusiveLock);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Scan pg_trigger twice for existing triggers on relation. We do this in
|
||||||
|
* order to ensure a trigger does not exist with newname (The unique index
|
||||||
|
* on tgrelid/tgname would complain anyway) and to ensure a trigger does
|
||||||
|
* exist with oldname.
|
||||||
|
*
|
||||||
|
* NOTE that this is cool only because we have AccessExclusiveLock on the
|
||||||
|
* relation, so the trigger set won't be changing underneath us.
|
||||||
|
*/
|
||||||
|
tgrel = heap_openr(TriggerRelationName, RowExclusiveLock);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* First pass -- look for name conflict
|
||||||
|
*/
|
||||||
|
ScanKeyEntryInitialize(&key, 0,
|
||||||
|
Anum_pg_trigger_tgrelid,
|
||||||
|
F_OIDEQ,
|
||||||
|
ObjectIdGetDatum(relid));
|
||||||
|
tgscan = systable_beginscan(tgrel, TriggerRelidNameIndex, true,
|
||||||
|
SnapshotNow, 1, &key);
|
||||||
|
while (HeapTupleIsValid(tuple = systable_getnext(tgscan)))
|
||||||
|
{
|
||||||
|
Form_pg_trigger pg_trigger = (Form_pg_trigger) GETSTRUCT(tuple);
|
||||||
|
|
||||||
|
if (namestrcmp(&(pg_trigger->tgname), newname) == 0)
|
||||||
|
elog(ERROR, "renametrig: trigger %s already defined on relation %s",
|
||||||
|
newname, RelationGetRelationName(targetrel));
|
||||||
|
}
|
||||||
|
systable_endscan(tgscan);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Second pass -- look for trigger existing with oldname and update
|
||||||
|
*/
|
||||||
|
ScanKeyEntryInitialize(&key, 0,
|
||||||
|
Anum_pg_trigger_tgrelid,
|
||||||
|
F_OIDEQ,
|
||||||
|
ObjectIdGetDatum(relid));
|
||||||
|
tgscan = systable_beginscan(tgrel, TriggerRelidNameIndex, true,
|
||||||
|
SnapshotNow, 1, &key);
|
||||||
|
while (HeapTupleIsValid(tuple = systable_getnext(tgscan)))
|
||||||
|
{
|
||||||
|
Form_pg_trigger pg_trigger = (Form_pg_trigger) GETSTRUCT(tuple);
|
||||||
|
|
||||||
|
if (namestrcmp(&(pg_trigger->tgname), oldname) == 0)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Update pg_trigger tuple with new tgname.
|
||||||
|
* (Scribbling on tuple is OK because it's a copy...)
|
||||||
|
*/
|
||||||
|
namestrcpy(&(pg_trigger->tgname), newname);
|
||||||
|
simple_heap_update(tgrel, &tuple->t_self, tuple);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* keep system catalog indices current
|
||||||
|
*/
|
||||||
|
CatalogOpenIndices(Num_pg_trigger_indices, Name_pg_trigger_indices, idescs);
|
||||||
|
CatalogIndexInsert(idescs, Num_pg_trigger_indices, tgrel, tuple);
|
||||||
|
CatalogCloseIndices(Num_pg_trigger_indices, idescs);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Invalidate relation's relcache entry so that other
|
||||||
|
* backends (and this one too!) are sent SI message to make them
|
||||||
|
* rebuild relcache entries.
|
||||||
|
*/
|
||||||
|
CacheInvalidateRelcache(relid);
|
||||||
|
|
||||||
|
found = TRUE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
systable_endscan(tgscan);
|
||||||
|
|
||||||
|
heap_close(tgrel, RowExclusiveLock);
|
||||||
|
|
||||||
|
if (!found)
|
||||||
|
elog(ERROR, "renametrig: trigger %s not defined on relation %s",
|
||||||
|
oldname, RelationGetRelationName(targetrel));
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Close rel, but keep exclusive lock!
|
||||||
|
*/
|
||||||
|
heap_close(targetrel, NoLock);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Build trigger data to attach to the given relcache entry.
|
* Build trigger data to attach to the given relcache entry.
|
||||||
*
|
*
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
|
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* $Header: /cvsroot/pgsql/src/backend/commands/user.c,v 1.96 2002/04/18 21:16:16 tgl Exp $
|
* $Header: /cvsroot/pgsql/src/backend/commands/user.c,v 1.97 2002/04/26 19:29:47 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -646,7 +646,7 @@ CreateUser(CreateUserStmt *stmt)
|
|||||||
/*
|
/*
|
||||||
* ALTER USER
|
* ALTER USER
|
||||||
*/
|
*/
|
||||||
extern void
|
void
|
||||||
AlterUser(AlterUserStmt *stmt)
|
AlterUser(AlterUserStmt *stmt)
|
||||||
{
|
{
|
||||||
Datum new_record[Natts_pg_shadow];
|
Datum new_record[Natts_pg_shadow];
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
|
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* $Id: tablecmds.h,v 1.2 2002/04/24 02:48:55 momjian Exp $
|
* $Id: tablecmds.h,v 1.3 2002/04/26 19:29:47 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -61,8 +61,4 @@ extern void renameatt(Oid relid,
|
|||||||
extern void renamerel(Oid relid,
|
extern void renamerel(Oid relid,
|
||||||
const char *newrelname);
|
const char *newrelname);
|
||||||
|
|
||||||
extern void renametrig(Oid relid,
|
|
||||||
const char *oldname,
|
|
||||||
const char *newname);
|
|
||||||
|
|
||||||
#endif /* TABLECMDS_H */
|
#endif /* TABLECMDS_H */
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
|
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* $Id: trigger.h,v 1.34 2002/04/01 22:36:13 tgl Exp $
|
* $Id: trigger.h,v 1.35 2002/04/26 19:29:47 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -105,6 +105,8 @@ extern void CreateTrigger(CreateTrigStmt *stmt);
|
|||||||
extern void DropTrigger(Oid relid, const char *trigname);
|
extern void DropTrigger(Oid relid, const char *trigname);
|
||||||
extern void RelationRemoveTriggers(Relation rel);
|
extern void RelationRemoveTriggers(Relation rel);
|
||||||
|
|
||||||
|
extern void renametrig(Oid relid, const char *oldname, const char *newname);
|
||||||
|
|
||||||
extern void RelationBuildTriggers(Relation relation);
|
extern void RelationBuildTriggers(Relation relation);
|
||||||
|
|
||||||
extern void FreeTriggerDesc(TriggerDesc *trigdesc);
|
extern void FreeTriggerDesc(TriggerDesc *trigdesc);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user