in reply to Re: Updating or Inserting a database from a txt file
in thread Updating or Inserting a database from a txt file
I agree, REPLACE would be better.
If you want to use the fact the execute command failed to detect duplicate entries, you should capture the actual error code, rather than blindly trying an update on any error.
if ($DBI::err) { if ($DBI::err eq '1062') { # taken from mysqld_error.h # duplicate.. try an update unless ($update->execute( $gamedesc, $gamename )) { die sprintf('UPDATE failed: %s %s', $gamename, $DBI::errstr); } } else { die sprintf('INSERT failed: %s %s', $gamename, $DBI::errstr); } }
|
|---|