Difference between revisions of "SQLROLLBACK()"

From Lianjapedia
Jump to: navigation, search
 
(3 intermediate revisions by 2 users not shown)
Line 6: Line 6:
  
 
==See Also==
 
==See Also==
[[SQLCANCEL()]], [[SQLCOLUMNS()]], [[SQLCOMMIT()]], [[SQLCONNECT()]], [[SQLDISCONNECT()]], [[SQLERROR()]], [[SQLEXEC()]], [[SQLGETPROP()]] [[SQLMORERESULTS()]], [[SQLPREPARE()]], [[SQLSETPROP()]], [[SQLSTRINGCONNECT()]], [[SQLTABLES()]]
+
[[SQLCANCEL()]], [[SQLCOLUMNS()]], [[SQLCOMMIT()]], [[SQLCONNECT()]], [[SQLDISCONNECT()]], [[SQLERROR()]], [[SQLEXEC()]], [[SQLGETPROP()]] [[SQLMORERESULTS()]], [[SQLPREPARE()]], [[SQLSETPROP()]], [[SQLSTRINGCONNECT()]], [[SQLTABLES()]], [[SQLTRANSACTION()]]
  
 
==Description==
 
==Description==
The SQLROLLBACK() function is used to roll back a transaction. The SQLROLLBACK() function is only required when Manual Transactions are in effect. The Transactions setting, set using SQLSETPROP(), can be either Automatic (1) or Manual (2).  Manual Transactions can be can be committed using the SQLCOMMIT() function.
+
The SQLROLLBACK() function is used to commit a transaction. The SQLROLLBACK() function is only required when SQLTRANSACTION() is in effect on the connection.
 +
The SQLROLLBACK() function operates on the ODBC connection specified by <nStatementHandle>.
  
 
The SQLROLLBACK() function operates on the data source specified by <nStatementHandle>.
 
The SQLROLLBACK() function operates on the data source specified by <nStatementHandle>.
  
{| class="wikitable"
+
{| class="wikitable" width="100%"
!Keywords||Description
+
!width="30%"|Keywords||width="70%"|Description
 
|-
 
|-
|nStatementHandle||The workarea in which the gateway data source is open
+
|nStatementHandle||Statement handle to the connection
|-
+
|}
+
 
+
====Return values:====
+
 
+
{| class="wikitable"
+
!Return Value||Description
+
|-
+
|1||SQL statement was rolled back successfully
+
|-
+
|&ndash;1||Error occurred
+
 
|-
 
|-
 
|}
 
|}
Line 33: Line 23:
 
==Example==
 
==Example==
 
<code lang="recital">
 
<code lang="recital">
nStatHand=SQLSTRINGCONNECT("rec@rec1:user1/pass1-southwind.tcpip",.T.)
+
nStatHand=sqlconnect("awhr")
 
if nStatHand < 1
 
if nStatHand < 1
    messagebox("Cannot make connection", 16, "SQL Connect Error")
+
messagebox("Cannot make connection", 16, "SQL Connect Error")
 
else
 
else
    messagebox("Connection made", 48, "SQL Connect Message")
+
messagebox("Connection made", 48, "SQL Connect Message")
    nSetEnd = SQLSETPROP(nStatHand,"Transactions",2)
+
sqltransaction(nStatHand)
    if nSetEnd = 1
+
sqlexec(nStatHand,"insert into dbo.doc1 (account_no, lastname, balance) values ('00889','Brown', 12000)")
        messagebox("Manual Transactions enabled",0,"Transaction")
+
if messagebox("Commit Insert?",36,"Transaction") = 6
    else
+
sqlcommit(nStatHand)
        if messagebox("Unable to enable Manual Transactions, continue?",36,"Transaction") = 6
+
else
            SQLDISCONNECT(nStatHand)
+
sqlrollback(nStatHand)
            return
+
endif
        endif
+
sqlexec(nStatHand,"select * from dbo.doc1")
    endif
+
list
    nRET=SQLEXEC(nStatHand,"INSERT INTO example (ACCOUNT_NO, TITLE, LAST_NAME, FIRST_NAME, INITIAL, STREET, CITY, STATE, ZIP, LIMIT, START_DATE) VALUES ('00200','Mr','Doe','John','L','1 High Street','Beverly','MA','01916', 12000, {05/12/2003})")
+
sqldisconnect(nStatHand)
    if SQLGETPROP(nStatHand, "Transactions") = 2
+
        if messagebox("Commit Insert?",36,"Transaction") = 6
+
            messagebox("SQLCOMMIT() returned " + etos(SQLCOMMIT(nStatHand)),0,"Transaction")
+
        else
+
            messagebox("SQLROLLBACK() returned " + etos(SQLROLLBACK(nStatHand)),0,"Transaction")
+
        endif
+
    endif
+
    nSetEnd = SQLSETPROP(nStatHand, "Transactions",1)
+
    if nSetEnd = 1
+
        messagebox("Automatic Transactions enabled",0,"Transaction")
+
    else
+
        messagebox("Unable to enable Automatic Transactions.",0,"Transaction")
+
    endif
+
 
endif
 
endif
SQLDISCONNECT(nStatHand)
 
 
</code>
 
</code>
  
Line 68: Line 44:
 
[[Category:Functions]]
 
[[Category:Functions]]
 
[[Category:SQL]]
 
[[Category:SQL]]
[[Category:Remote Data Connectivity Functions]]
 
 
[[Category:ODBC Functions]]
 
[[Category:ODBC Functions]]
 
[[Category:SQL Functions]]
 
[[Category:SQL Functions]]

Latest revision as of 10:01, 4 February 2013

Purpose

Rollback a transaction

Syntax

SQLROLLBACK(<nStatementHandle>)

See Also

SQLCANCEL(), SQLCOLUMNS(), SQLCOMMIT(), SQLCONNECT(), SQLDISCONNECT(), SQLERROR(), SQLEXEC(), SQLGETPROP() SQLMORERESULTS(), SQLPREPARE(), SQLSETPROP(), SQLSTRINGCONNECT(), SQLTABLES(), SQLTRANSACTION()

Description

The SQLROLLBACK() function is used to commit a transaction. The SQLROLLBACK() function is only required when SQLTRANSACTION() is in effect on the connection. The SQLROLLBACK() function operates on the ODBC connection specified by <nStatementHandle>.

The SQLROLLBACK() function operates on the data source specified by <nStatementHandle>.

Keywords Description
nStatementHandle Statement handle to the connection

Example

nStatHand=sqlconnect("awhr")
if nStatHand < 1
	messagebox("Cannot make connection", 16, "SQL Connect Error")
else
	messagebox("Connection made", 48, "SQL Connect Message")
	sqltransaction(nStatHand)
	sqlexec(nStatHand,"insert into dbo.doc1 (account_no, lastname, balance) values ('00889','Brown', 12000)")
	if messagebox("Commit Insert?",36,"Transaction") = 6
		sqlcommit(nStatHand)
	else
		sqlrollback(nStatHand)
	endif
	sqlexec(nStatHand,"select * from dbo.doc1")
	list
	sqldisconnect(nStatHand)
endif