Perl: Net::MySQL affected_rows_length

I just came across this minor issue in the pure Perl MySQL module Net::MySQL. There are a few open bugs, not much activity on the bug-tracker so who knows if this gets fixed — submitted it anyway.

Assuming an error like 1452 happened after a successful insert statement that inserted eg. 1 row. If you now use get_affected_rows_length, you still get 1 instead of 0. You should get 0, as the last executed query did affect 0 rows, because of a foreign key constraint.

The fix is easy — just set affected_rows_length to 0 in  _reset_status():

Index: Net/MySQL.pm
===================================================================
--- Net/MySQL.pm	(revision 1)
+++ Net/MySQL.pm	(working copy)
@@ -449,6 +449,7 @@
 	$self->{server_message}  = '';
 	$self->{error_code}      = undef;
 	$self->{selected_record} = undef;
+	$self->{affected_rows_length} = 0;
 }
  • email
  • PDF
  • Google Bookmarks
  • Yahoo! Bookmarks
  • del.icio.us
  • Twitter
  • Reddit
  • Digg
  • Ping.fm
  • Slashdot
  • Facebook
  • MySpace
  • Technorati
  • NewsVine
  • Tumblr
  • StumbleUpon

One Response to “Perl: Net::MySQL affected_rows_length”

  1. Perl: Net::MySQL “packets out of order” | florian.demmer.org writes:

    [...] another issue with Net::MySQL (after this one). Why are we using that again? Ah yes, it’s pure Perl and we hate compiling modules. [...]

Leave a Reply