PC SOFT

ONLINE HELP
FOR WINDEV, WEBDEV AND WINDEV MOBILE

Home | Sign in | English US
  • Location and access to data files
  • Detecting an error
  • Tip: Restoring the database consistency
  • Error cases
  • Transactions and independent HFSQL context
  • OLE DB and Native Accesses
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadApple WatchUniversal Windows 10 AppWindows Mobile
Others
Stored procedures
If a transaction is in progress, cancels all the operations performed on the data files in transaction since the start of transaction. In this case, the transaction is canceled without interrupting the program execution.
If no transaction is in progress, restores the consistency of the database and cancels the unsuccessful transaction (power failure for example).
Note: A transaction that failed can be canceled by any program. The transaction file is automatically destroyed if it is not shared. The records locked by the write operations performed during the transaction are unlocked.
AndroidAndroid Widget iPhone/iPadWindows Mobile The management of transactions is available for the HFSQL Client/Server databases.
Versions 17 and later
iPhone/iPad This function is now available for the iPhone/iPad applications.
New in version 17
iPhone/iPad This function is now available for the iPhone/iPad applications.
iPhone/iPad This function is now available for the iPhone/iPad applications.
Versions 18 and later
Universal Windows 10 App This function is now available in Windows Store apps mode.
Java This function is now available for the Java applications.
Android This function is now available for the Android applications.
Android Widget This function is now available in Android Widget mode.
New in version 18
Universal Windows 10 App This function is now available in Windows Store apps mode.
Java This function is now available for the Java applications.
Android This function is now available for the Android applications.
Android Widget This function is now available in Android Widget mode.
Universal Windows 10 App This function is now available in Windows Store apps mode.
Java This function is now available for the Java applications.
Android This function is now available for the Android applications.
Android Widget This function is now available in Android Widget mode.
Note: From version 19, HFSQL is the new name of HyperFileSQL.
Versions 21 and later
Universal Windows 10 App This function is now available in Universal Windows 10 App mode.
New in version 21
Universal Windows 10 App This function is now available in Universal Windows 10 App mode.
Universal Windows 10 App This function is now available in Universal Windows 10 App mode.
Example
Versions 19 and later
// Start the transaction on the files associated with MyConnection1
HTransactionStart(MyConnection1)
Add_Order()
WHEN EXCEPTION IN
// Add the order
HAdd(Orders)
// Validate the addition
HTransactionEnd(MyConnection1)
DO
// Delete the order lines
HTransactionCancel(MyConnection1)
END
New in version 19
// Start the transaction on the files associated with MyConnection1
HTransactionStart(MyConnection1)
Add_Order()
WHEN EXCEPTION IN
// Add the order
HAdd(Orders)
// Validate the addition
HTransactionEnd(MyConnection1)
DO
// Delete the order lines
HTransactionCancel(MyConnection1)
END
// Start the transaction on the files associated with MyConnection1
HTransactionStart(MyConnection1)
Add_Order()
WHEN EXCEPTION IN
// Add the order
HAdd(Orders)
// Validate the addition
HTransactionEnd(MyConnection1)
DO
// Delete the order lines
HTransactionCancel(MyConnection1)
END
WINDEVWEBDEV - Server codeReports and QueriesAjaxUser code (UMC)HFSQL
// Start the transaction on the Orders and OrdLine files
HTransactionStart("C:\Temp\Transaction.trs", "Orders, OrderLine, -Customer")
Add_Order()
WHEN EXCEPTION IN
// Add the order
HAdd(Orders)
// Validate the addition
HTransactionEnd()
DO
// Delete the order lines
HTransactionCancel()
END
WINDEVWEBDEV - Server codeReports and QueriesAndroidAndroid Widget iPhone/iPadWindows MobileAjaxUser code (UMC)HFSQL Client/Server
// Start the transaction on the Orders and OrdLine files
HTransactionStart("Orders, OrderLine, -Customer")
Add_Order()
WHEN EXCEPTION IN
// Add the order
HAdd(Orders)
// Validate the addition
HTransactionEnd()
DO
// Delete the order lines
HTransactionCancel()
END
Syntax
Versions 19 and later
AndroidAndroid Widget Java This syntax is not available in Android, Android Widget and Java.

Canceling a current transaction or an interrupted transaction on a Client/Server connection Hide the details

<Result> = HTransactionCancel(<Connection Name>)
<Result>: Boolean
  • True if the transaction was canceled,
  • False if a problem occurred. HErrorInfo returns more details about the error.
Caution:
  • If a transaction is in progress on the connection, it is canceled.
  • If no transaction is in progress, the interrupted transactions are canceled for the specified connection.
<Connection Name>: Character string (with or without quotes)
  • Name of connection to use. This connection was defined:
  • hAccessHF7 constant: The transaction is canceled on the HFSQL Classic files (ISAM).
