Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Nested Transaction
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00090423
Message ID:
00090536
Views:
23
Thanks, maybe I should have been a little clearer, DeleteAll is almost the same as the sample you provided. DeleteOne() basically is like this ( I left out a lot of code but this should give you a good idea ):


llOK = .t.
select This.RecordSource
go This.OnRec
lcPart = part
lnQty = Qty
BEGIN TRANS
if Seek(lcPart,'Invent','Part')
Repl onhand with onhand + lnQty
if!tableupdate(0,.f.'Invent')
llOk = .f.
endif
else
llOk = .f.
endif
select This.RecordSource
go This.OnRec
Delete
if!tableupdate( This.RecordSource )
llOk = .f.
endif
if llOk
END TRANS
else
ROLLBACK
endif
return llOk

So if in your example code which is trans level 1, three records delete and the fourth has ROLLBACK in level 2 and returns false, your code would issue ROLLBACK. The three records that were deleted by DeleteOne and returned .t. would go back as they were when your code issued BEGIN TRANS, right ?




>No. You will ROLLBACK only the innermost transaction. If you want to roll back everything when one delete transaction fails, you'll need to do another ROLLBACK. For example, in DeleteAll do something like this:
>
>m.llRollback=.F.
>BEGIN TRANSACTION
>SCAN FOR OrderKey=m.OrderKey
> IF !DeleteOne()
> m.llRollBack=.T.
> ROLLBACK
> EXIT
> ENDIF
>ENDSCAN
>IF !m.llRollBack
> END TRANSACTION
>ENDIF
>
>This assumes that DeleteOne() returns .F. if it fails to carry out the deletion.
>
>>I use a grid for the detail of an order entry form, I added methods to the grid rather than the form because the same grid is used on several forms. One method, I call DeleteOne, deletes the current record of the recordsource of the grid. I begin a transaction,make updates to three other tables effected by the delete, and if all is successfull, delete the record, if not ROLLBACK.
>>
>>Now I want to add a method that deletes all records in the grid which is detail for a single order. Call it DeleteAll and I want to begin a transaction, start at first record and call DeleteOne ( remeber this method uses BEGIN TRANS and END TRANS in itself ) and move through the detail records calling DeleteOne on each record. If for some reason one record can not be deleted and I issue ROLLBACK in DeleteAll method, will the tables updated when END TRANS was issued on each record in DeleteOne be rolled back also ?
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform