Sunday, January 10, 2010 at 4:21 am
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;
}


No. 1 — January 31st, 2010 at 1:44 am
[...] 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. [...]