Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Avoiding duplicate records, continuation
Message
De
09/06/2008 05:33:30
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Versions des environnements
Visual FoxPro:
VFP 9 SP2
Divers
Thread ID:
01322454
Message ID:
01322500
Vues:
11
>I gave up using auto increment integer fiels for a while
>
>I continue my war also giving up using a second table to keep
>records
>
>I user a timer that executing 2 forms at the same time,
>adding data to a table (very quickly, as test)
>
>At the end of the tests I have 2000 records, with no duplications
>Seems perfect...
>
>However if I use 3 forms, duplicate numbers accour in some records
>
>I wonder if 2 forms tests are enough or is there anything I could change
>below to improve the code
>
>Moises
>
>
>********** form 1 ***********
>
>SELECT ped
>
>DO WHILE !FLOCK()
>ENDDO
>
>dimension lctemp[1]
>select max(n) from ped ;
> into array lctemp
> lcTemp[1] = nvl(lcTemp[1],0)+1
>replace ped.n WITH lcTemp
> replace ped.n_id WITH "USER 1"
>
> FLUSH
>UNLOCK
>
>********** form 2 ***********
>
>SELECT ped
>
>DO WHILE !FLOCK()
>ENDDO
>
>dimension lctemp[1]
>select max(n) from ped ;
> into array lctemp
> lcTemp[1] = nvl(lcTemp[1],0)+1
>replace ped.n WITH lcTemp
> replace ped.n_id WITH "USER 2"
>
> FLUSH
>UNLOCK

Moises,
I didn't understand exactly what the code is intended to do. Form what I understand it increments a value in a table called ped (but doesn't return that value?).
Instead of a timer I would execute that in a for loop for a better test (and run them at the same time from multiple VFP sessions). Mine getid routine looks like:
set reprocess to 1
declare Sleep in win32API integer dwMilliSecs
if !seek(m.tcTableName, 'idtable', 'tablename')
 insert into idtable (tablename,currenID) values (m.tcTableName,1)
endif
do while !rlock('idTable')
  Sleep(10)
enddo
* ...
return m.lnId
Using a GUID as key removes the necessity to check.
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform