Allow PQcmdTuples to return row counts for MOVE and FETCH.
authorBruce Momjian
Wed, 19 Feb 2003 03:59:02 +0000 (03:59 +0000)
committerBruce Momjian
Wed, 19 Feb 2003 03:59:02 +0000 (03:59 +0000)
Neil Conway

doc/src/sgml/libpq.sgml
doc/src/sgml/protocol.sgml
src/backend/tcop/utility.c
src/interfaces/libpq/fe-exec.c

index 1ce38c379510890c7122022a35f3deb7d949e1cf..087f40e2380ca93cdf0ebcc3bed70951c207363e 100644 (file)
@@ -1,5 +1,5 @@
 
 
  
@@ -702,12 +702,11 @@ char *PQerrorMessage(const PGconn* conn);
 int PQbackendPID(const PGconn *conn);
        
        The backend PID is useful for debugging
-       purposes and for comparison
-       to NOTIFY messages (which include the PID of
-       the notifying backend).
-       Note that the PID belongs to a process
-       executing on the database
-       server host, not the local host!
+       purposes and for comparison to NOTIFY
+       messages (which include the PID of the
+       notifying backend).  Note that the PID
+       belongs to a process executing on the database server host, not
+       the local host!
       
      
 
@@ -818,13 +817,14 @@ ExecStatusType PQresultStatus(const PGresult *res)
  
 
 
-If  the result status is PGRES_TUPLES_OK, then the
-routines described below can be  used  to  retrieve  the
-rows returned by the query.  Note that a SELECT command that
-happens to retrieve zero rows still shows PGRES_TUPLES_OK.
-PGRES_COMMAND_OK is for commands that can never return rows
-(INSERT, UPDATE, etc.). A response of PGRES_EMPTY_QUERY often
-exposes a bug in the client software.
+If the result status is PGRES_TUPLES_OK, then the
+routines described below can be used to retrieve the rows returned by
+the query.  Note that a SELECT command that happens
+to retrieve zero rows still shows PGRES_TUPLES_OK.
+PGRES_COMMAND_OK is for commands that can never
+return rows (INSERTUPDATE,
+etc.). A response of PGRES_EMPTY_QUERY often
+indicates a bug in the client software.
 
 
 
@@ -1243,36 +1243,41 @@ char * PQcmdStatus(PGresult *res);
 char * PQcmdTuples(PGresult *res);
 
           If the SQL command that generated the
-     PGresult was INSERT, UPDATE or DELETE, this returns a
-     string containing the number of rows affected.  If the
-          command was anything else, it returns the empty string.
+     PGresult was INSERT,
+     UPDATEDELETE,
+     MOVE, or FETCH this
+     returns a string containing the number of rows affected.  If the
+     command was anything else, it returns the empty string.
 
 
 
 
 
 PQoidValue
-          Returns the object ID of the inserted row, if the
-     SQL command was an INSERT
-     that inserted exactly one row into a table that has OIDs.
-          Otherwise, returns InvalidOid.
+      Returns the object ID of the inserted row, if the
+      SQL command was an INSERT
+      that inserted exactly one row into a table that has OIDs.
+      Otherwise, returns InvalidOid.
 
 Oid PQoidValue(const PGresult *res);
 
-          The type Oid and the constant InvalidOid
-          will be defined if you include the libpq
-          header file. They will both be some integer type.
+          The type Oid and the constant
+      InvalidOid will be defined if you include the
+      libpq header file. They will both be
+      some integer type.
 
 
 
 
 
 PQoidStatus
-          Returns a string with the object ID of the inserted row, if the
-     SQL command was an INSERT.
-     (The string will be 0 if the INSERT did not insert exactly one
-     row, or if the target table does not have OIDs.)  If the command
-     was not an INSERT, returns an empty string.
+      Returns a string with the object ID
+      of the inserted row, if the SQL command
+      was an INSERT.  (The string will be
+      0 if the INSERT did not
+      insert exactly one row, or if the target table does not have
+      OIDs.)  If the command was not an INSERT,
+      returns an empty string.
 
 char * PQoidStatus(const PGresult *res);
 
@@ -1530,7 +1535,8 @@ When the main loop detects input ready, it should call
 PQconsumeInput to read the input.  It can then call
 PQisBusy, followed by PQgetResult
 if PQisBusy returns false (0).  It can also call
-PQnotifies to detect NOTIFY messages (see ).
+PQnotifies to detect NOTIFY
+messages (see ).
 
 
 
@@ -1700,13 +1706,13 @@ of asynchronous notification.
 PQnotifies() does not actually read backend data; it just
 returns messages previously absorbed by another libpq
 function.  In prior releases of libpq, the only way
-to ensure timely receipt of NOTIFY messages was to constantly submit queries,
+to ensure timely receipt of NOTIFY messages was to constantly submit queries,
 even empty ones, and then check PQnotifies() after each
 PQexec().  While this still works, it is
 deprecated as a waste of processing power.
 
 
