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

Commit17ac747

Browse files
committed
Put back error test for DECLARE CURSOR outside a transaction block ...
but do it correctly now.
1 parent810f2cf commit17ac747

File tree

3 files changed

+50
-3
lines changed

3 files changed

+50
-3
lines changed

‎src/backend/access/transam/xact.c

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.138 2002/11/13 03:12:05 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.139 2002/11/18 01:17:39 tgl Exp $
1212
*
1313
* NOTES
1414
*Transaction aborts can now occur two ways:
@@ -1488,6 +1488,50 @@ PreventTransactionChain(void *stmtNode, const char *stmtType)
14881488
}
14891489
}
14901490

1491+
/* --------------------------------
1492+
*RequireTransactionChain
1493+
*
1494+
*This routine is to be called by statements that must run inside
1495+
*a transaction block, because they have no effects that persist past
1496+
*transaction end (and so calling them outside a transaction block
1497+
*is presumably an error). DECLARE CURSOR is an example.
1498+
*
1499+
*If we appear to be running inside a user-defined function, we do not
1500+
*issue an error, since the function could issue more commands that make
1501+
*use of the current statement's results. Thus this is an inverse for
1502+
*PreventTransactionChain.
1503+
*
1504+
*stmtNode: pointer to parameter block for statement; this is used in
1505+
*a very klugy way to determine whether we are inside a function.
1506+
*stmtType: statement type name for error messages.
1507+
* --------------------------------
1508+
*/
1509+
void
1510+
RequireTransactionChain(void*stmtNode,constchar*stmtType)
1511+
{
1512+
/*
1513+
* xact block already started?
1514+
*/
1515+
if (IsTransactionBlock())
1516+
return;
1517+
/*
1518+
* Are we inside a function call? If the statement's parameter block
1519+
* was allocated in QueryContext, assume it is an interactive command.
1520+
* Otherwise assume it is coming from a function.
1521+
*/
1522+
if (!MemoryContextContains(QueryContext,stmtNode))
1523+
return;
1524+
/*
1525+
* If we are in autocommit-off mode then it's okay, because this
1526+
* statement will itself start a transaction block.
1527+
*/
1528+
if (!autocommit&& !suppressChain)
1529+
return;
1530+
/* translator: %s represents an SQL statement name */
1531+
elog(ERROR,"%s may only be used in begin/end transaction blocks",
1532+
stmtType);
1533+
}
1534+
14911535

14921536
/* ----------------------------------------------------------------
14931537
* transaction block support

‎src/backend/tcop/pquery.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/tcop/pquery.c,v 1.55 2002/09/04 20:31:26 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/tcop/pquery.c,v 1.56 2002/11/18 01:17:39 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -161,6 +161,8 @@ ProcessQuery(Query *parsetree,
161161
/* If binary portal, switch to alternate output format */
162162
if (dest==Remote&&parsetree->isBinary)
163163
dest=RemoteInternal;
164+
/* Check for invalid context (must be in transaction block) */
165+
RequireTransactionChain((void*)parsetree,"DECLARE CURSOR");
164166
}
165167
elseif (parsetree->into!=NULL)
166168
{

‎src/include/access/xact.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: xact.h,v 1.47 2002/11/13 03:12:05 momjian Exp $
10+
* $Id: xact.h,v 1.48 2002/11/18 01:17:39 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -115,6 +115,7 @@ extern bool IsTransactionBlock(void);
115115
externvoidUserAbortTransactionBlock(void);
116116
externvoidAbortOutOfAnyTransaction(void);
117117
externvoidPreventTransactionChain(void*stmtNode,constchar*stmtType);
118+
externvoidRequireTransactionChain(void*stmtNode,constchar*stmtType);
118119

119120
externvoidRecordTransactionCommit(void);
120121

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp