Re: [HACKERS] Getting number of tuples affected - Mailing list pgsql-hackers

From Michael Richards
Subject Re: [HACKERS] Getting number of tuples affected
Date
Msg-id Pine.BSF.4.10.9906301124010.12242-100000@scifair.acadiau.ca
Whole thread Raw
In response to Re: [HACKERS] Getting number of tuples affected  (Vince Vielhaber <vev@michvhf.com>)
Responses Re: [HACKERS] Getting number of tuples affected
List pgsql-hackers
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



pgsql-hackers by date:

Previous
From: Vince Vielhaber
Date:
Subject: Re: Vaccum (Was: Re: [HACKERS] Hot Backup Ability)
Next
From: Tom Lane
Date:
Subject: Re: [HACKERS] regression bigtest needs very long time