Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > rows affected not working..

Reply
Thread Tools

rows affected not working..

 
 
Faith Greenwood
Guest
Posts: n/a
 
      08-11-2009
Hi,

I am making some changes to my mysql table via DBI (I am inserting the
ages of the people I already have in the table). I have the following:

my $sql="UPDATE table SET age=? WHERE name=?";
my $sth=$dbh->prepare($sql);
$sth->execute($age,$name) or warn "$DBI::errstr\n" and next;
my $rc = $sth->rows;

I have 100 records total. Of course, when I run this script the first
time I update the age column of every single person in the table and
$rc=1 for each of the 100 rows. However, running the script the 2nd
time (without changing any of the ages), I still get $rc=1 for each of
the 100 rows (it should be zero, since the row actually wasn't
updated).

To check, I updated a record via phpmyadmin and got 0 rows affected
(like it should). Why is Perl giving me the wrong response? More
importantly, how do I correct it?

thx!
 
Reply With Quote
 
 
 
 
Peter Wyzl
Guest
Posts: n/a
 
      08-11-2009
"Faith Greenwood" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
>
> I am making some changes to my mysql table via DBI (I am inserting the
> ages of the people I already have in the table). I have the following:
>
> my $sql="UPDATE table SET age=? WHERE name=?";
> my $sth=$dbh->prepare($sql);
> $sth->execute($age,$name) or warn "$DBI::errstr\n" and next;
> my $rc = $sth->rows;
>
> I have 100 records total. Of course, when I run this script the first
> time I update the age column of every single person in the table and
> $rc=1 for each of the 100 rows. However, running the script the 2nd
> time (without changing any of the ages), I still get $rc=1 for each of
> the 100 rows (it should be zero, since the row actually wasn't
> updated).
>
> To check, I updated a record via phpmyadmin and got 0 rows affected
> (like it should). Why is Perl giving me the wrong response? More
> importantly, how do I correct it?


If you are using DBD::mysql (usually invoked by use DBI and defining the
mysql database) you should check the value of mysql_client_found_rows
(check the DBD::mysql docs at
http://search.cpan.org/~capttofu/DBD...b/DBD/mysql.pm)

I suspect you may have it set to TRUE but be expecting the result from
having it set to FALSE.

I could also be completely off the planet...

P


 
Reply With Quote
 
 
 
 
Faith Greenwood
Guest
Posts: n/a
 
      08-12-2009
On Aug 11, 8:56*am, "Peter Wyzl" <(E-Mail Removed)> wrote:
> "Faith Greenwood" <(E-Mail Removed)> wrote in message
>
> news:(E-Mail Removed)...
>
>
>
> > Hi,

>
> > I am making some changes to my mysql table via DBI (I am inserting the
> > ages of the people I already have in the table). I have the following:

>
> > my $sql="UPDATE table SET age=? WHERE name=?";
> > my $sth=$dbh->prepare($sql);
> > $sth->execute($age,$name) or warn "$DBI::errstr\n" and next;
> > my $rc = $sth->rows;

>
> > I have 100 records total. Of course, when I run this script the first
> > time I update the age column of every single person in the table and
> > $rc=1 for each of the 100 rows. However, running the script the 2nd
> > time (without changing any of the ages), I still get $rc=1 for each of
> > the 100 rows (it should be zero, since the row actually wasn't
> > updated).

>
> > To check, I updated a record via phpmyadmin and got 0 rows affected
> > (like it should). Why is Perl giving me the wrong response? More
> > importantly, how do I correct it?

>
> If you are using DBD::mysql (usually invoked by use DBI and defining the
> mysql database) you should check the value of mysql_client_found_rows
> (check the DBD::mysql docs athttp://search.cpan.org/~capttofu/DBD-mysql-4..012/lib/DBD/mysql.pm)
>
> I suspect you may have it set to TRUE but be expecting the result from
> having it set to FALSE.
>
> I could also be completely off the planet...
>
> P


thanks guys! I think I will go with $sql="UPDATE table SET age=? WHERE
name=? AND age!=?" as suggested...I just am looking for something that
will alert me when the age has changed and this seems to work and to
be honest I am too tired of this project to really care at this point
so I'll just go with the easiest solution. At some point I will look
more into the client_found_rows.......thx again!
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Possible to determine number of rows affected by a SQLite updateor delete command? Kushal Kumaran Python 0 11-30-2010 09:21 AM
mysql "rows affected" Carl K Python 4 04-29-2007 07:22 PM
IrfanView is not affected by the MS JPEG vulnerability. norm Digital Photography 41 01-16-2006 05:20 PM
Major host iPowerweb refuses to support Mozilla / Firefox - 240,000 sites affected js17@cavelle.com Firefox 3 01-21-2005 05:32 PM
Re: CatOS security advisory: are we affected? sPiDEr Cisco 2 07-11-2003 01:14 AM



Advertisments