On 9/24/07, kapil.V <[EMAIL PROTECTED]> wrote: snip > my $insert_query = qq{ > UPDATE hosts SET last_checked = '$date' WHERE hostname = > '$host'; > }; > $sth = $db -> prepare($insert_query) > or die "Could not prepare the statement: ".$db -> errstr;; > $sth -> execute or die "Could not execute query\n"; snip > The code runs without any warnings/errors, but the database is not touched. > What is wrong? snip
Updates do not fail if they do not update anything. The execute method returns "0E0" which is numerically equivalent to 0, but is treated as true by Perl. If you wish an update to fail if it did not update anything you must say something like $sth->execute > 0 or die "no rows were updated"; Also, please note these things * You should be using the strict pragma. This will prevent many subtle bugs. * You should never call an update an "insert_query". Are you trying to make your code unreadable? * There is no point in having RaiseError turned off if you are just going to die on errors anyway. Just turn on RaiseError and use eval {} to catch the errors you want to handle differently. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/