Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: dragon 5
  Where is dragon 5?
 Johor
 Malaysia
 dragon 5
 To: Jun Tangunan
  Where is Jun Tangunan?
 Cabanatuan
 Philippines
 Jun Tangunan
 Tags
Subject: RE: use GETAUTOINCVALUE() is suitable?
Thread ID: 287888 Message ID: 289388 # Views: 29 # Ratings: 0
Version: Visual FoxPro 9 Category: General VFP Topics
Date: Friday, December 31, 2010 11:49:45 AM         
   


> > Dear all,
> >
> > I had a problem that to retrieve an auto increment number in the multiuser environment.
> >
> > Example:
> >
> > user A insert a record into tableA, in that moment, user B also insert a record in tableB just after user A.
> >
> > I will use the code below.
> >
> > Begin transaction
> > insert into tableA(name) values('John')
> > tableupdate(.t.)
> > lnGetAutoID=GETAUTOINCVALUE()
> > end transaction
> >
> >
> > TableA content:
> >
> > ID name insertBy
> > -- ---- --------
> > 1 John user A
> > 2 kelvin user B
> >
> >
> > So for this situation, am I get the correct auto increment value, which is 1 not the 2?
> > Because I not sure that GETAUTOINCVALUE()will return the correspond of auto increment value.
> > I need to make sure that get the correct auto increment value.
> >
> > Or got other way, except lock the record.
> >
> > Thanks.
> >
> > dragon 5
>
>
> You are using that for usage as Foreign Key on another table right? If so, then you don't need to base it on GETAUTOINCVALUE(). Get the Integer AI on the recently saved record of the parent table because that is where you will be linking the child records anyway:
>
>
> SET AUTOINCERROR OFF 
> CREATE CURSOR parentdbf (parentPK I AUTOINC, xName c(40))
> CREATE CURSOR childdbf (childPK I AUTOINC, ParentFK I, Age N(2,0))
> 
> * Create records for parent
> INSERT INTO parentdbf VALUES (0,"JUN")
> SELECT parentdbf
> BROWSE NORMAL 
> 
> * create corresponding record to child
> * use the parent's integer autoinc field's (PARENTPK) currently saved record's value
> INSERT INTO childdbf VALUES (0, parentdbf.parentpk,39)  
> 
> SELECT childdbf 
> BROWSE NORMAL 
> 
> * Join Data to get the full picture
> SELECT xName, Age FROM parentdbf LEFT OUTER JOIN childdbf ON parentdbf.parentpk = childdbf.parentfk

>
> http://www.junblogs.com/
> http://weblogs.foxite.com/sandstorm36/default.aspx
> http://www.coderisland.com/forum/viewforum.php?f=10


Dear mr. Jun,

But in the multiuser environment, will it get the correct autoInc value?
I was worry that will get the wrong autoInc Id.

Thanks.
dragon 5

ENTIRE THREAD

use GETAUTOINCVALUE() is suitable? Posted by dragon 5 @ 12/15/2010 3:51:57 PM
RE: use GETAUTOINCVALUE() is suitable? Posted by Ony Too @ 12/15/2010 11:37:56 PM
RE: use GETAUTOINCVALUE() is suitable? Posted by Jun Tangunan @ 12/16/2010 1:22:38 AM
RE: use GETAUTOINCVALUE() is suitable? Posted by dragon 5 @ 12/31/2010 11:49:45 AM
RE: use GETAUTOINCVALUE() is suitable? Posted by Mike Yearwood @ 12/31/2010 7:56:04 PM