New in version 19
AndroidAndroid Widget Java This syntax is not available in Android, Android Widget and Java.

Canceling a current transaction or an interrupted transaction on a Client/Server connection Hide the details

<Result> = HTransactionCancel(<Connection Name>)
<Result>: Boolean
  • True if the transaction was canceled,
  • False if a problem occurred. HErrorInfo returns more details about the error.
Caution:
  • If a transaction is in progress on the connection, it is canceled.
  • If no transaction is in progress, the interrupted transactions are canceled for the specified connection.
<Connection Name>: Character string (with or without quotes)
  • Name of connection to use. This connection was defined:
  • hAccessHF7 constant: The transaction is canceled on the HFSQL Classic files (ISAM).
AndroidAndroid Widget Java This syntax is not available in Android, Android Widget and Java.

Canceling a current transaction or an interrupted transaction on a Client/Server connection Hide the details

<Result> = HTransactionCancel(<Connection Name>)
<Result>: Boolean
  • True if the transaction was canceled,
  • False if a problem occurred. HErrorInfo returns more details about the error.
Caution:
  • If a transaction is in progress on the connection, it is canceled.
  • If no transaction is in progress, the interrupted transactions are canceled for the specified connection.
<Connection Name>: Character string (with or without quotes)
  • Name of connection to use. This connection was defined:
  • hAccessHF7 constant: The transaction is canceled on the HFSQL Classic files (ISAM).

Canceling a current transaction or an interrupted transaction on all connections (HFSQL Classic or Client/Server) Hide the details

<Result> = HTransactionCancel([<Name and Path of Transaction File>])
<Result>: Boolean
  • True if the transaction was canceled,
  • False if a problem occurred. HErrorInfo returns more details about the error.
Caution:
  • HFSQL If the <Name and Path of Transaction File> is not specified, the current transaction is canceled.
  • If a transaction is in progress, ALL the current transactions are canceled (HFSQL Classic transactions and/or HFSQL Client/Server transactions).
  • If no transaction is in progress, ALL the interrupted transactions are canceled (in HFSQL Classic and in Client/Server).
<Name and Path of Transaction File>: Optional character string (with quotes)
HFSQL Name and path of transaction file to cancel:
  • This parameter must be identical to the name specified in HTransactionStart. This parameter must be identical to the name specified in HTransactionStart (or in HTransaction).
  • If this parameter is not specified and if no transaction is in progress, the default transaction file is taken into account.
  • If a transaction is in progress, this transaction is canceled and the name of transaction file is ignored.
HFSQL Client/ServerOLE DBNative Accesses This parameter is ignored.
AndroidAndroid Widget Java This syntax is not available in Android, Android Widget and Java.

Canceling an interrupted transaction on a Client/Server database (to be used if no transaction is in progress) Hide the details

<Result> = HTransactionCancel(<Connection Name> , <Database>)
<Result>: Boolean
  • True if the transaction was canceled,
  • False if a problem occurred. HErrorInfo returns more details about the error.
Caution:
  • Only the interrupted transactions on the specified database are canceled.
  • The transactions in progress are not canceled.
<Connection Name>: Character string (with or without quotes)
  • Name of connection to use. This connection was defined:
  • hAccessHF7 constant: only the interrupted transactions in HFSQL Classic mode are canceled.
<Database>: Character string
Name of relevant database. An error occurs if this parameter corresponds to an empty string ("").
WINDEVWEBDEV - Server codeWINDEV MobileReports and QueriesAjaxUser code (UMC)HFSQL

Canceling a transaction (to be used if no transaction is in progress) Hide the details

<Result> = HTransactionCancel(<Name and Path of ISAM Transaction File> , <Connection Name>)
<Result>: Boolean
  • True if the transaction was canceled,
  • False if a problem occurred. HErrorInfo returns more details about the error.
Caution:
  • If the <Name and Path of Transaction File> is not specified, the current transaction is canceled.
  • If a "general" transaction is in progress, ALL the current transactions are canceled (HFSQL Classic transactions and/or HFSQL Client/Server transactions).
  • If a transaction is in progress on the connection, it is canceled.
  • If no transaction is in progress, only the interrupted transactions are canceled for the specified connection.
<Name and Path of ISAM Transaction File>: Character string (with quotes)
Name and path of transaction file to cancel.
This parameter must be identical to the name specified in HTransactionStart. This parameter must be identical to the name specified in HTransactionStart (or in HTransaction).
<Connection Name>: Character string (with or without quotes)
  • Name of connection to use. This connection was defined:
  • hAccessHF7 constant: only the interrupted transactions in HFSQL Classic mode are canceled.
AndroidAndroid Widget Java This syntax is not available in Android, Android Widget and Java.

Canceling a specific transaction, linked to a connection Hide the details

