I was looking for a function to return the number of tuples an update
returned, but couldn't find anything for libpq++. Any ideas?

I also noticed a bug in the docs worth mentioning...
http://postgresql.nextpath.com/doxlist.html

        PgDatabase data;
        data.exec("create table foo (a int4, b char16, d float8)");
        data.exec("copy foo from stdin");
        data.putline("3\etHello World\et4.5\en");
        data.putline("4\etGoodbye World\et7.11\en");
        &...
        data.putline(".\en");
        data.endcopy();

There is no PgDatabase::exec


thanks
-Michael


Wed, 30 Jun 1999 01:57:55 -0300 (ADT)
Michael Richards <miker@scifair.acadiau.ca>
Getting number of tuples affected
On Wed, 30 Jun 1999, Michael Richards wrote:

> I was looking for a function to return the number of tuples an update
> returned, but couldn't find anything for libpq++. Any ideas?

Added to my list of stuff to do.  As to what else you can do, submit
patches? :)

> I also noticed a bug in the docs worth mentioning...
> http://postgresql.nextpath.com/doxlist.html
> 
>         PgDatabase data;
>         data.exec("create table foo (a int4, b char16, d float8)");
>         data.exec("copy foo from stdin");
>         data.putline("3\etHello World\et4.5\en");
>         data.putline("4\etGoodbye World\et7.11\en");
>         &...
>         data.putline(".\en");
>         data.endcopy();
> 
> There is no PgDatabase::exec

Yep.  Guess that should be data.Exec(...

Thanks!
Vince.
-- 
==========================================================================
Vince Vielhaber -- KA8CSH   email: vev@michvhf.com   flame-mail: /dev/null
       # include <std/disclaimers.h>                   TEAM-OS2
        Online Campground Directory    http://www.camping-usa.com
       Online Giftshop Superstore    http://www.cloudninegifts.com
==========================================================================




Wed, 30 Jun 1999 06:27:30 -0400 (EDT)
Vince Vielhaber <vev@michvhf.com>
Re: [HACKERS] Getting number of tuples affected
On Wed, 30 Jun 1999, Vince Vielhaber wrote:

> > I was looking for a function to return the number of tuples an update
> > returned, but couldn't find anything for libpq++. Any ideas?
> 
> Added to my list of stuff to do.  As to what else you can do, submit
> patches? :)

> > There is no PgDatabase::exec
> Yep.  Guess that should be data.Exec(...
Not sure there is an Exec either :)

I've been making a pile of changes to the PgDatabase class. (Actually I
derived it). One such change is a function to quote a string you're going
to use in SQL. I'm not sure if this belongs in the PgDatabase class, but
if you think so, I'll add it before I submit the tuple count patches.

This allows me to do something like:
String updatesql(form("UPDATE users SET lastrequest='now' WHERE 
loginid=%s",dbh->quote(_username).chars()));
cout << dbh->ExecTuplesOk(updatesql);

That is actually the call I needed the update count to ensure it worked...

Here is the routine:

// routine to quote any \ or ' chars in the passed string
// this isn't too efficient, but how much data are we really quoting?
String TDatabase::quote(const char *dirty) {
  // start with a single quote
  String clean("'");

  const char *strptr=dirty;
  // escape the string if it contains any ' or \ chars
  while (*strptr) {
    if ((*strptr=='\'') || (*strptr=='\\')) 
      clean+='\\'; 
    
    clean+=*(strptr++); 
  }
  // end with a quote
  clean+="'";

  return clean;
}


-Michael


Wed, 30 Jun 1999 11:28:43 -0300 (ADT)
Michael Richards <miker@scifair.acadiau.ca>
Re: [HACKERS] Getting number of tuples affected
On Wed, 30 Jun 1999, Michael Richards wrote:

> On Wed, 30 Jun 1999, Vince Vielhaber wrote:
> 
> > > I was looking for a function to return the number of tuples an update
> > > returned, but couldn't find anything for libpq++. Any ideas?
> > 
> > Added to my list of stuff to do.  As to what else you can do, submit
> > patches? :)
> 
> > > There is no PgDatabase::exec
> > Yep.  Guess that should be data.Exec(...
> Not sure there is an Exec either :)

It's inherited.

> 
> I've been making a pile of changes to the PgDatabase class. (Actually I
> derived it). One such change is a function to quote a string you're going
> to use in SQL. I'm not sure if this belongs in the PgDatabase class, but
> if you think so, I'll add it before I submit the tuple count patches.

