I have a MySQL Database and I use functions to convert readable values into their associated table IDs, and return that ID.
If an ID isn’t returned, the database will insert the value instead, and use the last inserted row ID.
The problem I have, is I keep getting errors saying unique key violations due to duplicate records.
I’ve done some tests:
- Run the function, checking for a new value, returns NULL (expected)
- Insert the new item into the database, obtains an new ID of 1 (expected)
- Rerun the function to see if the ID now returns, it doesn’t (unexpected)
All of the above is in a single query/transaction. It’s part of a process I’m trying to make it easier to add new referential data.
Am I missing something here?