Don't rely on hasKey as it is using the cache.
Always try UPDATE first. Get affected rows.
If 0 affected rows, try INSERT. Get affected rows.
If 0 affected rows, throw error (give user the chance to make a decision, e.g. retry).