pg.ddx.io pgsql-interfaces@postgresql.org mailing list archive
help / color / mirror / Atom feedPQcmdTuples() declaration
7+ messages / 4 participants
[nested] [flat]
* PQcmdTuples() declaration
@ 2002-11-05 16:54 Michael Klatt <mdklatt@ou.edu>
2002-11-07 14:23 ` Re: PQcmdTuples() declaration Payman <payman@Club-Internet.fr>
0 siblings, 1 reply; 7+ messages in thread
From: Michael Klatt @ 2002-11-05 16:54 UTC (permalink / raw)
To: 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."
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: PQcmdTuples() declaration
2002-11-05 16:54 PQcmdTuples() declaration Michael Klatt <mdklatt@ou.edu>
@ 2002-11-07 14:23 ` Payman <payman@Club-Internet.fr>
2002-11-07 16:58 ` Re: PQcmdTuples() declaration Bruce Momjian <pgman@candle.pha.pa.us>
2002-11-08 05:11 ` Re: PQcmdTuples() declaration Bruce Momjian <pgman@candle.pha.pa.us>
0 siblings, 2 replies; 7+ messages in thread
From: Payman @ 2002-11-07 14:23 UTC (permalink / raw)
To: Michael Klatt <mdklatt@ou.edu>; +Cc: 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.
>
>
>
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: PQcmdTuples() declaration
2002-11-05 16:54 PQcmdTuples() declaration Michael Klatt <mdklatt@ou.edu>
2002-11-07 14:23 ` Re: PQcmdTuples() declaration Payman <payman@Club-Internet.fr>
@ 2002-11-07 16:58 ` Bruce Momjian <pgman@candle.pha.pa.us>
1 sibling, 0 replies; 7+ messages in thread
From: Bruce Momjian @ 2002-11-07 16:58 UTC (permalink / raw)
To: Payman <payman@Club-Internet.fr>; +Cc: Michael Klatt <mdklatt@ou.edu>; 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@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
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: PQcmdTuples() declaration
2002-11-05 16:54 PQcmdTuples() declaration Michael Klatt <mdklatt@ou.edu>
2002-11-07 14:23 ` Re: PQcmdTuples() declaration Payman <payman@Club-Internet.fr>
@ 2002-11-08 05:11 ` Bruce Momjian <pgman@candle.pha.pa.us>
2002-11-08 09:25 ` Re: PQcmdTuples() declaration Payman <payman@Club-Internet.fr>
2002-11-08 15:15 ` Re: PQcmdTuples() declaration Tom Lane <tgl@sss.pgh.pa.us>
1 sibling, 2 replies; 7+ messages in thread
From: Bruce Momjian @ 2002-11-08 05:11 UTC (permalink / raw)
To: Payman <payman@Club-Internet.fr>; +Cc: Michael Klatt <mdklatt@ou.edu>; 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
Attachments:
/pgpatches/libpq_const (text/plain, 4.5K) download
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);
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: PQcmdTuples() declaration
2002-11-05 16:54 PQcmdTuples() declaration Michael Klatt <mdklatt@ou.edu>
2002-11-07 14:23 ` Re: PQcmdTuples() declaration Payman <payman@Club-Internet.fr>
2002-11-08 05:11 ` Re: PQcmdTuples() declaration Bruce Momjian <pgman@candle.pha.pa.us>
@ 2002-11-08 09:25 ` Payman <payman@Club-Internet.fr>
1 sibling, 0 replies; 7+ messages in thread
From: Payman @ 2002-11-08 09:25 UTC (permalink / raw)
To: Bruce Momjian <pgman@candle.pha.pa.us>; +Cc: Michael Klatt <mdklatt@ou.edu>; 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?
>
>
>
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: PQcmdTuples() declaration
2002-11-05 16:54 PQcmdTuples() declaration Michael Klatt <mdklatt@ou.edu>
2002-11-07 14:23 ` Re: PQcmdTuples() declaration Payman <payman@Club-Internet.fr>
2002-11-08 05:11 ` Re: PQcmdTuples() declaration Bruce Momjian <pgman@candle.pha.pa.us>
@ 2002-11-08 15:15 ` Tom Lane <tgl@sss.pgh.pa.us>
2002-11-08 15:55 ` Re: PQcmdTuples() declaration Bruce Momjian <pgman@candle.pha.pa.us>
1 sibling, 1 reply; 7+ messages in thread
From: Tom Lane @ 2002-11-08 15:15 UTC (permalink / raw)
To: Bruce Momjian <pgman@candle.pha.pa.us>; +Cc: Payman <payman@Club-Internet.fr>; Michael Klatt <mdklatt@ou.edu>; pgsql-interfaces
Bruce Momjian <pgman@candle.pha.pa.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
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: PQcmdTuples() declaration
2002-11-05 16:54 PQcmdTuples() declaration Michael Klatt <mdklatt@ou.edu>
2002-11-07 14:23 ` Re: PQcmdTuples() declaration Payman <payman@Club-Internet.fr>
2002-11-08 05:11 ` Re: PQcmdTuples() declaration Bruce Momjian <pgman@candle.pha.pa.us>
2002-11-08 15:15 ` Re: PQcmdTuples() declaration Tom Lane <tgl@sss.pgh.pa.us>
@ 2002-11-08 15:55 ` Bruce Momjian <pgman@candle.pha.pa.us>
0 siblings, 0 replies; 7+ messages in thread
From: Bruce Momjian @ 2002-11-08 15:55 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Payman <payman@Club-Internet.fr>; Michael Klatt <mdklatt@ou.edu>; pgsql-interfaces
Tom Lane wrote:
> Bruce Momjian <pgman@candle.pha.pa.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@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
^ permalink raw reply [nested|flat] 7+ messages in thread
end of thread, other threads:[~2002-11-08 15:55 UTC | newest]
Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-11-05 16:54 PQcmdTuples() declaration Michael Klatt <mdklatt@ou.edu>
2002-11-07 14:23 ` Payman <payman@Club-Internet.fr>
2002-11-07 16:58 ` Bruce Momjian <pgman@candle.pha.pa.us>
2002-11-08 05:11 ` Bruce Momjian <pgman@candle.pha.pa.us>
2002-11-08 09:25 ` Payman <payman@Club-Internet.fr>
2002-11-08 15:15 ` Tom Lane <tgl@sss.pgh.pa.us>
2002-11-08 15:55 ` Bruce Momjian <pgman@candle.pha.pa.us>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox