Using ASP.net I'm trying to set up a basic online shop. I've set up a database in MySql that has a variety of tables in it.
(Customers, Suppliers, Products etc)
I've set up a table called Quotes in order to keep track of "online" quotes like this:
CODE
QUOTE TABLE:
--------------
PK_QuoteID
FK_CustomerID
TotalPrice
QuoteDateTime
...
As people browse through products and prices they "build" their own quote by selecting a few items.
They will then click a button marked "Get Quote" which will take them to the Quote page.
This page I want to structure like a conventional quote, and in order to get a Quote number, I'm running a select statement like this:
CODE
SELECT last_insert_id() FROM quotes
EDIT:
Then I add 1 in the ExecuteScalar statement to get the next Quote number:
CODE
//scalar returns an object, so convert to int and add 1 for new quote
int newQuote = Convert.ToInt32(comQuoteNo.ExecuteScalar()) + 1;
There will be another button here to "Accept Quote" which will write all details to the "Quote" table and have an option for the user to Print.
This works fine at the moment, but I can forsee the following problem:
If 2 or more users click the "Get Quote" button at around the same time the select statement will return the same quote number for all of them. This will cause issues with non-unique QuoteIDs.
Do I need to lock the number somehow?
The problem with doing this is that if the 2nd user rejects his quote there is an unused quote number in the DB.
Is there a problem with my DB structure?
Any thoughts would be appreciated.
This post has been edited by Footsie: 29 Mar, 2008 - 05:04 AM