Re: PQcmdTuples() declaration - Mailing list pgsql-interfaces

From Bruce Momjian
Subject Re: PQcmdTuples() declaration
Date
Msg-id 200211080511.gA85B2K11157@candle.pha.pa.us
Whole thread Raw
In response to Re: PQcmdTuples() declaration  (Payman <payman@Club-Internet.fr>)
Responses Re: PQcmdTuples() declaration  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-interfaces
I am not sure how to deal with this.  I have updated the 7.3/CVS docs to
match the include file and code, which has no consts.

The issue with PQcmdTuples() and PQcmdStatus() are that they return
*result structure member pointers.  The patch makes the *result a const,
then we have to return the values as const's.  The code compiled OK, so
I assume that is fine.  How does that sound to others, or should we keep
the result non-const?

---------------------------------------------------------------------------

Payman wrote:
> Hi Michael
> I am running version 7.2.3 on MacOS X and seam thing
> I think this is a doc probleme .
> Strange my doc is a 7.2.1 documentation and 7.2.3 Package.
> If you change the include file you must rebuild all postgresql .
> you dont have link error ?
>
> Payman
>
> >I am running version 7.1.3, installed as an RPM from Red Hat.  According to
> >the documentation for libpq, function PQcmdTuples is declared as
> >'PQcmdTuples(const PGresult*)'.  In my 'libpq-fe.h' include file it is
> >declared as 'PQcmdTuples(PGresult*)' (no const).  Is this an error in the
> >documentation or my include file?  I have changed the include file to match
> >the documentation, and I haven't noticed any negative effects so far.
> >
> >
> >
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
>

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073
Index: doc/src/sgml/libpq.sgml
===================================================================
RCS file: /cvsroot/pgsql-server/doc/src/sgml/libpq.sgml,v
retrieving revision 1.98
diff -c -c -r1.98 libpq.sgml
*** doc/src/sgml/libpq.sgml    3 Nov 2002 01:30:46 -0000    1.98
--- doc/src/sgml/libpq.sgml    7 Nov 2002 23:14:22 -0000
***************
*** 1210,1216 ****
            Returns the command status string from the SQL command that
        generated the <structname>PGresult</structname>.
  <synopsis>
! char * PQcmdStatus(PGresult *res);
  </synopsis>
  </para>
  </listitem>
--- 1210,1216 ----
            Returns the command status string from the SQL command that
        generated the <structname>PGresult</structname>.
  <synopsis>
! const char * PQcmdStatus(const PGresult *res);
  </synopsis>
  </para>
  </listitem>
***************
*** 1220,1226 ****
  <function>PQcmdTuples</function>
        Returns the number of rows affected by the SQL command.
  <synopsis>
! char * PQcmdTuples(PGresult *res);
  </synopsis>
            If the <acronym>SQL</acronym> command that generated the
        <structname>PGresult</structname> was INSERT, UPDATE or DELETE, this returns a
--- 1220,1226 ----
  <function>PQcmdTuples</function>
        Returns the number of rows affected by the SQL command.
  <synopsis>
! const char * PQcmdTuples(const PGresult *res);
  </synopsis>
            If the <acronym>SQL</acronym> command that generated the
        <structname>PGresult</structname> was INSERT, UPDATE or DELETE, this returns a
Index: src/interfaces/libpq/fe-exec.c
===================================================================
RCS file: /cvsroot/pgsql-server/src/interfaces/libpq/fe-exec.c,v
retrieving revision 1.122
diff -c -c -r1.122 fe-exec.c
*** src/interfaces/libpq/fe-exec.c    4 Sep 2002 20:31:47 -0000    1.122
--- src/interfaces/libpq/fe-exec.c    7 Nov 2002 23:14:43 -0000
***************
*** 2234,2241 ****
          return 0;
  }

! char *
! PQcmdStatus(PGresult *res)
  {
      if (!res)
          return NULL;
--- 2234,2241 ----
          return 0;
  }

! const char *
! PQcmdStatus(const PGresult *res)
  {
      if (!res)
          return NULL;
***************
*** 2303,2310 ****
      if the last command was an INSERT/UPDATE/DELETE, return number
      of inserted/affected tuples, if not, return ""
  */
! char *
! PQcmdTuples(PGresult *res)
  {
      char        noticeBuf[128];

--- 2303,2310 ----
      if the last command was an INSERT/UPDATE/DELETE, return number
      of inserted/affected tuples, if not, return ""
  */
! const char *
! PQcmdTuples(const PGresult *res)
  {
      char        noticeBuf[128];

***************
*** 2315,2321 ****
          strncmp(res->cmdStatus, "DELETE", 6) == 0 ||
          strncmp(res->cmdStatus, "UPDATE", 6) == 0)
      {
!         char       *p = res->cmdStatus + 6;

          if (*p == 0)
          {
--- 2315,2321 ----
          strncmp(res->cmdStatus, "DELETE", 6) == 0 ||
          strncmp(res->cmdStatus, "UPDATE", 6) == 0)
      {
!         const char       *p = res->cmdStatus + 6;

          if (*p == 0)
          {
Index: src/interfaces/libpq/libpq-fe.h
===================================================================
RCS file: /cvsroot/pgsql-server/src/interfaces/libpq/libpq-fe.h,v
retrieving revision 1.86
diff -c -c -r1.86 libpq-fe.h
*** src/interfaces/libpq/libpq-fe.h    4 Sep 2002 20:31:47 -0000    1.86
--- src/interfaces/libpq/libpq-fe.h    7 Nov 2002 23:14:45 -0000
***************
*** 307,316 ****
  extern Oid    PQftype(const PGresult *res, int field_num);
  extern int    PQfsize(const PGresult *res, int field_num);
  extern int    PQfmod(const PGresult *res, int field_num);
! extern char *PQcmdStatus(PGresult *res);
  extern char *PQoidStatus(const PGresult *res);    /* old and ugly */
  extern Oid    PQoidValue(const PGresult *res);    /* new and improved */
! extern char *PQcmdTuples(PGresult *res);
  extern char *PQgetvalue(const PGresult *res, int tup_num, int field_num);
  extern int    PQgetlength(const PGresult *res, int tup_num, int field_num);
  extern int    PQgetisnull(const PGresult *res, int tup_num, int field_num);
--- 307,316 ----
  extern Oid    PQftype(const PGresult *res, int field_num);
  extern int    PQfsize(const PGresult *res, int field_num);
  extern int    PQfmod(const PGresult *res, int field_num);
! extern const char *PQcmdStatus(const PGresult *res);
  extern char *PQoidStatus(const PGresult *res);    /* old and ugly */
  extern Oid    PQoidValue(const PGresult *res);    /* new and improved */
! extern const char *PQcmdTuples(const PGresult *res);
  extern char *PQgetvalue(const PGresult *res, int tup_num, int field_num);
  extern int    PQgetlength(const PGresult *res, int tup_num, int field_num);
  extern int    PQgetisnull(const PGresult *res, int tup_num, int field_num);

pgsql-interfaces by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: pgtcl: Change in behavior of pg_result -oid, vs documentation
Next
From: "Jan Klostermann"
Date:
Subject: Wish to build a LabVIEW-Interface (= graphical programming language)