Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc0cba9e

Browse files
committed
When the RI triggers lock the PK table, temporarily switch the current user
id to the owner of the PK table, to avoid permission problems.
1 parentf428d05 commitc0cba9e

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

‎src/backend/utils/adt/ri_triggers.c

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
*1999 Jan Wieck
88
*
9-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ri_triggers.c,v 1.16 2000/05/30 00:49:53 momjian Exp $
9+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ri_triggers.c,v 1.17 2000/09/25 22:34:20 petere Exp $
1010
*
1111
* ----------
1212
*/
@@ -24,6 +24,7 @@
2424
#include"catalog/pg_operator.h"
2525
#include"commands/trigger.h"
2626
#include"executor/spi_priv.h"
27+
#include"miscadmin.h"
2728

2829

2930
/* ----------
@@ -158,6 +159,9 @@ RI_FKey_check(PG_FUNCTION_ARGS)
158159
boolisnull;
159160
inti;
160161
intmatch_type;
162+
Oidsave_uid;
163+
164+
save_uid=GetUserId();
161165

162166
ReferentialIntegritySnapshotOverride= true;
163167

@@ -252,9 +256,13 @@ RI_FKey_check(PG_FUNCTION_ARGS)
252256
if (SPI_connect()!=SPI_OK_CONNECT)
253257
elog(NOTICE,"SPI_connect() failed in RI_FKey_check()");
254258

259+
SetUserId(RelationGetForm(pk_rel)->relowner);
260+
255261
if (SPI_execp(qplan,check_values,check_nulls,1)!=SPI_OK_SELECT)
256262
elog(ERROR,"SPI_execp() failed in RI_FKey_check()");
257263

264+
SetUserId(save_uid);
265+
258266
if (SPI_processed==0)
259267
elog(ERROR,"%s referential integrity violation - "
260268
"no rows found in %s",
@@ -435,9 +443,14 @@ RI_FKey_check(PG_FUNCTION_ARGS)
435443
* Now check that foreign key exists in PK table
436444
* ----------
437445
*/
446+
447+
SetUserId(RelationGetForm(pk_rel)->relowner);
448+
438449
if (SPI_execp(qplan,check_values,check_nulls,1)!=SPI_OK_SELECT)
439450
elog(ERROR,"SPI_execp() failed in RI_FKey_check()");
440451

452+
SetUserId(save_uid);
453+
441454
if (SPI_processed==0)
442455
elog(ERROR,"%s referential integrity violation - "
443456
"key referenced from %s not found in %s",
@@ -508,6 +521,9 @@ RI_FKey_noaction_del(PG_FUNCTION_ARGS)
508521
chardel_nulls[RI_MAX_NUMKEYS+1];
509522
boolisnull;
510523
inti;
524+
Oidsave_uid;
525+
526+
save_uid=GetUserId();
511527

512528
ReferentialIntegritySnapshotOverride= true;
513529

@@ -659,9 +675,13 @@ RI_FKey_noaction_del(PG_FUNCTION_ARGS)
659675
* Now check for existing references
660676
* ----------
661677
*/
678+
SetUserId(RelationGetForm(pk_rel)->relowner);
679+
662680
if (SPI_execp(qplan,del_values,del_nulls,1)!=SPI_OK_SELECT)
663681
elog(ERROR,"SPI_execp() failed in RI_FKey_noaction_del()");
664682

683+
SetUserId(save_uid);
684+
665685
if (SPI_processed>0)
666686
elog(ERROR,"%s referential integrity violation - "
667687
"key in %s still referenced from %s",
@@ -716,6 +736,9 @@ RI_FKey_noaction_upd(PG_FUNCTION_ARGS)
716736
charupd_nulls[RI_MAX_NUMKEYS+1];
717737
boolisnull;
718738
inti;
739+
Oidsave_uid;
740+
741+
save_uid=GetUserId();
719742

720743
ReferentialIntegritySnapshotOverride= true;
721744

@@ -876,9 +899,13 @@ RI_FKey_noaction_upd(PG_FUNCTION_ARGS)
876899
* Now check for existing references
877900
* ----------
878901
*/
902+
SetUserId(RelationGetForm(pk_rel)->relowner);
903+
879904
if (SPI_execp(qplan,upd_values,upd_nulls,1)!=SPI_OK_SELECT)
880905
elog(ERROR,"SPI_execp() failed in RI_FKey_noaction_upd()");
881906

907+
SetUserId(save_uid);
908+
882909
if (SPI_processed>0)
883910
elog(ERROR,"%s referential integrity violation - "
884911
"key in %s still referenced from %s",
@@ -1570,6 +1597,9 @@ RI_FKey_restrict_upd(PG_FUNCTION_ARGS)
15701597
charupd_nulls[RI_MAX_NUMKEYS+1];
15711598
boolisnull;
15721599
inti;
1600+
Oidsave_uid;
1601+
1602+
save_uid=GetUserId();
15731603

15741604
ReferentialIntegritySnapshotOverride= true;
15751605

@@ -1730,9 +1760,13 @@ RI_FKey_restrict_upd(PG_FUNCTION_ARGS)
17301760
* Now check for existing references
17311761
* ----------
17321762
*/
1763+
SetUserId(RelationGetForm(pk_rel)->relowner);
1764+
17331765
if (SPI_execp(qplan,upd_values,upd_nulls,1)!=SPI_OK_SELECT)
17341766
elog(ERROR,"SPI_execp() failed in RI_FKey_restrict_upd()");
17351767

1768+
SetUserId(save_uid);
1769+
17361770
if (SPI_processed>0)
17371771
elog(ERROR,"%s referential integrity violation - "
17381772
"key in %s still referenced from %s",

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp