Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Transaction - End Transaction - Rollback
Message
From
13/04/2007 00:00:52
 
 
To
12/04/2007 04:21:46
Hans-Otto Lochmann
Dr. Lochmann Consulting Gmbh
Frankfurt, Germany
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01214857
Message ID:
01215388
Views:
23
This message has been marked as the solution to the initial question of the thread.
>Hi All,
>
>Sorry for this beginner's question: Does "Rollback" imply TableRevert()?
>
>Details: I want to use this kind of a structure - does the Rollback effect the TableRevert()-s, which are needed, when some of the TableUpdate()-s fail?
>
>m.llReturnValue = .F.
>Begin Tansaction
>.....
>< Some Loop With m.llReturnValue = m.llReturnValue And TableUptdate(...) >
>.....
>If m.llReturnValue = .T.
>  End Transaction
>Else
>  Rollback
>Endif
>
>
>Thanks in advance!
>
>Hans


Hi Hans

You will find some tutorials about CA's here. While they were written for VFP8 they are still relevant in 9 because not that much was changed.

http://www.foxite.com/articles/articleindex.htm

starting with :
http://www.foxite.com/articles/read.aspx?id=49&document=creating-using-cursor-adapter-classes-a-simple-tutorial

Couple of points:

When using SQLServer data and transactions you are actually managing 2 databases. The VFP tables and the SQL backend. The CA's make it easier but for transactions you still have to manage the code for the backend yourself or you will lose integrity.

If you use defaults and your VFP app crashes during a transaction, the back end will be updated with Orphans etc.

To avoid this it is best to explicitly change the default transaction status to manual and then update the tables involved.

The following snippet will show you how I do it using CA's:
BEGIN TRANSACTION    && this is for VFP
SQLSETPROP(oConn,"Transactions",2)  && this for SQLServer - manual transaction mode
If Not Tableupdate(0,.T.,"contract")
	Aerror(aer)
	Sqlrollback(oConn)    && for SQLServer
        ROLLBACK      && for VFP
	SQLSETPROP(oConn,"Transactions",1)  && for SQLServer
	Thisform.logsqlerror()
	Messagebox(aer[2])
	Return .F.
ELSE
    If Not Tableupdate(0,.T.,"SomeOtherTable")
    .... code similar to above



   ENDIF
ENDIF
Bernard
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform