From 4ce6be4f5e1e4b0c89c5c8de179e3fa8216a7b54 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Wed, 14 Dec 2005 17:06:28 +0000 Subject: Defend against crash while processing Describe Statement or Describe Portal messages, when client attempts to execute these outside a transaction (start one) or in a failed transaction (reject message, except for COMMIT/ROLLBACK statements which we can handle). Per report from Francisco Figueiredo Jr. --- src/backend/commands/prepare.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'src/backend/commands/prepare.c') diff --git a/src/backend/commands/prepare.c b/src/backend/commands/prepare.c index dc84f57506a..1ee955ebe14 100644 --- a/src/backend/commands/prepare.c +++ b/src/backend/commands/prepare.c @@ -10,7 +10,7 @@ * Copyright (c) 2002-2005, PostgreSQL Global Development Group * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/prepare.c,v 1.43 2005/11/29 01:25:49 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/commands/prepare.c,v 1.44 2005/12/14 17:06:27 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -447,6 +447,30 @@ FetchPreparedStatementResultDesc(PreparedStatement *stmt) return NULL; } +/* + * Given a prepared statement, determine whether it will return tuples. + * + * Note: this is used rather than just testing the result of + * FetchPreparedStatementResultDesc() because that routine can fail if + * invoked in an aborted transaction. This one is safe to use in any + * context. Be sure to keep the two routines in sync! + */ +bool +PreparedStatementReturnsTuples(PreparedStatement *stmt) +{ + switch (ChoosePortalStrategy(stmt->query_list)) + { + case PORTAL_ONE_SELECT: + case PORTAL_UTIL_SELECT: + return true; + + case PORTAL_MULTI_QUERY: + /* will not return tuples */ + break; + } + return false; +} + /* * Given a prepared statement that returns tuples, extract the query * targetlist. Returns NIL if the statement doesn't have a determinable -- cgit v1.2.3