-A better way to check for NOTIFY
+A better way to check for NOTIFY
 messages when you have no useful queries to make is to call
 PQconsumeInput(), then check
 PQnotifies().
index 06901a8e335295a1fac75177ecedd2661ee5a46f..f6507387287abd02b4eaa44d17b895c66776e130 100644 (file)
@@ -1,4 +1,4 @@
-
+
 
 
  Frontend/Backend Protocol
@@ -1335,6 +1335,20 @@ CompletedResponse (B)
    UPDATE rows where
         rows is the number of rows updated.
 
+
+       
+        For a MOVE command, the tag is
+        MOVE rows where
+        rows is the number of rows the
+        cursor's position has been changed by.
+       
+
+       
+        For a FETCH command, the tag is
+        FETCH rows where
+        rows is the number of rows that
+        have been retrieved from the cursor.
+       
 
 
 
index b48550428f65a44899a7c90cd1081b7f75985894..db7dc0945cd0c74e23cd3b3b3553f1e84577b81d 100644 (file)
@@ -10,7 +10,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.192 2003/02/13 05:20:01 momjian Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.193 2003/02/19 03:59:02 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -254,7 +254,7 @@ ProcessUtility(Node *parsetree,
    switch (nodeTag(parsetree))
    {
            /*
-            * ******************************** transactions ********************************
+            * ******************** transactions ********************
             */
        case T_TransactionStmt:
            {
index 858c4339c46d6fdcb8f6e3b275e8ca10fb9b0842..bc18aeaf0870c8d874647da026a3d29328efdbb4 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.124 2003/01/07 22:23:17 tgl Exp $
+ *   $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.125 2003/02/19 03:59:02 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -2272,7 +2272,7 @@ PQoidStatus(const PGresult *res)
 
 /*
   PQoidValue -
-       a perhaps preferable form of the above which just returns
+   a perhaps preferable form of the above which just returns
    an Oid type
 */
 Oid
@@ -2300,53 +2300,54 @@ PQoidValue(const PGresult *res)
 
 /*
    PQcmdTuples -
-   if the last command was an INSERT/UPDATE/DELETE, return number
-   of inserted/affected tuples, if not, return ""
+   If the last command was an INSERT/UPDATE/DELETE/MOVE/FETCH, return a
+   string containing the number of inserted/affected tuples. If not,
+   return "".
+
+   XXX: this should probably return an int
 */
 char *
 PQcmdTuples(PGresult *res)
 {
    char        noticeBuf[128];
+   char        *p;
 
    if (!res)
        return "";
 
-   if (strncmp(res->cmdStatus, "INSERT", 6) == 0 ||
-       strncmp(res->cmdStatus, "DELETE", 6) == 0 ||
-       strncmp(res->cmdStatus, "UPDATE", 6) == 0)
+   if (strncmp(res->cmdStatus, "INSERT ", 7) == 0)
    {
-       char       *p = res->cmdStatus + 6;
-
-       if (*p == 0)
-       {
-           if (res->noticeHook)
-           {
-               snprintf(noticeBuf, sizeof(noticeBuf),
-                        libpq_gettext("could not interpret result from server: %s\n"),
-                        res->cmdStatus);
-               DONOTICE(res, noticeBuf);
-           }
-           return "";
-       }
+       p = res->cmdStatus + 6;
        p++;
-       if (*(res->cmdStatus) != 'I')   /* UPDATE/DELETE */
-           return p;
+       /* INSERT: skip oid */
        while (*p != ' ' && *p)
-           p++;                /* INSERT: skip oid */
-       if (*p == 0)
+           p++;
+   }
+   else if (strncmp(res->cmdStatus, "DELETE ", 7) == 0 ||
+            strncmp(res->cmdStatus, "UPDATE ", 7) == 0)
+       p = res->cmdStatus + 6;
+   else if (strncmp(res->cmdStatus, "FETCH ", 6) == 0)
+       p = res->cmdStatus + 5;
+   else if (strncmp(res->cmdStatus, "MOVE ", 5) == 0)
+       p = res->cmdStatus + 4;
+   else
+       return "";
+
+   p++;
+
+   if (*p == 0)
+   {
+       if (res->noticeHook)
        {
-           if (res->noticeHook)
-           {
-               snprintf(noticeBuf, sizeof(noticeBuf),
-                        libpq_gettext("no row count available\n"));
-               DONOTICE(res, noticeBuf);
-           }
-           return "";
+           snprintf(noticeBuf, sizeof(noticeBuf),
+                    libpq_gettext("could not interpret result from server: %s\n"),
+                    res->cmdStatus);
+           DONOTICE(res, noticeBuf);
        }
-       p++;
-       return p;
+       return "";
    }
-   return "";
+
+   return p;
 }
 
 /*