>Is this a correct way to handle SQL transactions?
>
>2 sql views
>
>BEGIN TRANS
>.
>.
>code for mods to both views, i.e. adding records, updating fields
>.
>.
>lupdateok=tableupdate(1,.t.,'view_a')
>lupdateok=lupdateok and tableupdate(1,.t.,'view_b')
>
>IF NOT lupdateok
> ROLLBACK
>ELSE
> END TRANS
>ENDIF
You got it.
Note that you can also nest TRANSACTIONS upto 5 levels. I often do this when I have a fairly complex update that can be devided into logical batches.
BEGIN TRANSACTION
if not FirstBatchUpdate()
=RevertIt()
RETURN .F. && Early Exit!
endif
BEGIN TRANSACTION
.... etc.
END TRANSACTION
END TRANSACTION
FUNCTION RevertIt()
DO WHILE TXNLEVEL() > 0
ROLLBACK
ENDDO
George