I don't think it belongs in PgDatabase.  I'm not even sure it belongs in
libpq++, although I can see its usefulness.

Vince.
-- 
==========================================================================
Vince Vielhaber -- KA8CSH   email: vev@michvhf.com   flame-mail: /dev/null
       # include <std/disclaimers.h>                   TEAM-OS2
        Online Campground Directory    http://www.camping-usa.com
       Online Giftshop Superstore    http://www.cloudninegifts.com
==========================================================================





Wed, 30 Jun 1999 10:41:30 -0400 (EDT)
Vince Vielhaber <vev@michvhf.com>
Re: [HACKERS] Getting number of tuples affected
Hi.
Here are some diffs that implement a function called TuplesAffected. It
returns the number of tuples the last command affected, or 0 if the last
command was a SELECT. I added it to the PgConnection because it contains
the Exec method as well as the PQresult structure. Maybe farther down in
the inheritance there should be a function that executes a query and
returns the number of tuples affected or returned (according to whether it
was a select or not) or a -1 on error.

Patches are attached...

-Michael
Wed, 30 Jun 1999 14:27:46 -0300 (ADT)
Michael Richards <miker@scifair.acadiau.ca>
Patches to get number of tuples affected
Thus spake Michael Richards
> Here are some diffs that implement a function called TuplesAffected. It
> returns the number of tuples the last command affected, or 0 if the last
> command was a SELECT. I added it to the PgConnection because it contains

Why not overload PGTuples() instead (assuming it doesn't already do this)?

-- 
D'Arcy J.M. Cain <darcy@{druid|vex}.net>   |  Democracy is three wolves
http://www.druid.net/darcy/                |  and a sheep voting on
+1 416 424 2871     (DoD#0082)    (eNTP)   |  what's for dinner.

Wed, 30 Jun 1999 14:15:09 -0400 (EDT)
"D'Arcy" "J.M." Cain <darcy@druid.net>
Re: [PATCHES] Patches to get number of tuples affected
On Wed, 30 Jun 1999, D'Arcy J.M. Cain wrote:

> Thus spake Michael Richards
> > Here are some diffs that implement a function called TuplesAffected. It
> > returns the number of tuples the last command affected, or 0 if the last
> > command was a SELECT. I added it to the PgConnection because it contains
> 
> Why not overload PGTuples() instead (assuming it doesn't already do this)?

Tuples returned tells you how many you can get using the getvalue series.
If you tried that with an update, it core dumps. I think the two are
really related, but fundamentally different.

-Michael


Wed, 30 Jun 1999 15:36:00 -0300 (ADT)
Michael Richards <miker@scifair.acadiau.ca>
Re: [PATCHES] Patches to get number of tuples affected
Thus spake Michael Richards
> > Why not overload PGTuples() instead (assuming it doesn't already do this)?

As mentioned in another posting, I meant PQntuples().

> Tuples returned tells you how many you can get using the getvalue series.
> If you tried that with an update, it core dumps. I think the two are
> really related, but fundamentally different.

I'm just thinking that it's easy for PQntuples() to tell what it has
to return and branch accordingly.  It just makes it easier to remember
the function.  No asking which get tuple count function works for update
and which for select.

-- 
D'Arcy J.M. Cain <darcy@{druid|vex}.net>   |  Democracy is three wolves
http://www.druid.net/darcy/                |  and a sheep voting on
+1 416 424 2871     (DoD#0082)    (eNTP)   |  what's for dinner.

Wed, 30 Jun 1999 15:20:50 -0400 (EDT)
"D'Arcy" "J.M." Cain <darcy@druid.net>
Re: [PATCHES] Patches to get number of tuples affected