Skip to content

Commit b651b2a

Browse files
committed
Make sure we give an appropriate user-facing error when attempting
to drop a table that is referenced by an open cursor. Fix unstable ecpg regression test result that was produced by this oversight.
1 parent 2a6108a commit b651b2a

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

src/backend/catalog/heap.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/catalog/heap.c,v 1.346 2008/11/27 15:59:28 heikki Exp $
11+
* $PostgreSQL: pgsql/src/backend/catalog/heap.c,v 1.347 2008/11/29 00:13:21 tgl Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -1412,6 +1412,17 @@ heap_drop_with_catalog(Oid relid)
14121412
*/
14131413
rel = relation_open(relid, AccessExclusiveLock);
14141414

1415+
/*
1416+
* There can no longer be anyone *else* touching the relation, but we
1417+
* might still have open queries or cursors in our own session.
1418+
*/
1419+
if (rel->rd_refcnt != 1)
1420+
ereport(ERROR,
1421+
(errcode(ERRCODE_OBJECT_IN_USE),
1422+
errmsg("cannot drop \"%s\" because "
1423+
"it is being used by active queries in this session",
1424+
RelationGetRelationName(rel))));
1425+
14151426
/*
14161427
* Schedule unlinking of the relation's physical files at commit.
14171428
*/

src/interfaces/ecpg/test/expected/sql-fetch.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,10 @@
138138
[NO_PID]: sqlca: code: 0, state: 00000
139139
[NO_PID]: ecpg_execute on line 53: using PQexec
140140
[NO_PID]: sqlca: code: 0, state: 00000
141-
[NO_PID]: ecpg_check_PQresult on line 53: ERROR: relation 16491 is still open
141+
[NO_PID]: ecpg_check_PQresult on line 53: ERROR: cannot drop "my_table" because it is being used by active queries in this session
142142
[NO_PID]: sqlca: code: 0, state: 00000
143-
[NO_PID]: raising sqlstate XX000 (sqlcode -400) on line 53: relation 16491 is still open on line 53
144-
[NO_PID]: sqlca: code: -400, state: XX000
145-
sql error: relation 16491 is still open on line 53
143+
[NO_PID]: raising sqlstate 55006 (sqlcode -400) on line 53: cannot drop "my_table" because it is being used by active queries in this session on line 53
144+
[NO_PID]: sqlca: code: -400, state: 55006
145+
sql error: cannot drop "my_table" because it is being used by active queries in this session on line 53
146146
[NO_PID]: ecpg_finish: connection regress1 closed
147147
[NO_PID]: sqlca: code: 0, state: 00000

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy