diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2005-12-14 17:06:37 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2005-12-14 17:06:37 +0000 |
commit | ba7fd49de5e32485c343187446fdd8cf656471c8 (patch) | |
tree | f56621b01f2f0f21bdb1c6949c3d00761f492672 /src/backend/commands/prepare.c | |
parent | 599e225c114d74eaf4b5d24190abbb4962948073 (diff) | |
download | postgresql-ba7fd49de5e32485c343187446fdd8cf656471c8.tar.gz postgresql-ba7fd49de5e32485c343187446fdd8cf656471c8.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 7932f838fee..3974de173fd 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.42 2005/10/21 16:43:33 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/commands/prepare.c,v 1.42.2.1 2005/12/14 17:06:37 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -446,6 +446,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. |