I have a question concerning general syntax of a Transaction block. My application is written in ColdFusion and my table in question is InnoDB.
Currently we have a non-auto-incrementing PK. My DBA instructed me this cannot change for some time.
So to retrieve the next available key to use, I run a SELECT:
I have code that uses this selection as the id to be inserted.
This will produce an error when two people attempt to insert a record into this table with identical keys.
The pseudo code for my transaction block should flow like so:
If there is a better way (perhaps looping until a successful INSERT- please call me out)
Does anyone know how to present this in logical SQL? Thanks in advance.
[blue]Go to work to learn. Don't go to work to earn.[/blue]
Currently we have a non-auto-incrementing PK. My DBA instructed me this cannot change for some time.
So to retrieve the next available key to use, I run a SELECT:
Code:
SELECT (id + 1) AS id
FROM tradingPartners
ORDER BY id DESC
I have code that uses this selection as the id to be inserted.
This will produce an error when two people attempt to insert a record into this table with identical keys.
The pseudo code for my transaction block should flow like so:
Code:
1. Retrieve Max available ID (unique)
2. Insert record using this ID
3. Rollback if error occurs
4. Alert user what happened
If there is a better way (perhaps looping until a successful INSERT- please call me out)
Does anyone know how to present this in logical SQL? Thanks in advance.
[blue]Go to work to learn. Don't go to work to earn.[/blue]