PDA

View Full Version : how database handle request?


albert85
04-28-2006, 09:13 AM
Hi friend,

I want to write a program that can access to multiple database based on the user ID, but I dont know how the database handle user request. Please help me...

if user A execute program and redirect to database abc, and user B also accessing it. user A retrieve value from database but not yet update it, at the same time user B go get the value. How can I control it? can I code a program that control if A not yet finish, we cannot allowed user B to retrieve the value?

I cannot use Java synchronization. if I use it, it will synchronize for all the request although the request is redirect to different database(I am using many databases but sharing 1 program). There is no point to do synchronization if another user accessing other database that is no user at that moment but still need to wait user at different database finish their tasks first.

guelphdad
04-28-2006, 03:04 PM
you could use row locks. you may also use last_insert_id() depending on what you are doing.

can you show us a sample of what a user would be doing?

If you mean user A is going to access record 905 and update the value of address to "123 Main St." and user B may also be trying to do the same thing then you would want row locking.

If you mean user A is going to select max(id) from a column in table A to use it in table B but user B could also try to get max(id) at the same time then you would use an auto increment column and use last_insert_id which is independent of users and you wouldn't need row locking.