aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/portalcmds.c
diff options
context:
space:
mode:
authorNeil Conway <neilc@samurai.com>2006-01-18 06:49:30 +0000
committerNeil Conway <neilc@samurai.com>2006-01-18 06:49:30 +0000
commit33e06ebccbc21677be6dbc112e3d150bd13b17cb (patch)
treeb55b21dfeefca076512b2cc8f597eace12f3eeb4 /src/backend/commands/portalcmds.c
parent558bc2584d7e79801acb8344b79838cd3511915b (diff)
downloadpostgresql-33e06ebccbc21677be6dbc112e3d150bd13b17cb.tar.gz
postgresql-33e06ebccbc21677be6dbc112e3d150bd13b17cb.zip
Add a new system view, pg_cursors, that displays the currently available
cursors. Patch from Joachim Wieland, review and ediorialization by Neil Conway. The view lists cursors defined by DECLARE CURSOR, using SPI, or via the Bind message of the frontend/backend protocol. This means the view does not list the unnamed portal or the portal created to implement EXECUTE. Because we do list SPI portals, there might be more rows in this view than you might expect if you are using SPI implicitly (e.g. via a procedural language). Per recent discussion on -hackers, the query string included in the view for cursors defined by DECLARE CURSOR is based on debug_query_string. That means it is not accurate if multiple queries separated by semicolons are submitted as one query string. However, there doesn't seem a trivial fix for that: debug_query_string is better than nothing. I also changed SPI_cursor_open() to include the source text for the portal it creates: AFAICS there is no reason not to do this. Update the documentation and regression tests, bump the catversion.
Diffstat (limited to 'src/backend/commands/portalcmds.c')
-rw-r--r--src/backend/commands/portalcmds.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/backend/commands/portalcmds.c b/src/backend/commands/portalcmds.c
index 8246b25774e..b2dab9d98de 100644
--- a/src/backend/commands/portalcmds.c
+++ b/src/backend/commands/portalcmds.c
@@ -14,7 +14,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/portalcmds.c,v 1.44 2005/11/03 17:11:35 alvherre Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/portalcmds.c,v 1.45 2006/01/18 06:49:26 neilc Exp $
*
*-------------------------------------------------------------------------
*/
@@ -28,6 +28,7 @@
#include "optimizer/planner.h"
#include "rewrite/rewriteHandler.h"
#include "tcop/pquery.h"
+#include "tcop/tcopprot.h"
#include "utils/memutils.h"
@@ -105,8 +106,12 @@ PerformCursorOpen(DeclareCursorStmt *stmt, ParamListInfo params)
query = copyObject(query);
plan = copyObject(plan);
+ /*
+ * XXX: debug_query_string is wrong here: the user might have
+ * submitted more than one semicolon delimited queries.
+ */
PortalDefineQuery(portal,
- NULL, /* unfortunately don't have sourceText */
+ pstrdup(debug_query_string),
"SELECT", /* cursor's query is always a SELECT */
list_make1(query),
list_make1(plan),