in reply to Perl and SQL issue.
As an aside, you should use strict - it makes it possible for Perl to tell you about typos in your code.
A while() loop never starts if the condition is false. You most likely want to use a different construct then, if you want your code to behave differently, or, if your database driver returns a reliable rowcount from the ->execute method, use that:
Variant 1 - database returns a reliable rowcount
my $count = $sth->execute; if (! $count) { die "Couldn't execute >>$sql<< : " . $sth->errstr; }; if ($count == 0) { print "No rows were affected."; } else { while (my $pointer = $sth->fetchrow_hashref) { ... do magic ... }; };
Variant 2 - the DB driver does not return a reliable rowcount
my $res = $sth->execute; if (! $res) { die "Couldn't execute >>$sql<< : " . $sth->errstr; }; my $rows = 0; while (my $pointer = $sth->fetchrow_hashref) { ... do magic ... $rows++; }; if (! $rows) { print "No rows were affected."; };
|
|---|