Timeline for Mysql PDO Wrapper that throws Unique Constraint Exception
Current License: CC BY-SA 4.0
16 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Mar 30, 2021 at 21:43 | vote | accept | bumperbox | ||
Mar 29, 2021 at 6:36 | comment | added | Rick James | Use transactions to deal with race conditions. | |
Mar 29, 2021 at 6:35 | comment | added | Rick James | What about a husband and wife who share a computer and an email account but want to login separately? | |
Jan 25, 2021 at 17:44 | answer | added | Your Common Sense | timeline score: 4 | |
Jan 25, 2021 at 17:29 | comment | added | Your Common Sense | @Anonymous database locks are evil and you should avoid them when possible. The op has the correct approach to the problem and introduction table locks will make it much worse. Not to mention that there is no UPDATE query can be seen | |
Jan 25, 2021 at 17:14 | history | edited | Sᴀᴍ Onᴇᴌᴀ♦ |
edited tags
|
|
Jan 25, 2021 at 17:14 | answer | added | Sᴀᴍ Onᴇᴌᴀ♦ | timeline score: 3 | |
Oct 7, 2020 at 22:42 | comment | added | bumperbox | @slepic I didn't know that, I will try it out, thanks | |
Oct 6, 2020 at 14:37 | comment | added | slepic | "For index records the search encounters, locks the rows and any associated index entries" So if there is a unique index, it gets locked and modification of the row or the index (range) is not possible until the transaction ends. And this applies even if there is no such row, the index entry is virtual, yet part of the locked index range. | |
Oct 4, 2020 at 18:45 | comment | added | bumperbox | I don't quite understand how SELECT FOR UPDATE would help in the case of inserting a user with a duplicate email address? If the email address doesn't exist in the db, there will be no row to select? | |
Oct 4, 2020 at 13:15 | comment | added | Kate | Database locks are meant to avoid race conditions. In Mysql you may want to use SELECT FOR UPDATE for example, at least if your tables are InnoDB. | |
Oct 4, 2020 at 9:08 | comment | added | bumperbox | approx 15 uses in total across 5 projects. I was under the impression using the db constraint was the correct approach. Take for example users signing up, with a unique email address. I could go and select the user first to see if the email exists, but that would result in a race condition (however unlikely). I would like to be able to detect and handle that particular exception differently, which is why it isn't just a generic exception. | |
Oct 3, 2020 at 0:00 | history | tweeted | twitter.com/StackCodeReview/status/1312180715514068994 | ||
Oct 2, 2020 at 22:22 | comment | added | Kate | Do you run into this situation often ? Isn't is better to fix existing code to avoid the exception, rather than having to handle it ? Last but not least, is your exception class doing anything special that a generic, application-wide exception handler could not do ? | |
Oct 2, 2020 at 20:57 | history | edited | bumperbox | CC BY-SA 4.0 |
deleted 6 characters in body
|
Oct 2, 2020 at 20:00 | history | asked | bumperbox | CC BY-SA 4.0 |