* Portions Copyright (c) 2000-2001, PostgreSQL Global Development Group
* Copyright 1999 Jan Wieck
*
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/ri_triggers.c,v 1.23 2001/03/22 06:16:17 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/ri_triggers.c,v 1.24 2001/05/07 19:57:24 petere Exp $
*
* ----------
*/
char del_nulls[RI_MAX_NUMKEYS + 1];
bool isnull;
int i;
+ Oid save_uid;
+ Oid fk_owner;
ReferentialIntegritySnapshotOverride = true;
* tuple.
*/
fk_rel = heap_openr(tgargs[RI_FK_RELNAME_ARGNO], NoLock);
+ fk_owner = RelationGetForm(fk_rel)->relowner;
pk_rel = trigdata->tg_relation;
old_row = trigdata->tg_trigtuple;
/*
* Now delete constraint
*/
+ save_uid = GetUserId();
+ SetUserId(fk_owner);
+
if (SPI_execp(qplan, del_values, del_nulls, 0) != SPI_OK_DELETE)
elog(ERROR, "SPI_execp() failed in RI_FKey_cascade_del()");
+ SetUserId(save_uid);
+
if (SPI_finish() != SPI_OK_FINISH)
elog(NOTICE, "SPI_finish() failed in RI_FKey_cascade_del()");
bool isnull;
int i;
int j;
+ Oid save_uid;
+ Oid fk_owner;
ReferentialIntegritySnapshotOverride = true;
* and old tuple.
*/
fk_rel = heap_openr(tgargs[RI_FK_RELNAME_ARGNO], NoLock);
+ fk_owner = RelationGetForm(fk_rel)->relowner;
pk_rel = trigdata->tg_relation;
new_row = trigdata->tg_newtuple;
old_row = trigdata->tg_trigtuple;
/*
* Now update the existing references
*/
+ save_uid = GetUserId();
+ SetUserId(fk_owner);
+
if (SPI_execp(qplan, upd_values, upd_nulls, 0) != SPI_OK_UPDATE)
elog(ERROR, "SPI_execp() failed in RI_FKey_cascade_upd()");
+ SetUserId(save_uid);
+
if (SPI_finish() != SPI_OK_FINISH)
elog(NOTICE, "SPI_finish() failed in RI_FKey_cascade_upd()");
char del_nulls[RI_MAX_NUMKEYS + 1];
bool isnull;
int i;
+ Oid save_uid;
+ Oid fk_owner;
ReferentialIntegritySnapshotOverride = true;
* tuple.
*/
fk_rel = heap_openr(tgargs[RI_FK_RELNAME_ARGNO], NoLock);
+ fk_owner = RelationGetForm(fk_rel)->relowner;
pk_rel = trigdata->tg_relation;
old_row = trigdata->tg_trigtuple;
/*
* Now check for existing references
*/
+ save_uid = GetUserId();
+ SetUserId(fk_owner);
+
if (SPI_execp(qplan, del_values, del_nulls, 1) != SPI_OK_SELECT)
elog(ERROR, "SPI_execp() failed in RI_FKey_restrict_del()");
+ SetUserId(save_uid);
+
if (SPI_processed > 0)
elog(ERROR, "%s referential integrity violation - "
"key in %s still referenced from %s",
bool isnull;
int i;
Oid save_uid;
-
- save_uid = GetUserId();
+ Oid fk_owner;
ReferentialIntegritySnapshotOverride = true;
* and old tuple.
*/
fk_rel = heap_openr(tgargs[RI_FK_RELNAME_ARGNO], NoLock);
+ fk_owner = RelationGetForm(fk_rel)->relowner;
pk_rel = trigdata->tg_relation;
new_row = trigdata->tg_newtuple;
old_row = trigdata->tg_trigtuple;
/*
* Now check for existing references
*/
+ save_uid = GetUserId();
+ SetUserId(fk_owner);
+
SetUserId(RelationGetForm(pk_rel)->relowner);
if (SPI_execp(qplan, upd_values, upd_nulls, 1) != SPI_OK_SELECT)
char upd_nulls[RI_MAX_NUMKEYS + 1];
bool isnull;
int i;
+ Oid save_uid;
+ Oid fk_owner;
ReferentialIntegritySnapshotOverride = true;
* tuple.
*/
fk_rel = heap_openr(tgargs[RI_FK_RELNAME_ARGNO], NoLock);
+ fk_owner = RelationGetForm(fk_rel)->relowner;
pk_rel = trigdata->tg_relation;
old_row = trigdata->tg_trigtuple;
/*
* Now update the existing references
*/
+ save_uid = GetUserId();
+ SetUserId(fk_owner);
+
if (SPI_execp(qplan, upd_values, upd_nulls, 0) != SPI_OK_UPDATE)
elog(ERROR, "SPI_execp() failed in RI_FKey_setnull_del()");
+ SetUserId(save_uid);
+
if (SPI_finish() != SPI_OK_FINISH)
elog(NOTICE, "SPI_finish() failed in RI_FKey_setnull_del()");
int i;
int match_type;
bool use_cached_query;
+ Oid save_uid;
+ Oid fk_owner;
ReferentialIntegritySnapshotOverride = true;
* tuple.
*/
fk_rel = heap_openr(tgargs[RI_FK_RELNAME_ARGNO], NoLock);
+ fk_owner = RelationGetForm(fk_rel)->relowner;
pk_rel = trigdata->tg_relation;
new_row = trigdata->tg_newtuple;
old_row = trigdata->tg_trigtuple;
/*
* Now update the existing references
*/
+ save_uid = GetUserId();
+ SetUserId(fk_owner);
+
if (SPI_execp(qplan, upd_values, upd_nulls, 0) != SPI_OK_UPDATE)
elog(ERROR, "SPI_execp() failed in RI_FKey_setnull_upd()");
+ SetUserId(save_uid);
+
if (SPI_finish() != SPI_OK_FINISH)
elog(NOTICE, "SPI_finish() failed in RI_FKey_setnull_upd()");
char upd_nulls[RI_MAX_NUMKEYS + 1];
bool isnull;
int i;
+ Oid save_uid;
+ Oid fk_owner;
ReferentialIntegritySnapshotOverride = true;
* tuple.
*/
fk_rel = heap_openr(tgargs[RI_FK_RELNAME_ARGNO], NoLock);
+ fk_owner = RelationGetForm(fk_rel)->relowner;
pk_rel = trigdata->tg_relation;
old_row = trigdata->tg_trigtuple;
/*
* Now update the existing references
*/
+ save_uid = GetUserId();
+ SetUserId(fk_owner);
+
if (SPI_execp(qplan, upd_values, upd_nulls, 0) != SPI_OK_UPDATE)
elog(ERROR, "SPI_execp() failed in RI_FKey_setdefault_del()");
+ SetUserId(save_uid);
+
if (SPI_finish() != SPI_OK_FINISH)
elog(NOTICE, "SPI_finish() failed in RI_FKey_setdefault_del()");
bool isnull;
int i;
int match_type;
+ Oid save_uid;
+ Oid fk_owner;
ReferentialIntegritySnapshotOverride = true;
* tuple.
*/
fk_rel = heap_openr(tgargs[RI_FK_RELNAME_ARGNO], NoLock);
+ fk_owner = RelationGetForm(fk_rel)->relowner;
pk_rel = trigdata->tg_relation;
new_row = trigdata->tg_newtuple;
old_row = trigdata->tg_trigtuple;
/*
* Now update the existing references
*/
+ save_uid = GetUserId();
+ SetUserId(fk_owner);
+
if (SPI_execp(qplan, upd_values, upd_nulls, 0) != SPI_OK_UPDATE)
elog(ERROR, "SPI_execp() failed in RI_FKey_setdefault_upd()");
+ SetUserId(save_uid);
+
if (SPI_finish() != SPI_OK_FINISH)
elog(NOTICE, "SPI_finish() failed in RI_FKey_setdefault_upd()");