Make MOVE/FETCH 0 actually move/fetch 0. Add MOVE LAST to move to end
authorBruce Momjian
Wed, 13 Nov 2002 00:44:09 +0000 (00:44 +0000)
committerBruce Momjian
Wed, 13 Nov 2002 00:44:09 +0000 (00:44 +0000)
of cursor.

doc/src/sgml/ref/move.sgml
src/backend/commands/portalcmds.c
src/backend/executor/execMain.c
src/backend/parser/gram.y
src/backend/parser/keywords.c
src/backend/tcop/utility.c
src/include/commands/portalcmds.h
src/include/nodes/parsenodes.h

index 0d0d662ada25d055816307bf8f8cec37a93abf8f..46c830406eacd24c73226fc6cda5708e6e83032b 100644 (file)
@@ -1,5 +1,5 @@
 
 
@@ -21,7 +21,8 @@ PostgreSQL documentation
    1999-07-20
   
   
-MOVE [ direction ] [ count ] 
+MOVE [ direction ] 
+    {count | LAST }
     { IN | FROM } cursor
   
  
@@ -37,8 +38,9 @@ MOVE [ direction ] [ 
    MOVE allows a user to move cursor position a specified
    number of rows.
    MOVE works like the FETCH command,
-   but only positions the cursor and does
-   not return rows.
+   but only positions the cursor and does not return rows.
+   LAST moves to the end
+   of the cursor.
   
   
    Refer to 
index 0454b21b11a9a9a140090f848ce91f287e8df84f..812cb05dacfb90930e448dbb5b003f23fb80ac38 100644 (file)
@@ -8,13 +8,15 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/commands/portalcmds.c,v 1.3 2002/09/04 20:31:15 momjian Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/commands/portalcmds.c,v 1.4 2002/11/13 00:44:08 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
 
 #include "postgres.h"
 
+#include 
+
 #include "commands/portalcmds.h"
 #include "executor/executor.h"
 
@@ -55,7 +57,7 @@ PortalCleanup(Portal portal)
  *
  * name: name of portal
  * forward: forward or backward fetch?
- * count: # of tuples to fetch (0 implies all)
+ * count: # of tuples to fetch
  * dest: where to send results
  * completionTag: points to a buffer of size COMPLETION_TAG_BUFSIZE
  *     in which to store a command completion status string.
@@ -100,6 +102,14 @@ PerformPortalFetch(char *name,
        return;
    }
 
+   /* If zero count, we are done */
+   if (count == 0)
+       return;
+
+   /* Internally, zero count processes all portal rows */
+   if (count == INT_MAX)
+       count = 0;
+       
    /*
     * switch into the portal context
     */
index e775ae030e0c5f79a304252291eac053ad0f091a..65afe0820316af8c297d7ee7f02e0743fe5281c4 100644 (file)
@@ -27,7 +27,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.185 2002/11/13 00:39:46 momjian Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.186 2002/11/13 00:44:08 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -1116,7 +1116,8 @@ lnext:    ;
 
        /*
         * check our tuple count.. if we've processed the proper number
-        * then quit, else loop again and process more tuples..
+        * then quit, else loop again and process more tuples.  Zero
+        * number_tuples means no limit.
         */
        current_tuple_count++;
        if (numberTuples == current_tuple_count)
index 96d12f1b560a49f7444bb69522e3d39f57f91c5b..724424220b671f3d79cb56483919e3a26efc68c8 100644 (file)
@@ -11,7 +11,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.376 2002/11/11 22:19:23 tgl Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.377 2002/11/13 00:44:08 momjian Exp $
  *
  * HISTORY
  *   AUTHOR            DATE            MAJOR EVENT
@@ -49,6 +49,7 @@
 #include "postgres.h"
 
 #include 
+#include 
 
 #include "access/htup.h"
 #include "catalog/index.h"
@@ -358,7 +359,7 @@ static void doNegateFloat(Value *v);
 
    KEY
 
-   LANCOMPILER LANGUAGE LEADING LEFT LEVEL LIKE LIMIT
+   LANCOMPILER LANGUAGE LAST LEADING LEFT LEVEL LIKE LIMIT
    LISTEN LOAD LOCAL LOCALTIME LOCALTIMESTAMP LOCATION
    LOCK_P
 
@@ -2661,7 +2662,7 @@ FetchStmt:    FETCH direction fetch_how_many from_in name
                    if ($3 < 0)
                    {
                        $3 = -$3;
-                       $2 = (($2 == FORWARD)? BACKWARD: FORWARD);
+                       $2 = (($2 == FORWARD) ? BACKWARD: FORWARD);
                    }
                    n->direction = $2;
                    n->howMany = $3;
@@ -2729,8 +2730,8 @@ direction:    FORWARD                                 { $$ = FORWARD; }
 fetch_how_many:
            Iconst                                  { $$ = $1; }
            | '-' Iconst                            { $$ = - $2; }
-                                           /* 0 means fetch all tuples*/
-           | ALL                                   { $$ = 0; }
+           | ALL                                   { $$ = INT_MAX; }
+           | LAST                                  { $$ = INT_MAX; }
            | NEXT                                  { $$ = 1; }
            | PRIOR                                 { $$ = -1; }
        ;
@@ -7060,6 +7061,7 @@ unreserved_keyword:
            | KEY
            | LANGUAGE
            | LANCOMPILER
+           | LAST
            | LEVEL
            | LISTEN
            | LOAD
index 1c9c064e4747cfbf503e4d9fb9d7591d48551952..b86ffa522e4e3f45d3ba4996c8e1f11c11f010a9 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/parser/keywords.c,v 1.129 2002/11/11 22:19:23 tgl Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/parser/keywords.c,v 1.130 2002/11/13 00:44:09 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -172,6 +172,7 @@ static const ScanKeyword ScanKeywords[] = {
    {"key", KEY},
    {"lancompiler", LANCOMPILER},
    {"language", LANGUAGE},
+   {"last", LAST},
    {"leading", LEADING},
    {"left", LEFT},
    {"level", LEVEL},
index 1c3ea71d2fe886cf5e73b26db031ab787f3c8fe2..ddd5c7626a6c28fba221a36a0efd2f4c4f0588ea 100644 (file)
@@ -10,7 +10,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.180 2002/10/21 20:31:52 momjian Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.181 2002/11/13 00:44:09 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -262,9 +262,8 @@ ProcessUtility(Node *parsetree,
                forward = (bool) (stmt->direction == FORWARD);
 
                /*
-                * parser ensures that count is >= 0 and 'fetch ALL' -> 0
+                * parser ensures that count is >= 0
                 */
-
                count = stmt->howMany;
                PerformPortalFetch(portalName, forward, count,
                                   (stmt->ismove) ? None : dest,
index 9611cb47f9283502b71cfd96c941ea2d2958d2ba..5526ac997dc43a094d35ac306aafdc250a321009 100644 (file)
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: portalcmds.h,v 1.2 2002/09/04 20:31:42 momjian Exp $
+ * $Id: portalcmds.h,v 1.3 2002/11/13 00:44:09 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -18,7 +18,7 @@
 
 /*
  * PerformPortalFetch
- *     Performs the POSTQUEL function FETCH.  Fetches count (or all if 0)
+ *     Performs the POSTQUEL function FETCH.  Fetches count
  * tuples in portal with name in the forward direction iff goForward.
  *
  * Exceptions:
index 7554f00361d56b1ae6ac5550cacc0257bfdd602d..962452992e80c59b70f23563bcec6d61d1d1787f 100644 (file)
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: parsenodes.h,v 1.212 2002/11/11 22:19:24 tgl Exp $
+ * $Id: parsenodes.h,v 1.213 2002/11/13 00:44:09 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -1277,7 +1277,7 @@ typedef struct FetchStmt
 {
    NodeTag     type;
    int         direction;      /* FORWARD or BACKWARD */
-   int         howMany;        /* amount to fetch ("ALL" --> 0) */
+   int         howMany;        /* amount to fetch */
    char       *portalname;     /* name of portal (cursor) */
    bool        ismove;         /* TRUE if MOVE */
 } FetchStmt;