PQcmdTuples() declaration

Lists: pgsql-interfaces
From: Michael Klatt <mdklatt(at)ou(dot)edu>
To: pgsql-interfaces(at)postgresql(dot)org
Subject: PQcmdTuples() declaration
Date: 2002-11-05 16:54:11
Message-ID: NCBBLFLGLEIDHCJLONHNKEDGFJAA.mdklatt@ou.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-interfaces

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.

___________________________________
Michael Klatt

University of Oklahoma
Environmental Verification and Analysis Center
3200 Marshall Avenue, Suite 110
Norman, OK 73072-8032

405.447.8412
405.447.8455 FAX
http://www.evac.ou.edu/

"It's easy to be virtuous when you can't afford the vice."


From: Payman <payman(at)Club-Internet(dot)fr>
To: Michael Klatt <mdklatt(at)ou(dot)edu>
Cc: pgsql-interfaces(at)postgresql(dot)org
Subject: Re: PQcmdTuples() declaration
Date: 2002-11-07 14:23:32
Message-ID: 3DCA7764.8070404@Club-Internet.fr
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-interfaces

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.
>
>
>


From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Payman <payman(at)Club-Internet(dot)fr>
Cc: Michael Klatt <mdklatt(at)ou(dot)edu>, pgsql-interfaces(at)postgresql(dot)org
Subject: Re: PQcmdTuples() declaration
Date: 2002-11-07 16:58:39
Message-ID: 200211071658.gA7Gwd522837@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-interfaces


Good catch. It looks like PQcmdStatus and PQcmdStatus are both wrong.
They should be 'const' in the code. I will fix that in 7.4.

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

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(at)postgresql(dot)org
>

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073


From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Payman <payman(at)Club-Internet(dot)fr>
Cc: Michael Klatt <mdklatt(at)ou(dot)edu>, pgsql-interfaces(at)postgresql(dot)org
Subject: Re: PQcmdTuples() declaration
Date: 2002-11-08 05:11:01
Message-ID: 200211080511.gA85B2K11157@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: 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(at)postgresql(dot)org
>

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073

Attachment Content-Type Size
unknown_filename text/plain 4.5 KB

From: Payman <payman(at)Club-Internet(dot)fr>
To: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
Cc: Michael Klatt <mdklatt(at)ou(dot)edu>, pgsql-interfaces(at)postgresql(dot)org
Subject: Re: PQcmdTuples() declaration
Date: 2002-11-08 09:25:04
Message-ID: 3DCB82F0.4070607@Club-Internet.fr
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-interfaces

Hi Bruce,

The code compile ok, PGresult *res is not changed
in source code of PQcmdTuples, for me it's a const PGresult *res.
Now the probleme is : who put it in non const and why ?
Is changing this will cause problems in actual project for anyone?

Other thing is, PQcmdTuples return numbre of tuples after a insert,
delete, update
I say Number, Number is a numerical value and not String value ...

in libpq++ :
int PgDatabase::CmdTuples() const
{
const char *a = PQcmdTuples(pgResult);
return a[0] ? atoi(a) : -1;
}

return int value and not char *
(changing this cause more problems for other users...)

thanks
Payman

Bruce Momjian wrote:

>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?
>
>
>


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
Cc: Payman <payman(at)Club-Internet(dot)fr>, Michael Klatt <mdklatt(at)ou(dot)edu>, pgsql-interfaces(at)postgresql(dot)org
Subject: Re: PQcmdTuples() declaration
Date: 2002-11-08 15:15:12
Message-ID: 5860.1036768512@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-interfaces

Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> writes:
> 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?

Adding a const to the result type will break client applications that
aren't expecting it. I don't think we can get away with that.

We could still declare the input type as const if we were willing to
cast away const inside the functions, but that seems pretty ugly.

regards, tom lane


From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Payman <payman(at)Club-Internet(dot)fr>, Michael Klatt <mdklatt(at)ou(dot)edu>, pgsql-interfaces(at)postgresql(dot)org
Subject: Re: PQcmdTuples() declaration
Date: 2002-11-08 15:55:11
Message-ID: 200211081555.gA8FtBa03406@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-interfaces

Tom Lane wrote:
> Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> writes:
> > 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?
>
> Adding a const to the result type will break client applications that
> aren't expecting it. I don't think we can get away with that.
>
> We could still declare the input type as const if we were willing to
> cast away const inside the functions, but that seems pretty ugly.

Yep, seems pretty ugly to me too. Why bother calling it a const if we
are going to cast it away.

I have updated the docs for 7.3 and CVS to match the non-const code.
Let's see if this issue comes up again.

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073