Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Local Views at Wits End
Message
De
10/06/2003 07:18:47
 
 
À
09/06/2003 15:46:51
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00796970
Message ID:
00798287
Vues:
39
Hi Erik,

I've run your new code and it stops on my machines as well.
I've moved a few things around, so bear with me...

You don't need to close the test-table, just forcing a reread
by jumping to the same record is "usually" enough - tested
with a few more records and less time for the inkey.
YOu find that code in "SqlNextID_UnSafe".

But I really think you should be working on with a rowlocking
scheme for each record/table combination. Since my version eliminated
much of the fluff between change and update, there won't be any problem. But the safer method can be found in "SqlNextID_UnSafe".

Both versions runhere without problems.

If this scheme is used for getting new ID's for newly created records,
all should be encompassed by a transaction.

HTH

thomas
***********************************************************************
private lnRun, lnNext

CLEAR
CLOSE DATA
CLOSE TABLES
SET EXCLUSIVE OFF
SET DELETED ON
SET CURSOR OFF

if NOT FILE("ShowBug.Dbc")

CREATE Database SHOWBUG
CREATE TABLE Test (MyID I, NextID I)
APPEND BLANK
REPLACE MyID WITH 1, NextID WITH 1
USE

CREATE SQL VIEW VTest AS SELECT * FROM Test WHERE MyID=1
DBSetProp( "VTest.MyID" , "Field", "KeyField" , .T. )
DBSetProp( "VTest.MyID" , "Field", "Updatable" , .F. )
DBSetProp( "VTest.NextID" , "Field", "Updatable" , .T. )
DBSetProp( "VTest" , "View" , "SendUpdates", .T. )
DBSetProp( "VTest" , "View" , "WhereType" , 3 )

CLOSE DATA

endif

OPEN DATABASE ShowBug
USE VTest SHARED

@2,2 SAY "Assign :"
@3,2 SAY "Run Main :"
@4,2 SAY "Source :"
@5,2 SAY "View :"
@6,2 SAY "Run Sub :"

for lnRun = 1 to 10000
INKEY(.01)
lnNext = iif(.t., SqlNextID_Safe(), SqlNextID_UnSafe())
if m.lnNext < 0
=MessageBox("It's Dead!")
EXIT
endif
next

CLOSE DATA
CLOSE TABLES
SET CURSOR ON

return

********************************************************************************************************************
Function SqlNextID_UnSafe( cAlias )
private lnRet, lnSubTry, lnRLockTry
Store 0 To lnSubTry, lnRLockTry

do while .T.
REQUERY()
REPLACE NextID WITH NextID + 1
if !eof("test") and .t.
Go recno("Test") in Test
endif
if TableUpdate( .T., .F. )
lnRet = NextID - 1
= ShowState()
EXIT
else
= TableRevert( .T. )
lnRet = -1
= ShowState()
if m.lnSubTry > 100
EXIT
endif
lnSubTry = m.lnSubTry + 1
endif
enddo
return (m.lnRet)

Function SqlNextID_Safe( cAlias )
private lnRet, lnSubTry, lnRLockTry

for lnRLockTry = 1 To 1000
if RLock("Test")
for lnSubTry = 1 to 100
REQUERY()
REPLACE NextID WITH NextID + 1
if TableUpdate( .T., .F. )
lnRet = NextID - 1
= ShowState()
EXIT
else
= TableRevert( .T. )
lnRet = -1
= ShowState()
endif
next
unlock in Test
if m.lnRet>0
exit
endif
else
Store 0 To lnSubTry
lnRet = -1
= ShowState()
endif
next
return (m.lnRet)

function ShowState
@2,15 SAY m.lnRet
@3,15 SAY m.lnRun
@4,15 SAY Str(Test.NextID, 10) + str(recno("Test"), 5) + " ." + iif(Eof("Test"), "T.", "F.")
@5,15 SAY Str(VTest.NextID, 10) + str(recno("VTest"), 5) + " ." + iif(Eof("VTest"), "T.", "F.")
@6,15 SAY Str(m.lnRLockTry, 10) + Str(m.lnSubTry, 5)
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform