Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
465cf168
Commit
465cf168
authored
May 07, 2001
by
Peter Eisentraut
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix remaining RI permission problems (cascaded update/delete, restrict,
set null/default).
parent
232724af
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
62 additions
and
3 deletions
+62
-3
src/backend/utils/adt/ri_triggers.c
src/backend/utils/adt/ri_triggers.c
+62
-3
No files found.
src/backend/utils/adt/ri_triggers.c
View file @
465cf168
...
@@ -18,7 +18,7 @@
...
@@ -18,7 +18,7 @@
* Portions Copyright (c) 2000-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 2000-2001, PostgreSQL Global Development Group
* Copyright 1999 Jan Wieck
* Copyright 1999 Jan Wieck
*
*
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ri_triggers.c,v 1.2
3 2001/03/22 06:16:17 momjian
Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ri_triggers.c,v 1.2
4 2001/05/07 19:57:24 petere
Exp $
*
*
* ----------
* ----------
*/
*/
...
@@ -941,6 +941,8 @@ RI_FKey_cascade_del(PG_FUNCTION_ARGS)
...
@@ -941,6 +941,8 @@ RI_FKey_cascade_del(PG_FUNCTION_ARGS)
char
del_nulls
[
RI_MAX_NUMKEYS
+
1
];
char
del_nulls
[
RI_MAX_NUMKEYS
+
1
];
bool
isnull
;
bool
isnull
;
int
i
;
int
i
;
Oid
save_uid
;
Oid
fk_owner
;
ReferentialIntegritySnapshotOverride
=
true
;
ReferentialIntegritySnapshotOverride
=
true
;
...
@@ -978,6 +980,7 @@ RI_FKey_cascade_del(PG_FUNCTION_ARGS)
...
@@ -978,6 +980,7 @@ RI_FKey_cascade_del(PG_FUNCTION_ARGS)
* tuple.
* tuple.
*/
*/
fk_rel
=
heap_openr
(
tgargs
[
RI_FK_RELNAME_ARGNO
],
NoLock
);
fk_rel
=
heap_openr
(
tgargs
[
RI_FK_RELNAME_ARGNO
],
NoLock
);
fk_owner
=
RelationGetForm
(
fk_rel
)
->
relowner
;
pk_rel
=
trigdata
->
tg_relation
;
pk_rel
=
trigdata
->
tg_relation
;
old_row
=
trigdata
->
tg_trigtuple
;
old_row
=
trigdata
->
tg_trigtuple
;
...
@@ -1081,9 +1084,14 @@ RI_FKey_cascade_del(PG_FUNCTION_ARGS)
...
@@ -1081,9 +1084,14 @@ RI_FKey_cascade_del(PG_FUNCTION_ARGS)
/*
/*
* Now delete constraint
* Now delete constraint
*/
*/
save_uid
=
GetUserId
();
SetUserId
(
fk_owner
);
if
(
SPI_execp
(
qplan
,
del_values
,
del_nulls
,
0
)
!=
SPI_OK_DELETE
)
if
(
SPI_execp
(
qplan
,
del_values
,
del_nulls
,
0
)
!=
SPI_OK_DELETE
)
elog
(
ERROR
,
"SPI_execp() failed in RI_FKey_cascade_del()"
);
elog
(
ERROR
,
"SPI_execp() failed in RI_FKey_cascade_del()"
);
SetUserId
(
save_uid
);
if
(
SPI_finish
()
!=
SPI_OK_FINISH
)
if
(
SPI_finish
()
!=
SPI_OK_FINISH
)
elog
(
NOTICE
,
"SPI_finish() failed in RI_FKey_cascade_del()"
);
elog
(
NOTICE
,
"SPI_finish() failed in RI_FKey_cascade_del()"
);
...
@@ -1128,6 +1136,8 @@ RI_FKey_cascade_upd(PG_FUNCTION_ARGS)
...
@@ -1128,6 +1136,8 @@ RI_FKey_cascade_upd(PG_FUNCTION_ARGS)
bool
isnull
;
bool
isnull
;
int
i
;
int
i
;
int
j
;
int
j
;
Oid
save_uid
;
Oid
fk_owner
;
ReferentialIntegritySnapshotOverride
=
true
;
ReferentialIntegritySnapshotOverride
=
true
;
...
@@ -1165,6 +1175,7 @@ RI_FKey_cascade_upd(PG_FUNCTION_ARGS)
...
@@ -1165,6 +1175,7 @@ RI_FKey_cascade_upd(PG_FUNCTION_ARGS)
* and old tuple.
* and old tuple.
*/
*/
fk_rel
=
heap_openr
(
tgargs
[
RI_FK_RELNAME_ARGNO
],
NoLock
);
fk_rel
=
heap_openr
(
tgargs
[
RI_FK_RELNAME_ARGNO
],
NoLock
);
fk_owner
=
RelationGetForm
(
fk_rel
)
->
relowner
;
pk_rel
=
trigdata
->
tg_relation
;
pk_rel
=
trigdata
->
tg_relation
;
new_row
=
trigdata
->
tg_newtuple
;
new_row
=
trigdata
->
tg_newtuple
;
old_row
=
trigdata
->
tg_trigtuple
;
old_row
=
trigdata
->
tg_trigtuple
;
...
@@ -1297,9 +1308,14 @@ RI_FKey_cascade_upd(PG_FUNCTION_ARGS)
...
@@ -1297,9 +1308,14 @@ RI_FKey_cascade_upd(PG_FUNCTION_ARGS)
/*
/*
* Now update the existing references
* Now update the existing references
*/
*/
save_uid
=
GetUserId
();
SetUserId
(
fk_owner
);
if
(
SPI_execp
(
qplan
,
upd_values
,
upd_nulls
,
0
)
!=
SPI_OK_UPDATE
)
if
(
SPI_execp
(
qplan
,
upd_values
,
upd_nulls
,
0
)
!=
SPI_OK_UPDATE
)
elog
(
ERROR
,
"SPI_execp() failed in RI_FKey_cascade_upd()"
);
elog
(
ERROR
,
"SPI_execp() failed in RI_FKey_cascade_upd()"
);
SetUserId
(
save_uid
);
if
(
SPI_finish
()
!=
SPI_OK_FINISH
)
if
(
SPI_finish
()
!=
SPI_OK_FINISH
)
elog
(
NOTICE
,
"SPI_finish() failed in RI_FKey_cascade_upd()"
);
elog
(
NOTICE
,
"SPI_finish() failed in RI_FKey_cascade_upd()"
);
...
@@ -1349,6 +1365,8 @@ RI_FKey_restrict_del(PG_FUNCTION_ARGS)
...
@@ -1349,6 +1365,8 @@ RI_FKey_restrict_del(PG_FUNCTION_ARGS)
char
del_nulls
[
RI_MAX_NUMKEYS
+
1
];
char
del_nulls
[
RI_MAX_NUMKEYS
+
1
];
bool
isnull
;
bool
isnull
;
int
i
;
int
i
;
Oid
save_uid
;
Oid
fk_owner
;
ReferentialIntegritySnapshotOverride
=
true
;
ReferentialIntegritySnapshotOverride
=
true
;
...
@@ -1386,6 +1404,7 @@ RI_FKey_restrict_del(PG_FUNCTION_ARGS)
...
@@ -1386,6 +1404,7 @@ RI_FKey_restrict_del(PG_FUNCTION_ARGS)
* tuple.
* tuple.
*/
*/
fk_rel
=
heap_openr
(
tgargs
[
RI_FK_RELNAME_ARGNO
],
NoLock
);
fk_rel
=
heap_openr
(
tgargs
[
RI_FK_RELNAME_ARGNO
],
NoLock
);
fk_owner
=
RelationGetForm
(
fk_rel
)
->
relowner
;
pk_rel
=
trigdata
->
tg_relation
;
pk_rel
=
trigdata
->
tg_relation
;
old_row
=
trigdata
->
tg_trigtuple
;
old_row
=
trigdata
->
tg_trigtuple
;
...
@@ -1493,9 +1512,14 @@ RI_FKey_restrict_del(PG_FUNCTION_ARGS)
...
@@ -1493,9 +1512,14 @@ RI_FKey_restrict_del(PG_FUNCTION_ARGS)
/*
/*
* Now check for existing references
* Now check for existing references
*/
*/
save_uid
=
GetUserId
();
SetUserId
(
fk_owner
);
if
(
SPI_execp
(
qplan
,
del_values
,
del_nulls
,
1
)
!=
SPI_OK_SELECT
)
if
(
SPI_execp
(
qplan
,
del_values
,
del_nulls
,
1
)
!=
SPI_OK_SELECT
)
elog
(
ERROR
,
"SPI_execp() failed in RI_FKey_restrict_del()"
);
elog
(
ERROR
,
"SPI_execp() failed in RI_FKey_restrict_del()"
);
SetUserId
(
save_uid
);
if
(
SPI_processed
>
0
)
if
(
SPI_processed
>
0
)
elog
(
ERROR
,
"%s referential integrity violation - "
elog
(
ERROR
,
"%s referential integrity violation - "
"key in %s still referenced from %s"
,
"key in %s still referenced from %s"
,
...
@@ -1554,8 +1578,7 @@ RI_FKey_restrict_upd(PG_FUNCTION_ARGS)
...
@@ -1554,8 +1578,7 @@ RI_FKey_restrict_upd(PG_FUNCTION_ARGS)
bool
isnull
;
bool
isnull
;
int
i
;
int
i
;
Oid
save_uid
;
Oid
save_uid
;
Oid
fk_owner
;
save_uid
=
GetUserId
();
ReferentialIntegritySnapshotOverride
=
true
;
ReferentialIntegritySnapshotOverride
=
true
;
...
@@ -1593,6 +1616,7 @@ RI_FKey_restrict_upd(PG_FUNCTION_ARGS)
...
@@ -1593,6 +1616,7 @@ RI_FKey_restrict_upd(PG_FUNCTION_ARGS)
* and old tuple.
* and old tuple.
*/
*/
fk_rel
=
heap_openr
(
tgargs
[
RI_FK_RELNAME_ARGNO
],
NoLock
);
fk_rel
=
heap_openr
(
tgargs
[
RI_FK_RELNAME_ARGNO
],
NoLock
);
fk_owner
=
RelationGetForm
(
fk_rel
)
->
relowner
;
pk_rel
=
trigdata
->
tg_relation
;
pk_rel
=
trigdata
->
tg_relation
;
new_row
=
trigdata
->
tg_newtuple
;
new_row
=
trigdata
->
tg_newtuple
;
old_row
=
trigdata
->
tg_trigtuple
;
old_row
=
trigdata
->
tg_trigtuple
;
...
@@ -1708,6 +1732,9 @@ RI_FKey_restrict_upd(PG_FUNCTION_ARGS)
...
@@ -1708,6 +1732,9 @@ RI_FKey_restrict_upd(PG_FUNCTION_ARGS)
/*
/*
* Now check for existing references
* Now check for existing references
*/
*/
save_uid
=
GetUserId
();
SetUserId
(
fk_owner
);
SetUserId
(
RelationGetForm
(
pk_rel
)
->
relowner
);
SetUserId
(
RelationGetForm
(
pk_rel
)
->
relowner
);
if
(
SPI_execp
(
qplan
,
upd_values
,
upd_nulls
,
1
)
!=
SPI_OK_SELECT
)
if
(
SPI_execp
(
qplan
,
upd_values
,
upd_nulls
,
1
)
!=
SPI_OK_SELECT
)
...
@@ -1764,6 +1791,8 @@ RI_FKey_setnull_del(PG_FUNCTION_ARGS)
...
@@ -1764,6 +1791,8 @@ RI_FKey_setnull_del(PG_FUNCTION_ARGS)
char
upd_nulls
[
RI_MAX_NUMKEYS
+
1
];
char
upd_nulls
[
RI_MAX_NUMKEYS
+
1
];
bool
isnull
;
bool
isnull
;
int
i
;
int
i
;
Oid
save_uid
;
Oid
fk_owner
;
ReferentialIntegritySnapshotOverride
=
true
;
ReferentialIntegritySnapshotOverride
=
true
;
...
@@ -1801,6 +1830,7 @@ RI_FKey_setnull_del(PG_FUNCTION_ARGS)
...
@@ -1801,6 +1830,7 @@ RI_FKey_setnull_del(PG_FUNCTION_ARGS)
* tuple.
* tuple.
*/
*/
fk_rel
=
heap_openr
(
tgargs
[
RI_FK_RELNAME_ARGNO
],
NoLock
);
fk_rel
=
heap_openr
(
tgargs
[
RI_FK_RELNAME_ARGNO
],
NoLock
);
fk_owner
=
RelationGetForm
(
fk_rel
)
->
relowner
;
pk_rel
=
trigdata
->
tg_relation
;
pk_rel
=
trigdata
->
tg_relation
;
old_row
=
trigdata
->
tg_trigtuple
;
old_row
=
trigdata
->
tg_trigtuple
;
...
@@ -1915,9 +1945,14 @@ RI_FKey_setnull_del(PG_FUNCTION_ARGS)
...
@@ -1915,9 +1945,14 @@ RI_FKey_setnull_del(PG_FUNCTION_ARGS)
/*
/*
* Now update the existing references
* Now update the existing references
*/
*/
save_uid
=
GetUserId
();
SetUserId
(
fk_owner
);
if
(
SPI_execp
(
qplan
,
upd_values
,
upd_nulls
,
0
)
!=
SPI_OK_UPDATE
)
if
(
SPI_execp
(
qplan
,
upd_values
,
upd_nulls
,
0
)
!=
SPI_OK_UPDATE
)
elog
(
ERROR
,
"SPI_execp() failed in RI_FKey_setnull_del()"
);
elog
(
ERROR
,
"SPI_execp() failed in RI_FKey_setnull_del()"
);
SetUserId
(
save_uid
);
if
(
SPI_finish
()
!=
SPI_OK_FINISH
)
if
(
SPI_finish
()
!=
SPI_OK_FINISH
)
elog
(
NOTICE
,
"SPI_finish() failed in RI_FKey_setnull_del()"
);
elog
(
NOTICE
,
"SPI_finish() failed in RI_FKey_setnull_del()"
);
...
@@ -1963,6 +1998,8 @@ RI_FKey_setnull_upd(PG_FUNCTION_ARGS)
...
@@ -1963,6 +1998,8 @@ RI_FKey_setnull_upd(PG_FUNCTION_ARGS)
int
i
;
int
i
;
int
match_type
;
int
match_type
;
bool
use_cached_query
;
bool
use_cached_query
;
Oid
save_uid
;
Oid
fk_owner
;
ReferentialIntegritySnapshotOverride
=
true
;
ReferentialIntegritySnapshotOverride
=
true
;
...
@@ -2000,6 +2037,7 @@ RI_FKey_setnull_upd(PG_FUNCTION_ARGS)
...
@@ -2000,6 +2037,7 @@ RI_FKey_setnull_upd(PG_FUNCTION_ARGS)
* tuple.
* tuple.
*/
*/
fk_rel
=
heap_openr
(
tgargs
[
RI_FK_RELNAME_ARGNO
],
NoLock
);
fk_rel
=
heap_openr
(
tgargs
[
RI_FK_RELNAME_ARGNO
],
NoLock
);
fk_owner
=
RelationGetForm
(
fk_rel
)
->
relowner
;
pk_rel
=
trigdata
->
tg_relation
;
pk_rel
=
trigdata
->
tg_relation
;
new_row
=
trigdata
->
tg_newtuple
;
new_row
=
trigdata
->
tg_newtuple
;
old_row
=
trigdata
->
tg_trigtuple
;
old_row
=
trigdata
->
tg_trigtuple
;
...
@@ -2161,9 +2199,14 @@ RI_FKey_setnull_upd(PG_FUNCTION_ARGS)
...
@@ -2161,9 +2199,14 @@ RI_FKey_setnull_upd(PG_FUNCTION_ARGS)
/*
/*
* Now update the existing references
* Now update the existing references
*/
*/
save_uid
=
GetUserId
();
SetUserId
(
fk_owner
);
if
(
SPI_execp
(
qplan
,
upd_values
,
upd_nulls
,
0
)
!=
SPI_OK_UPDATE
)
if
(
SPI_execp
(
qplan
,
upd_values
,
upd_nulls
,
0
)
!=
SPI_OK_UPDATE
)
elog
(
ERROR
,
"SPI_execp() failed in RI_FKey_setnull_upd()"
);
elog
(
ERROR
,
"SPI_execp() failed in RI_FKey_setnull_upd()"
);
SetUserId
(
save_uid
);
if
(
SPI_finish
()
!=
SPI_OK_FINISH
)
if
(
SPI_finish
()
!=
SPI_OK_FINISH
)
elog
(
NOTICE
,
"SPI_finish() failed in RI_FKey_setnull_upd()"
);
elog
(
NOTICE
,
"SPI_finish() failed in RI_FKey_setnull_upd()"
);
...
@@ -2206,6 +2249,8 @@ RI_FKey_setdefault_del(PG_FUNCTION_ARGS)
...
@@ -2206,6 +2249,8 @@ RI_FKey_setdefault_del(PG_FUNCTION_ARGS)
char
upd_nulls
[
RI_MAX_NUMKEYS
+
1
];
char
upd_nulls
[
RI_MAX_NUMKEYS
+
1
];
bool
isnull
;
bool
isnull
;
int
i
;
int
i
;
Oid
save_uid
;
Oid
fk_owner
;
ReferentialIntegritySnapshotOverride
=
true
;
ReferentialIntegritySnapshotOverride
=
true
;
...
@@ -2243,6 +2288,7 @@ RI_FKey_setdefault_del(PG_FUNCTION_ARGS)
...
@@ -2243,6 +2288,7 @@ RI_FKey_setdefault_del(PG_FUNCTION_ARGS)
* tuple.
* tuple.
*/
*/
fk_rel
=
heap_openr
(
tgargs
[
RI_FK_RELNAME_ARGNO
],
NoLock
);
fk_rel
=
heap_openr
(
tgargs
[
RI_FK_RELNAME_ARGNO
],
NoLock
);
fk_owner
=
RelationGetForm
(
fk_rel
)
->
relowner
;
pk_rel
=
trigdata
->
tg_relation
;
pk_rel
=
trigdata
->
tg_relation
;
old_row
=
trigdata
->
tg_trigtuple
;
old_row
=
trigdata
->
tg_trigtuple
;
...
@@ -2404,9 +2450,14 @@ RI_FKey_setdefault_del(PG_FUNCTION_ARGS)
...
@@ -2404,9 +2450,14 @@ RI_FKey_setdefault_del(PG_FUNCTION_ARGS)
/*
/*
* Now update the existing references
* Now update the existing references
*/
*/
save_uid
=
GetUserId
();
SetUserId
(
fk_owner
);
if
(
SPI_execp
(
qplan
,
upd_values
,
upd_nulls
,
0
)
!=
SPI_OK_UPDATE
)
if
(
SPI_execp
(
qplan
,
upd_values
,
upd_nulls
,
0
)
!=
SPI_OK_UPDATE
)
elog
(
ERROR
,
"SPI_execp() failed in RI_FKey_setdefault_del()"
);
elog
(
ERROR
,
"SPI_execp() failed in RI_FKey_setdefault_del()"
);
SetUserId
(
save_uid
);
if
(
SPI_finish
()
!=
SPI_OK_FINISH
)
if
(
SPI_finish
()
!=
SPI_OK_FINISH
)
elog
(
NOTICE
,
"SPI_finish() failed in RI_FKey_setdefault_del()"
);
elog
(
NOTICE
,
"SPI_finish() failed in RI_FKey_setdefault_del()"
);
...
@@ -2451,6 +2502,8 @@ RI_FKey_setdefault_upd(PG_FUNCTION_ARGS)
...
@@ -2451,6 +2502,8 @@ RI_FKey_setdefault_upd(PG_FUNCTION_ARGS)
bool
isnull
;
bool
isnull
;
int
i
;
int
i
;
int
match_type
;
int
match_type
;
Oid
save_uid
;
Oid
fk_owner
;
ReferentialIntegritySnapshotOverride
=
true
;
ReferentialIntegritySnapshotOverride
=
true
;
...
@@ -2488,6 +2541,7 @@ RI_FKey_setdefault_upd(PG_FUNCTION_ARGS)
...
@@ -2488,6 +2541,7 @@ RI_FKey_setdefault_upd(PG_FUNCTION_ARGS)
* tuple.
* tuple.
*/
*/
fk_rel
=
heap_openr
(
tgargs
[
RI_FK_RELNAME_ARGNO
],
NoLock
);
fk_rel
=
heap_openr
(
tgargs
[
RI_FK_RELNAME_ARGNO
],
NoLock
);
fk_owner
=
RelationGetForm
(
fk_rel
)
->
relowner
;
pk_rel
=
trigdata
->
tg_relation
;
pk_rel
=
trigdata
->
tg_relation
;
new_row
=
trigdata
->
tg_newtuple
;
new_row
=
trigdata
->
tg_newtuple
;
old_row
=
trigdata
->
tg_trigtuple
;
old_row
=
trigdata
->
tg_trigtuple
;
...
@@ -2676,9 +2730,14 @@ RI_FKey_setdefault_upd(PG_FUNCTION_ARGS)
...
@@ -2676,9 +2730,14 @@ RI_FKey_setdefault_upd(PG_FUNCTION_ARGS)
/*
/*
* Now update the existing references
* Now update the existing references
*/
*/
save_uid
=
GetUserId
();
SetUserId
(
fk_owner
);
if
(
SPI_execp
(
qplan
,
upd_values
,
upd_nulls
,
0
)
!=
SPI_OK_UPDATE
)
if
(
SPI_execp
(
qplan
,
upd_values
,
upd_nulls
,
0
)
!=
SPI_OK_UPDATE
)
elog
(
ERROR
,
"SPI_execp() failed in RI_FKey_setdefault_upd()"
);
elog
(
ERROR
,
"SPI_execp() failed in RI_FKey_setdefault_upd()"
);
SetUserId
(
save_uid
);
if
(
SPI_finish
()
!=
SPI_OK_FINISH
)
if
(
SPI_finish
()
!=
SPI_OK_FINISH
)
elog
(
NOTICE
,
"SPI_finish() failed in RI_FKey_setdefault_upd()"
);
elog
(
NOTICE
,
"SPI_finish() failed in RI_FKey_setdefault_upd()"
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment