aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/prepare.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/commands/prepare.c')
-rw-r--r--src/backend/commands/prepare.c20
1 files changed, 8 insertions, 12 deletions
diff --git a/src/backend/commands/prepare.c b/src/backend/commands/prepare.c
index 8361fc67554..bf6aad1ac14 100644
--- a/src/backend/commands/prepare.c
+++ b/src/backend/commands/prepare.c
@@ -10,7 +10,7 @@
* Copyright (c) 2002-2008, PostgreSQL Global Development Group
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/prepare.c,v 1.87 2008/05/12 20:01:59 alvherre Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/prepare.c,v 1.88 2008/07/18 20:26:06 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -174,6 +174,7 @@ ExecuteQuery(ExecuteStmt *stmt, const char *queryString,
ParamListInfo paramLI = NULL;
EState *estate = NULL;
Portal portal;
+ char *query_string;
/* Look it up in the hash table */
entry = FetchPreparedStatement(stmt->name, true);
@@ -203,6 +204,10 @@ ExecuteQuery(ExecuteStmt *stmt, const char *queryString,
/* Don't display the portal in pg_cursors, it is for internal use only */
portal->visible = false;
+ /* Copy the plan's saved query string into the portal's memory */
+ query_string = MemoryContextStrdup(PortalGetHeapMemory(portal),
+ entry->plansource->query_string);
+
/*
* For CREATE TABLE / AS EXECUTE, we must make a copy of the stored query
* so that we can modify its destination (yech, but this has always been
@@ -249,13 +254,9 @@ ExecuteQuery(ExecuteStmt *stmt, const char *queryString,
plan_list = cplan->stmt_list;
}
- /*
- * Note: we don't bother to copy the source query string into the portal.
- * Any errors it might be useful for will already have been reported.
- */
PortalDefineQuery(portal,
NULL,
- NULL,
+ query_string,
entry->plansource->commandTag,
plan_list,
cplan);
@@ -777,12 +778,7 @@ pg_prepared_statement(PG_FUNCTION_ARGS)
MemSet(nulls, 0, sizeof(nulls));
values[0] = CStringGetTextDatum(prep_stmt->stmt_name);
-
- if (prep_stmt->plansource->query_string == NULL)
- nulls[1] = true;
- else
- values[1] = CStringGetTextDatum(prep_stmt->plansource->query_string);
-
+ values[1] = CStringGetTextDatum(prep_stmt->plansource->query_string);
values[2] = TimestampTzGetDatum(prep_stmt->prepare_time);
values[3] = build_regtype_array(prep_stmt->plansource->param_types,
prep_stmt->plansource->num_params);