That is what transactions are for. Bracket your check and insert procedure in a transaction which you can roll back in case of duplicate values.
smantscheff
Nearly a Posting Virtuoso
1,233 posts since Oct 2010
Reputation Points: 300
Solved Threads: 254
1) Start the transaction.
2) Do your processing and send a flag if a notification must be sent.
3a) Commit the transaction OR
3b) Unset the notification flag and roll back the transaction.
4) Check if the notification flag is set and sent the email accordingly.
smantscheff
Nearly a Posting Virtuoso
1,233 posts since Oct 2010
Reputation Points: 300
Solved Threads: 254
Either you send a notification email or you don't. If you do depends on the logic of your program. This has nothing to do with "safety" - if it has, your algorithm is flawed.
smantscheff
Nearly a Posting Virtuoso
1,233 posts since Oct 2010
Reputation Points: 300
Solved Threads: 254
Any function can result in an error. Your code has to deal with that possibility.
Without knowing your algorithm or seeing some pseudo-code of it I cannot help you any further.
smantscheff
Nearly a Posting Virtuoso
1,233 posts since Oct 2010
Reputation Points: 300
Solved Threads: 254