diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2005-12-14 17:06:28 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2005-12-14 17:06:28 +0000 |
commit | 4ce6be4f5e1e4b0c89c5c8de179e3fa8216a7b54 (patch) | |
tree | aa97d6ee837e6fa5834da31defd3fd69f872b8fc /src/backend/commands/prepare.c | |
parent | 426292663acb30bdd8381eae4058e8ffcbf12162 (diff) | |
download | postgresql-4ce6be4f5e1e4b0c89c5c8de179e3fa8216a7b54.tar.gz postgresql-4ce6be4f5e1e4b0c89c5c8de179e3fa8216a7b54.zip |
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.
Diffstat (limited to 'src/backend/commands/prepare.c')
-rw-r--r-- | src/backend/commands/prepare.c | 26 |
1 files changed, 25 insertions, 1 deletions
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 $ * *------------------------------------------------------------------------- */ @@ -448,6 +448,30 @@ FetchPreparedStatementResultDesc(PreparedStatement *stmt) } /* + * 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 * targetlist. |