|
6 | 6 | * |
7 | 7 | *1999 Jan Wieck |
8 | 8 | * |
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 $ |
10 | 10 | * |
11 | 11 | * ---------- |
12 | 12 | */ |
|
24 | 24 | #include"catalog/pg_operator.h" |
25 | 25 | #include"commands/trigger.h" |
26 | 26 | #include"executor/spi_priv.h" |
| 27 | +#include"miscadmin.h" |
27 | 28 |
|
28 | 29 |
|
29 | 30 | /* ---------- |
@@ -158,6 +159,9 @@ RI_FKey_check(PG_FUNCTION_ARGS) |
158 | 159 | boolisnull; |
159 | 160 | inti; |
160 | 161 | intmatch_type; |
| 162 | +Oidsave_uid; |
| 163 | + |
| 164 | +save_uid=GetUserId(); |
161 | 165 |
|
162 | 166 | ReferentialIntegritySnapshotOverride= true; |
163 | 167 |
|
@@ -252,9 +256,13 @@ RI_FKey_check(PG_FUNCTION_ARGS) |
252 | 256 | if (SPI_connect()!=SPI_OK_CONNECT) |
253 | 257 | elog(NOTICE,"SPI_connect() failed in RI_FKey_check()"); |
254 | 258 |
|
| 259 | +SetUserId(RelationGetForm(pk_rel)->relowner); |
| 260 | + |
255 | 261 | if (SPI_execp(qplan,check_values,check_nulls,1)!=SPI_OK_SELECT) |
256 | 262 | elog(ERROR,"SPI_execp() failed in RI_FKey_check()"); |
257 | 263 |
|
| 264 | +SetUserId(save_uid); |
| 265 | + |
258 | 266 | if (SPI_processed==0) |
259 | 267 | elog(ERROR,"%s referential integrity violation - " |
260 | 268 | "no rows found in %s", |
@@ -435,9 +443,14 @@ RI_FKey_check(PG_FUNCTION_ARGS) |
435 | 443 | * Now check that foreign key exists in PK table |
436 | 444 | * ---------- |
437 | 445 | */ |
| 446 | + |
| 447 | +SetUserId(RelationGetForm(pk_rel)->relowner); |
| 448 | + |
438 | 449 | if (SPI_execp(qplan,check_values,check_nulls,1)!=SPI_OK_SELECT) |
439 | 450 | elog(ERROR,"SPI_execp() failed in RI_FKey_check()"); |
440 | 451 |
|
| 452 | +SetUserId(save_uid); |
| 453 | + |
441 | 454 | if (SPI_processed==0) |
442 | 455 | elog(ERROR,"%s referential integrity violation - " |
443 | 456 | "key referenced from %s not found in %s", |
@@ -508,6 +521,9 @@ RI_FKey_noaction_del(PG_FUNCTION_ARGS) |
508 | 521 | chardel_nulls[RI_MAX_NUMKEYS+1]; |
509 | 522 | boolisnull; |
510 | 523 | inti; |
| 524 | +Oidsave_uid; |
| 525 | + |
| 526 | +save_uid=GetUserId(); |
511 | 527 |
|
512 | 528 | ReferentialIntegritySnapshotOverride= true; |
513 | 529 |
|
@@ -659,9 +675,13 @@ RI_FKey_noaction_del(PG_FUNCTION_ARGS) |
659 | 675 | * Now check for existing references |
660 | 676 | * ---------- |
661 | 677 | */ |
| 678 | +SetUserId(RelationGetForm(pk_rel)->relowner); |
| 679 | + |
662 | 680 | if (SPI_execp(qplan,del_values,del_nulls,1)!=SPI_OK_SELECT) |
663 | 681 | elog(ERROR,"SPI_execp() failed in RI_FKey_noaction_del()"); |
664 | 682 |
|
| 683 | +SetUserId(save_uid); |
| 684 | + |
665 | 685 | if (SPI_processed>0) |
666 | 686 | elog(ERROR,"%s referential integrity violation - " |
667 | 687 | "key in %s still referenced from %s", |
@@ -716,6 +736,9 @@ RI_FKey_noaction_upd(PG_FUNCTION_ARGS) |
716 | 736 | charupd_nulls[RI_MAX_NUMKEYS+1]; |
717 | 737 | boolisnull; |
718 | 738 | inti; |
| 739 | +Oidsave_uid; |
| 740 | + |
| 741 | +save_uid=GetUserId(); |
719 | 742 |
|
720 | 743 | ReferentialIntegritySnapshotOverride= true; |
721 | 744 |
|
@@ -876,9 +899,13 @@ RI_FKey_noaction_upd(PG_FUNCTION_ARGS) |
876 | 899 | * Now check for existing references |
877 | 900 | * ---------- |
878 | 901 | */ |
| 902 | +SetUserId(RelationGetForm(pk_rel)->relowner); |
| 903 | + |
879 | 904 | if (SPI_execp(qplan,upd_values,upd_nulls,1)!=SPI_OK_SELECT) |
880 | 905 | elog(ERROR,"SPI_execp() failed in RI_FKey_noaction_upd()"); |
881 | 906 |
|
| 907 | +SetUserId(save_uid); |
| 908 | + |
882 | 909 | if (SPI_processed>0) |
883 | 910 | elog(ERROR,"%s referential integrity violation - " |
884 | 911 | "key in %s still referenced from %s", |
@@ -1570,6 +1597,9 @@ RI_FKey_restrict_upd(PG_FUNCTION_ARGS) |
1570 | 1597 | charupd_nulls[RI_MAX_NUMKEYS+1]; |
1571 | 1598 | boolisnull; |
1572 | 1599 | inti; |
| 1600 | +Oidsave_uid; |
| 1601 | + |
| 1602 | +save_uid=GetUserId(); |
1573 | 1603 |
|
1574 | 1604 | ReferentialIntegritySnapshotOverride= true; |
1575 | 1605 |
|
@@ -1730,9 +1760,13 @@ RI_FKey_restrict_upd(PG_FUNCTION_ARGS) |
1730 | 1760 | * Now check for existing references |
1731 | 1761 | * ---------- |
1732 | 1762 | */ |
| 1763 | +SetUserId(RelationGetForm(pk_rel)->relowner); |
| 1764 | + |
1733 | 1765 | if (SPI_execp(qplan,upd_values,upd_nulls,1)!=SPI_OK_SELECT) |
1734 | 1766 | elog(ERROR,"SPI_execp() failed in RI_FKey_restrict_upd()"); |
1735 | 1767 |
|
| 1768 | +SetUserId(save_uid); |
| 1769 | + |
1736 | 1770 | if (SPI_processed>0) |
1737 | 1771 | elog(ERROR,"%s referential integrity violation - " |
1738 | 1772 | "key in %s still referenced from %s", |
|