Difference between revisions of "SQLCOMMIT()"

From Recital Documentation Wiki
Jump to: navigation, search
 
 
(6 intermediate revisions by 2 users not shown)
Line 1: Line 1:
=SQLCOMMIT()=
 
 
 
==Class==
 
SQL Applications
 
 
 
 
==Purpose==
 
==Purpose==
 
Commit a transaction
 
Commit a transaction
Line 15: Line 8:
  
 
==See Also==
 
==See Also==
[[CREATE CONNECTION]], [[SQLCANCEL()]], [[SQLCOLUMNS()]], [[SQLCONNECT()]], [[SQLDISCONNECT()]], [[SQLEXEC()]], [[SQLGETPROP()]] [[SQLMORERESULTS()]], [[SQLPREPARE()]], [[SQLROLLBACK()]], [[SQLSETPROP()]], [[SQLSTRINGCONNECT()]], [[SQLTABLES()]]
+
[[CREATE CONNECTION]], [[SQLCANCEL()]], [[SQLCOLUMNS()]], [[SQLCONNECT()]], [[SQLDISCONNECT()]], [[SQLERROR()]], [[SQLEXEC()]], [[SQLGETPROP()]] [[SQLMORERESULTS()]], [[SQLPREPARE()]], [[SQLROLLBACK()]], [[SQLSETPROP()]], [[SQLSTRINGCONNECT()]], [[SQLTABLES()]]
  
 
==Description==
 
==Description==
Line 46: Line 39:
 
==Example==
 
==Example==
 
<code lang="recital">
 
<code lang="recital">
nStatHand=SQLSTRINGCONNECT("rec@rec1:user1/pass1/usr/recital/uas/data/southwind.tcpip",.T.)
+
nStatHand=SQLSTRINGCONNECT("rec@rec1:user1/pass1-southwind.tcpip",.T.)
 
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)
+
    nSetEnd = SQLSETPROP(nStatHand,"Transactions",2)
if nSetEnd = 1
+
    if nSetEnd = 1
dialog box [Manual Transactions enabled]
+
        messagebox("Manual Transactions enabled",0,"Transaction")
else
+
    else
dialog message [Unable to enable Manual Transactions. Continue?]
+
        if messagebox("Unable to enable Manual Transactions, continue?",36,"Transaction") = 6
if lastkey() <> 89
+
            SQLDISCONNECT(nStatHand)
SQLDISCONNECT(nStatHand)
+
            return
return
+
        endif
endif
+
    endif
endif
+
    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})")
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})")
+
    if SQLGETPROP(nStatHand, "Transactions") = 2
if SQLGETPROP(nStatHand, "Transactions") = 2
+
        if messagebox("Commit Insert?",36,"Transaction") = 6
dialog message [Commit Insert?]
+
            messagebox("SQLCOMMIT() returned " + etos(SQLCOMMIT(nStatHand)),0,"Transaction")
if lastkey() = 89
+
        else
dialog box "SQLCOMMIT() returned " + etos(SQLCOMMIT(nStatHand))
+
            messagebox("SQLROLLBACK() returned " + etos(SQLROLLBACK(nStatHand)),0,"Transaction")
else
+
        endif
dialog box "SQLROLLBACK() returned " + etos(SQLROLLBACK(nStatHand))
+
    endif
endif
+
    nSetEnd = SQLSETPROP(nStatHand, "Transactions",1)
endif
+
    if nSetEnd = 1
nSetEnd = SQLSETPROP(nStatHand, "Transactions",1)
+
        messagebox("Automatic Transactions enabled",0,"Transaction")
if nSetEnd = 1
+
    else
dialog box [Automatic Transactions enabled]
+
        messagebox("Unable to enable Automatic Transactions.",0,"Transaction")
else
+
    endif
dialog message [Unable to enable Automatic Transactions.]
+
endif
+
 
endif
 
endif
 
SQLDISCONNECT(nStatHand)
 
SQLDISCONNECT(nStatHand)
Line 82: Line 73:
  
 
==Products==
 
==Products==
Recital Database Server, Recital Mirage Server, Recital Terminal Developer
+
Recital, Recital Server
 
[[Category:Documentation]]
 
[[Category:Documentation]]
 
[[Category:Functions]]
 
[[Category:Functions]]
 
[[Category:SQL]]
 
[[Category:SQL]]
 +
[[Category:Remote Data Connectivity Functions]]

Latest revision as of 16:14, 4 July 2011

Purpose

Commit a transaction


Syntax

SQLCOMMIT(<nStatementHandle>)


See Also

CREATE CONNECTION, SQLCANCEL(), SQLCOLUMNS(), SQLCONNECT(), SQLDISCONNECT(), SQLERROR(), SQLEXEC(), SQLGETPROP() SQLMORERESULTS(), SQLPREPARE(), SQLROLLBACK(), SQLSETPROP(), SQLSTRINGCONNECT(), SQLTABLES()

Description

The SQLCOMMIT() function is used to commit a transaction. The SQLCOMMIT() 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 rolled back using the SQLROLLBACK() function.

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


Keywords Description
nStatementHandle The workarea in which the gateway data source is open


Return values:

Return Value Description
1 SQL statement was committed successfully
–1 Error occurred


Example

nStatHand=SQLSTRINGCONNECT("rec@rec1:user1/pass1-southwind.tcpip",.T.)
if nStatHand < 1
    messagebox("Cannot make connection", 16, "SQL Connect Error")
else
    messagebox("Connection made", 48, "SQL Connect Message")
    nSetEnd = SQLSETPROP(nStatHand,"Transactions",2)
    if nSetEnd = 1
        messagebox("Manual Transactions enabled",0,"Transaction")
    else
        if messagebox("Unable to enable Manual Transactions, continue?",36,"Transaction") = 6
            SQLDISCONNECT(nStatHand)
            return
        endif
    endif
    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})")
    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
SQLDISCONNECT(nStatHand)


Products

Recital, Recital Server