Re: Question: multiuser
Posted in 1995
Heidi, Select avg(rating) from rating_table will pick up the average at the time that statement is run. That statement will normally fail if it comes across a locked record. A record will automatically get locked by the engine for the instant when another user does an update on that record. How you handle that depends on yourself and what tools you have available. You can 1. Ignore it and hope it does not happen too often (earlier versions of ace report writer did this). 2. If you are using standard engine you can issue the statement SET LOCK MODE TO WAIT. The problem with this one is that you can end up waiting indefinately. 3. If you are using Online then you can say SET LOCK MODE TO WAIT n SECONDS. This gives a finite wait for a lock to free up. You can also say SET ISOLATION TO DIRTY READ, which means you do not really care if you are looking at a before or after image of a record that is being updated. 4. If you are using 4gl then you can put your select statement between a WHENEVER ERROR CONTINUE and a WHENEVER ERROR STOP and trap the STATUS variable. STATUS is a variable that is created automatically and keeps track of how things are going: if STATUS != 0 then things are going wrong. Check for the STATUS you get when a row is already locked and either exit gracefully or offer the user another go. You would have to have half a dozen or more people constantly updating this table before problems of contention like this became a serious issue. A lot of organisations use cron to run these statistical type programs in the small hours of the morning. I hope this has not put you off. Pete Harris On 28 Jan 1995, Sasami wrote: > I have this idea of making a rating program for a certain product. > This program will reside in a multiuser system, and many people can > run the program at the same time. The program will maintain a database > of all the rating input from people and will calculate the average of the > rating. > > My question is: > How does informix handle this? I mean, if many people are accessing > the database at the same time, adding new data, then the average will > be different everytime. How does informix decide which data to show > to the user? Will informix let only one user manipulate the data > before letting others manipulate it? > > Many thanks! > > Heidi >