By the time being I've no environment to test this. Anyway, it seems to be an issue strictly related to MySQL development rather than its usage, as it should be even better to use a replace rather than a delete/insert.
What is the effect you notice by using an alternative syntax? EG: INSERT ... ON DUPLICATE KEY UPDATE