 | | From: | Will | | Subject: | rowset | | Date: | Mon, 17 Jan 2005 15:15:02 -0600 |
|
|
 | I need to calculate a field and write the field directly to the rowset. How can this be coded? This is the code I have so far:
form.orderno1.rowset.last() y = form.orderno1.rowset.fields["orders"].value form.orderno1.rowset.beginappend() x = y +1 // incrementing field for order no form.orderno1.rowset.fields["orders"].value = x (is this correct code for sending this value to the rowset)
|
|
 | | From: | Rick Gearardo | | Subject: | Re: rowset | | Date: | Mon, 17 Jan 2005 16:18:15 -0500 |
|
|
 | Yes, it will work (assuming natural order or order number order) if you are not in a multiuser environment. If this is networked with multiple users you will be duplicating order numbers because of caching and timing. Multiple people will see the last order number before a new one is saved().
Rick
"Will" wrote in message news:bi$1bnN$EHA.1456@news-server... > I need to calculate a field and write the field directly to the rowset. How > can this be coded? This is the code I have so far: > > form.orderno1.rowset.last() > y = form.orderno1.rowset.fields["orders"].value > form.orderno1.rowset.beginappend() > x = y +1 // incrementing field for order no > form.orderno1.rowset.fields["orders"].value = x (is this correct code for > sending this value to the rowset) > >
|
|
 | | From: | Will | | Subject: | Re: rowset | | Date: | Mon, 17 Jan 2005 15:27:44 -0600 |
|
|
 | this program will be used in a multiuser environment. How can I prevent the order numbers from being duplicated "Rick Gearardo" wrote in message news:cCyQKrN$EHA.876@news-server... > Yes, it will work (assuming natural order or order number order) if you > are > not in a multiuser environment. If this is networked with multiple users > you > will be duplicating order numbers because of caching and timing. Multiple > people will see the last order number before a new one is saved(). > > Rick > > "Will" wrote in message > news:bi$1bnN$EHA.1456@news-server... >> I need to calculate a field and write the field directly to the rowset. > How >> can this be coded? This is the code I have so far: >> >> form.orderno1.rowset.last() >> y = form.orderno1.rowset.fields["orders"].value >> form.orderno1.rowset.beginappend() >> x = y +1 // incrementing field for order no >> form.orderno1.rowset.fields["orders"].value = x (is this correct code for >> sending this value to the rowset) >> >> > >
|
|
 | | From: | Marilyn Price | | Subject: | Re: rowset | | Date: | Tue, 18 Jan 2005 07:54:33 -0500 |
|
|
 | In article <96RyiuN$EHA.1456@news-server>, toquerrio@hotmail.com says... > this program will be used in a multiuser environment. How can I prevent the > order numbers from being duplicated >
I see Roland has given you one possibility. Another is to have a tiny table that just holds the most recently assigned number. When you need a new one, you explicitly lock the rowset with this number in it, increment the number, save it, then unlock it. Each user gets a unique number and, if two people attempt to get a value at the same time, the lock prevents this. Note that the lock is only in place for fractions of a second, so the delay is minimal.
Something like this:
q = new query() q.sql := 'select * from "locks.dbf"' q.active := true
// wait for a rowset lock do while not q.rowset.lockrow() enddo mnext = q.rowset.fields["lastvalue"].value + 1 q.rowset.fields["lastvalue"].value := mnext q.rowset.save() q.rowset.unlock() q.active := false
form.orderno1.rowset.beginappend() form.orderno1.rowset.fields["orders"].value := mnext
Note: this is untested, but should give you some ideas....
-- Marilyn Price M. P. Data
|
|
 | | From: | Rick Gearardo | | Subject: | Re: rowset | | Date: | Tue, 18 Jan 2005 08:39:33 -0500 |
|
|
 | That still doesn't work in the Window's world. You need to put in a delay to overcome caching and it varies with the amount of users you are going to have.
I generate various numbers: service call, invoice, po, index keys, etc. I keep them in a seperate file , along with the delay setting, and increment them in a loop:
if r.lock() r.fields["num"].value++ r.save() for i = 1 to r.fields["myDelay"].value r.flush() r.save() endif endif
The loop is actually a little more complex but this gives you the idea.
I've had to change the delay a few times as we've added users. It is currently at 18 which doesn't slow you down but I've eliminated duplicates. If you are using Windows clients and a Windows server you will probably need a longer delay because you're overcoming two caching situations.
For index keys I now use a combination of the user's login name and a generated number. Everyone has a unique login so I don't need a delay.
Rick
> I see Roland has given you one possibility. Another is to have a tiny > table that just holds the most recently assigned number. When you need > a new one, you explicitly lock the rowset with this number in it, > increment the number, save it, then unlock it. Each user gets a unique > number and, if two people attempt to get a value at the same time, the > lock prevents this. Note that the lock is only in place for fractions > of a second, so the delay is minimal. > > Something like this: > > q = new query() > q.sql := 'select * from "locks.dbf"' > q.active := true > > // wait for a rowset lock > do while not q.rowset.lockrow() > enddo > mnext = q.rowset.fields["lastvalue"].value + 1 > q.rowset.fields["lastvalue"].value := mnext > q.rowset.save() > q.rowset.unlock() > q.active := false > > form.orderno1.rowset.beginappend() > form.orderno1.rowset.fields["orders"].value := mnext > > Note: this is untested, but should give you some ideas.... > > -- > Marilyn Price > M. P. Data
|
|
 | | From: | Roland Wingerter | | Subject: | Re: rowset | | Date: | Tue, 18 Jan 2005 08:14:04 +0100 |
|
|
 | Will wrote: > this program will be used in a multiuser environment. How can I > prevent the order numbers from being duplicated ----- Use dBASE level 7 tables autoinc fields.
Roland
|
|