Not sure if this belongs here or elsewhere, but I'm desperate so hoping someone here can help, I've done searches for everything I can think of but can't find it.
Here is the issue,
I have an address table where because of DB2 constraints (V7 I think?) I cannot have all the address fields as the unique key, as such I have a "non-business" unique key, and then the program that writes records to the table checks for uniqueness on the other fields before it inserts a record. For the sake of simplicity assume the table has three columns, the
key (integer, non-business object)
City (varchar(30))
State (varchar(2))
The situation I have is that two uncommited transactions are attempting to write to this table at exactly the same time with exactly the same business data, as such both do a read on all the commited transactions, find no record, both generate a key (random number) and then both create a record, so I end up breaking my "program imposed" uniqueness.
The only way around this that I can think of currently is to have the read to check for uniqueness do an uncommited read as well as a commited read, and wait for the number of records returned to be the same, at that point I'll know that nothing has "pending" records (I can't just make it an uncommited read in case the uncommited transaction ends up getting rolled back).
Does anyone else have any clever solutions (or even understand what I'm talking about)?
Many thanks for any suggestions, hopefully this makes some sense. In case it matters the program is written in Cobol, and I think I am on DB2 V7 (but that is not something I can change, although if future versions have functionality that would help I may be able to use that as a good reason that I should upgrade).