Hi there Monks,
Lately I've been working a lot with storing CSV content (after some parsing of the data) in a database. In a lot of cases the data allready is in the database, in which case I want to update it. Familiar problem I guess. I came up with this solution:
connectDB(); my $insert = "Insert Into table (id,name) Values (?,?)"; my $update = "Update table set name = ? Where id=?"; my $sth_insert = $dbh->prepare($insert) or die $dbh->errstr; my $sth_update = $dbh->prepare($update) or die $dbh->errstr; for my $data (@$data_ref){ if (! $sth_insert->execute( $$data{'id'}, $$data{'name'} ) ){ print 'Insert error: '.$sth_insert->errstr if $debug; print "Doing update\n"; $sth_update->execute( $$data{'name'}, $$data{'id'} ) or die("Insert and Update failed, update: +".$sth_update->errstr ); } } $sth_insert->finish(); $sth_update->finish(); disconnectDB();
As it turns out the $sth_update is never executed, or at least the database does not reflect it... The insert goes as expected. I do get the "Doing update" message. Any ideas on what Im doing wrong here?
In reply to My update on insert error solution by PeterKaagman
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |