Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Transactions & Sqlcommit ???
Message
 
To
30/08/2001 09:47:24
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00550831
Message ID:
00550842
Views:
14
When talking to SQL Server or Oracle you need to use both transaction commands: VFP begin transaction plus SQL Server begin transacion. Likewise when closing it.

Below is an typical example on how to do it with SQL Server.
* Start a VFP transaction and 
* a transaction on the server.
begin transaction
SQLExec( nConnection, ‘BEGIN TRANSACTION’ )

  * Update changes to MyTable.
	lEverythingOK = tableupdate( 2, .F., ‘rv_MyView’ )
	if lEverythingOK
    * Update changes to MyOtherTable.
    lEverythingOK = tableupdate( 2, .F., ‘rv_MyOtherView’ )
	endif	

* End the transaction on the server and VFP.
If lEverythingOK
	SQLExec( nConnection, ‘IF @@TRANCOUNT > 0 COMMIT’ )
	end transaction
else
	SQLExec( nConnection, ‘IF @@TRANCOUNT > 0 ROLLBACK’ )
	rollback
Endif
You could use SQLCommit() or SQLRollback() instead of the SQLExec() that I am using here.

If you are subscribed to FoxTalk, take a look at issue September 2000 where I explained why you need to use both transaction commands.

>Hi all,
>
>I am wondering something. Up until now I’ve been sending my updates to the database with a TABLEUPDATE(.T.) everything has been fine. This is good if there is only 1 cursor to update. If I have several cursors to update that depend on each other. I don’t want 2 or 3 of them saved and the last one not. So I want to start using TRANSACTIONS set to 2. This means SQLCOMMIT().
>
>My question: If I go this route. Do I still send my updates in the same way? i.e. TABLEUPDATE(.T.)? And then after I am sure that every update when ok issue, the SQLCOMMIT? Or SQLROLLBACK if there was an error? Will the ROLLBACK clear all the previous TABLEUPDATEs?
>
>Also, I assume that I still need to set all my cursor properties as before.
>
>I am using a VFP database & ODBC driver. And VFP 6 SP3
>
>TIA
>Mike
Hector Correa
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform