diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2002-04-01 22:36:13 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2002-04-01 22:36:13 +0000 |
commit | 789ddcb5fe0584fd7524db97909ff43cb2ac37f6 (patch) | |
tree | d94e23b6e5606aee2bbe5d5006e6107863daa160 /src/backend/commands/command.c | |
parent | 6a25cd6b26cc5012828119f9c01c93b9d4d46ad7 (diff) | |
download | postgresql-789ddcb5fe0584fd7524db97909ff43cb2ac37f6.tar.gz postgresql-789ddcb5fe0584fd7524db97909ff43cb2ac37f6.zip |
Add tgconstrrelid to stored Trigger structures, make RI trigger functions
depend on this rather than the trigger argument strings to locate the
other relation to test. This makes RI triggers function properly in
the presence of schemas and temp tables. Along the way, fix bogus lack
of locking in RI triggers, handle quoting of names fully correctly,
compute required sizes of query buffers with some semblance of accuracy.
Diffstat (limited to 'src/backend/commands/command.c')
-rw-r--r-- | src/backend/commands/command.c | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/src/backend/commands/command.c b/src/backend/commands/command.c index 9bdeb3c7c7a..44def03fa43 100644 --- a/src/backend/commands/command.c +++ b/src/backend/commands/command.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.170 2002/04/01 04:35:38 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.171 2002/04/01 22:36:09 tgl Exp $ * * NOTES * The PerformAddAttribute() code, like most of the relation @@ -1639,9 +1639,6 @@ AlterTableAddConstraint(Oid myrelid, !isTempNamespace(RelationGetNamespace(rel))) elog(ERROR, "ALTER TABLE / ADD CONSTRAINT: Unable to reference temporary table from permanent table constraint."); - /* Don't need pkrel open anymore, but hold lock */ - heap_close(pkrel, NoLock); - /* * First we check for limited correctness of the * constraint. @@ -1651,34 +1648,30 @@ AlterTableAddConstraint(Oid myrelid, * referenced relation, and that the column datatypes * are comparable. * - * Scan through each tuple, calling the RI_FKey_Match_Ins + * Scan through each tuple, calling RI_FKey_check_ins * (insert trigger) as if that tuple had just been * inserted. If any of those fail, it should * elog(ERROR) and that's that. */ - - trig.tgoid = 0; + MemSet(&trig, 0, sizeof(trig)); + trig.tgoid = InvalidOid; if (fkconstraint->constr_name) trig.tgname = fkconstraint->constr_name; else trig.tgname = "<unknown>"; - trig.tgfoid = 0; - trig.tgtype = 0; trig.tgenabled = TRUE; trig.tgisconstraint = TRUE; - trig.tginitdeferred = FALSE; + trig.tgconstrrelid = RelationGetRelid(pkrel); trig.tgdeferrable = FALSE; + trig.tginitdeferred = FALSE; trig.tgargs = (char **) palloc( sizeof(char *) * (4 + length(fkconstraint->fk_attrs) + length(fkconstraint->pk_attrs))); - if (fkconstraint->constr_name) - trig.tgargs[0] = fkconstraint->constr_name; - else - trig.tgargs[0] = "<unknown>"; - trig.tgargs[1] = pstrdup(RelationGetRelationName(rel)); - trig.tgargs[2] = fkconstraint->pktable->relname; + trig.tgargs[0] = trig.tgname; + trig.tgargs[1] = RelationGetRelationName(rel); + trig.tgargs[2] = RelationGetRelationName(pkrel); trig.tgargs[3] = fkconstraint->match_type; count = 4; foreach(list, fkconstraint->fk_attrs) @@ -1732,6 +1725,9 @@ AlterTableAddConstraint(Oid myrelid, heap_endscan(scan); pfree(trig.tgargs); + + heap_close(pkrel, NoLock); + break; } default: |