<Result> = HTransactionCancel(<Connection Name> , <Transaction Identifier>)
<Result>: Boolean
  • True if the transaction was canceled,
  • False if a problem occurred. HErrorInfo returns more details about the error.
Caution: Only the interrupted transactions on the specified database are canceled.
<Connection Name>: Character string (with or without quotes)
  • Name of connection to use. This connection was defined:
  • hAccessHF7 constant: only the interrupted transaction in HFSQL Classic mode is canceled.
<Transaction Identifier>: Integer
Identifier of transaction that will be canceled for the specified connection. This identifier is returned by HTransactionList.
Remarks

Location and access to data files

Before calling HTransactionCancel, the data files handled by the canceled transaction must be:

Detecting an error

When an error is detected by the program (management of errors with WHILE EXCEPTION for example), HTransactionCancel is used to:
  • restore the data files in their initial status.
  • cancel all operations performed on the data files since the call to HTransactionStart.cancel all the operations performed on the data files since the call to HTransactionStart (or HTransaction).

Tip: Restoring the database consistency

If a breakdown (power failure, reboot, ...) occurs during a transaction, the data files may become corrupted: the transaction was neither validated, nor canceled. The transaction file is still found on the computer.
To restore the consistency of the database, you should propose in your application:
  • an option used to maintain the database consistency.
    This option can for example call HTransactionCancel or HTransactionStart/HTransactionEnd.
  • management of error 70034 in the initialization code of project via the WHEN EXCEPTION keyword.
    Therefore, when the error 70034 occurs, the database consistency will be restored by HTransactionCancel, or by HTransactionStart/HTransactionEnd.
Note: this operation can be quite long (according to the number of operations performed in transaction).

Error cases

  • Nesting transactions: The transactions cannot be nested (HTransactionStart cannot be called in a transaction). In this case, the error 70031 occurs.Nesting transactions: The transactions cannot be nested (HTransactionStart or HTransaction cannot be called in a transaction). In this case, the error 70031 occurs.
  • Versions 19 and later
    A fatal error is displayed in the following cases:
    • A transaction is started on all the connections while there is at least one connection in transaction.
    • A transaction is started on a connection while a transaction was already started on all the connections.
    • A transaction is started on all the connections while there is at least one connection whose isolation mode is not "Read Uncommitted".
    New in version 19
    A fatal error is displayed in the following cases:
    • A transaction is started on all the connections while there is at least one connection in transaction.
    • A transaction is started on a connection while a transaction was already started on all the connections.
    • A transaction is started on all the connections while there is at least one connection whose isolation mode is not "Read Uncommitted".
    A fatal error is displayed in the following cases:
    • A transaction is started on all the connections while there is at least one connection in transaction.
    • A transaction is started on a connection while a transaction was already started on all the connections.
    • A transaction is started on all the connections while there is at least one connection whose isolation mode is not "Read Uncommitted".

Transactions and independent HFSQL context

When copying a context, if a transaction is in progress on the first context, the new context is not in transaction. You must call HTransactionStart to start a transaction in the new context.When copying a context, if a transaction is in progress on the first context, the new context is not in transaction. You must call HTransactionStart (or HTransaction) to start a transaction in the new context.
WINDEVWEBDEV - Server codeAjaxUser code (UMC)OLE DBNative Accesses

OLE DB and Native Accesses

HTransactionCancel cannot be used in this version. To start a transaction, use SQLTransaction.Only the syntaxes with connection are taken into account by the Native Accesses that support the transactions. You also have the ability to use SQLTransaction.
Components
WINDEVWEBDEV - Server codeReports and Queries wd230hf.dll
Windows Mobile wp230hf.dll
Java wd230java.jar
Linux wd230hf.so
Android wd230android.jar
Minimum required version
  • Version 9
This page is also available for…
Comments
Example Transaction with Commit 100 in 100
//SQL

SERIAL is int

HTransactionStart(Hfsql)

FOR EACH t0010_enderecoscorreios //leitura da tabela ms sql server // TABELA DE ORIGEM

SERIAL += 1

PROGBAR_01..Value += 1
IF PROGBAR_01..Value = 100 THEN
HTransactionEnd(Hfsql) //commit
PROGBAR_01..Value = 0
HTransactionStart(Hfsql) //start
Multitask(1) //permite compartilhar o processador com os outros prog e serviços windows
END

//HFSQL = MS SQL SERVER 2016 / DEVELOPER
enderecoscorreios.LogradouroAbrev = t0010_enderecoscorreios.LogradouroAbrev
enderecoscorreios.Logradouro = t0010_enderecoscorreios.Logradouro

ok is boolean = HAdd(enderecoscorreios) // gravacao no hfsql
IF ok = False THEN
HTransactionCancel(Hfsql) //Rollback
END

END

Info(SERIAL)
BOLLER
Apr. 13 2017