I'm writing a script using a MySQL database. I'm running an update query like this:
$rows_affected = $dbh->do("UPDATE meters SET description=? WHERE name= +?", undef, $info, $meter);

Sometimes this query is issued with $info equal to the value already stored in that description field. The strange part is that $rows_affected is getting set to 1 even if $info is exactly the same as the existing value! I logged into the database manually and ran the query, which returned:

Query OK, 0 rows affected (0.00 sec) Rows matched: 1 Changed: 0 Warnings: 0

MySQL and Perl for the Web (p.37, footnote) says that "affected by" means "changed", and that do() should indeed return 0 in this case, unless I have ";mysql_client_found_rows=1" set, which I do not.

Guesses? Clues? Answers? Berating? I wish I had more information to provide about the problem...

Many thanks,
LassiLantar

Update: Fixed it, as per suggestion, by making the WHERE clause read  ...WHERE name=? AND description=?", undef, $info, $meter, $info... Which resulted in return values of 0E0. Anyone know why MySQL or DBI is refusing to return just plain 0 in this case, and why it's returning 1 without the extra check?


In reply to Odd "rows affected" values using DBI on MySQL by LassiLantar

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.