aboutsummaryrefslogtreecommitdiff
path: root/src/backend
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/commands/portalcmds.c46
-rw-r--r--src/backend/parser/gram.y21
-rw-r--r--src/backend/tcop/utility.c4
3 files changed, 47 insertions, 24 deletions
diff --git a/src/backend/commands/portalcmds.c b/src/backend/commands/portalcmds.c
index b1799e49f8c..3a670d8f899 100644
--- a/src/backend/commands/portalcmds.c
+++ b/src/backend/commands/portalcmds.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/portalcmds.c,v 1.6 2002/12/15 16:17:42 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/portalcmds.c,v 1.7 2002/12/30 15:31:47 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -65,7 +65,7 @@ PortalCleanup(Portal portal)
void
PerformPortalFetch(char *name,
bool forward,
- int count,
+ long count,
CommandDest dest,
char *completionTag)
{
@@ -100,14 +100,48 @@ PerformPortalFetch(char *name,
return;
}
- /* If zero count, we are done */
+ /* If zero count, handle specially */
if (count == 0)
- return;
+ {
+ bool on_row = false;
+
+ /* Are we sitting on a row? */
+ oldcontext = MemoryContextSwitchTo(PortalGetHeapMemory(portal));
+ queryDesc = PortalGetQueryDesc(portal);
+ estate = queryDesc->estate;
+ if (portal->atStart == false && portal->atEnd == false)
+ on_row = true;
+ MemoryContextSwitchTo(oldcontext);
+
+ if (dest == None)
+ {
+ /* MOVE 0 returns 0/1 based on if FETCH 0 would return a row */
+ if (completionTag && on_row)
+ strcpy(completionTag, "MOVE 1");
+ return;
+ }
+ else
+ {
+ /* If we are not on a row, FETCH 0 returns nothing */
+ if (!on_row)
+ return;
+
+ /* Since we are sitting on a row, return the row */
+ /* Back up so we can reread the row */
+ PerformPortalFetch(name, false /* backward */, 1,
+ None, /* throw away output */
+ NULL /* do not modify the command tag */);
+
+ /* Set up to fetch one row */
+ count = 1;
+ forward = true;
+ }
+ }
/* Internally, zero count processes all portal rows */
- if (count == INT_MAX)
+ if (count == LONG_MAX)
count = 0;
-
+
/*
* switch into the portal context
*/
diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
index bb94d1f8e82..c19673fc422 100644
--- a/src/backend/parser/gram.y
+++ b/src/backend/parser/gram.y
@@ -11,7 +11,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.388 2002/12/12 20:35:13 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.389 2002/12/30 15:31:47 momjian Exp $
*
* HISTORY
* AUTHOR DATE MAJOR EVENT
@@ -2591,13 +2591,6 @@ comment_text:
FetchStmt: FETCH direction fetch_how_many from_in name
{
FetchStmt *n = makeNode(FetchStmt);
- if ($2 == RELATIVE)
- {
- if ($3 == 0)
- elog(ERROR,
- "FETCH / RELATIVE at current position is not supported");
- $2 = FORWARD;
- }
if ($3 < 0)
{
$3 = -$3;
@@ -2629,10 +2622,6 @@ FetchStmt: FETCH direction fetch_how_many from_in name
| FETCH direction from_in name
{
FetchStmt *n = makeNode(FetchStmt);
- if ($2 == RELATIVE)
- {
- $2 = FORWARD;
- }
n->direction = $2;
n->howMany = 1;
n->portalname = $4;
@@ -2719,20 +2708,20 @@ FetchStmt: FETCH direction fetch_how_many from_in name
direction: FORWARD { $$ = FORWARD; }
| BACKWARD { $$ = BACKWARD; }
- | RELATIVE { $$ = RELATIVE; }
+ | RELATIVE { $$ = FORWARD; }
| ABSOLUTE
{
elog(NOTICE,
"FETCH / ABSOLUTE not supported, using RELATIVE");
- $$ = RELATIVE;
+ $$ = FORWARD;
}
;
fetch_how_many:
Iconst { $$ = $1; }
| '-' Iconst { $$ = - $2; }
- | ALL { $$ = INT_MAX; }
- | LAST { $$ = INT_MAX; }
+ | ALL { $$ = LONG_MAX; }
+ | LAST { $$ = LONG_MAX; }
| NEXT { $$ = 1; }
| PRIOR { $$ = -1; }
;
diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c
index 40228601d72..cc0f139b2db 100644
--- a/src/backend/tcop/utility.c
+++ b/src/backend/tcop/utility.c
@@ -10,7 +10,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.185 2002/12/06 05:00:31 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.186 2002/12/30 15:31:48 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -257,7 +257,7 @@ ProcessUtility(Node *parsetree,
FetchStmt *stmt = (FetchStmt *) parsetree;
char *portalName = stmt->portalname;
bool forward;
- int count;
+ long count;
forward = (bool) (stmt->direction == FORWARD);