ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / Managing databases / HFSQL / Managing transactions / WLanguage functions
  • Network application (ISAM database)
  • Locking records
  • Error cases
  • Temporary files created during the transaction (ISAM database)
  • Handling records during a transaction
  • Transactions and independent HFSQL context
  • OLE DB and Native Connectors
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Others
Stored procedures
Starts a transaction on the data files (HFSQL or accessed via a Native Connector) and creates the transaction file.
What information is saved in the transaction file? Whenever a WLanguage function modifies a data file or an index file during a transaction, the former values of the record and the operation performed are stored in the transaction file.
HFSQL Client/Server This function proposes two operating modes of transactions:
  • The transaction can be started on a connection: In this case, a transaction is started only for files associated to this connection. This mode is required to manage the isolation levels of transactions.
  • The transaction can be started on all HFSQL connections (existing ones or future ones). In this case, HTransactionStart starts both an HFSQL Classic transaction (ISAM) and an HFSQL Client/Server transaction.
AndroidAndroid Widget iPhone/iPadIOS WidgetMac Catalyst The management of transactions is available for HFSQL Client/Server databases.
Remark: This function is equivalent to HTransaction.
Example
MyConnection1 is Connection
 
// Start transaction on data files associated with MyConnection1
HTransactionStart(MyConnection1)
 
// Code used to prepare the order to added
// ...
 
WHEN EXCEPTION IN
// Add the order
HAdd(Orders)
// Validate the addition
HTransactionEnd(MyConnection1)
DO
// Delete the order lines
HTransactionCancel(MyConnection1)
END
// Start transaction on the Orders and OrdLine data files
HTransactionStart("C:\Temp\Transaction.trs", "Orders,OrdLine,-Customer")
 
// Code used to prepare the order to added
// ...
 
WHEN EXCEPTION IN
// Add the order
HAdd(Orders)
// Validate the addition
HTransactionEnd()
DO
// Delete the order lines
HTransactionCancel()
END
Syntax

Starting a Client/Server transaction on a specific connection Hide the details

<Result> = HTransactionStart(<Connection> [, <List of data files>])
<Result>: Boolean
  • True if the transaction was started,
  • False if a problem occurs. HErrorInfo returns more details about the error.
<Connection>: Character string or Connection variable
Name of connection to use. This connection corresponds to: If this parameter corresponds to the hAccessHF7 constant, the transaction will be performed on ISAM HFSQL files.
<List of data files>: Optional character string
List of logical names of one or more data files to take into account (or not) in the transaction (in this case, the data file name is preceded by the "-" sign).
If this parameter is not specifiedAll data files used during the transaction will be taken into account in the transaction.
If all data files are prefixed with the "-" sign
For example: "-Customer, -Product"
All data files specified in the list and used during the transaction will not be taken into account by the transaction.
All data files not specified in the list will be taken into account and used during the transaction.
If no data file on the list is prefixed with the "-" sign
For example: "Customer, Product"
All data files specified in the list and used during the transaction will be taken into account in the transaction.
All data files not specified and manipulated during the transaction will be ignored in the transaction.
If some data files are prefixed with "-" and others are not
For example: "-Customer, Product" (equivalent to "Product")
All data files in the list prefixed with "-" and used during the transaction will be ignored in the transaction.
All data files in the list not prefixed with "-" and used during the transaction will be taken into account in the transaction.
The files not specified in the list will be excluded from the transaction.
Native Connectors (Native Accesses) This parameter is ignored. All the data files associated with the connection are in transaction on the native server.

Starting a Client/Server transaction on a specific connection or an ISAM transaction Hide the details

<Result> = HTransactionStart(<Connection> , <Transaction file> , <List of data files>)
<Result>: Boolean
  • True if the transaction was started,
  • False if a problem occurs. HErrorInfo returns more details about the error.
<Connection>: Character string or Connection variable
Connection to use. This connection corresponds to:If this parameter corresponds to an empty string ("") or to the hAccessHF7 constant, the transaction is performed on ISAM HFSQL data files.
<Transaction file>: Character string
HFSQL Classic Full name of the transaction file (used to store the operations performed within the transaction). This file will be automatically deleted when using HTransactionEnd or HTransactionCancel.
If this name corresponds to an empty string, the transaction file will be created in the directory of application files and it will be named: <Project Name>_$TRS_OPERATION.TRS.
HFSQL Client/ServerNative Connectors (Native Accesses) This parameter is ignored. This parameter is taken into account for the HFSQL Classic transactions only (ISAM transactions).
<List of data files>: Character string
List of logical names of one or more data files to take into account (or not) in the transaction (in this case, the data file name is preceded by the "-" sign).
If this parameter is not specifiedAll data files used during the transaction will be taken into account in the transaction.
If all data files are prefixed with the "-" sign
For example: "-Customer, -Product"
All data files specified in the list and used during the transaction will not be taken into account by the transaction.
All data files not specified in the list will be taken into account and used during the transaction.
If no data file on the list is prefixed with the "-" sign
For example: "Customer, Product"
All data files specified in the list and used during the transaction will be taken into account in the transaction.
All data files not specified and manipulated during the transaction will be ignored in the transaction.
If some data files are prefixed with "-" and others are not
For example: "-Customer, Product" (equivalent to "Product")
All data files in the list prefixed with "-" and used during the transaction will be ignored in the transaction.
All data files in the list not prefixed with "-" and used during the transaction will be taken into account in the transaction.
Data files not specified in the list will be excluded from the transaction.
Native Connectors (Native Accesses) This parameter is ignored. All the data files associated with the connection are in transaction on the native server.

Starting an ISAM and/or Client/Server transaction on all the HFSQL Client/Server connections (existing ones or future ones) Hide the details

<Result> = HTransactionStart([<Transaction file> [, <List of files>]])
<Result>: Boolean
  • True if the transaction was started,
  • False if a problem occurs. HErrorInfo returns more details about the error.
<Transaction file>: Optional character string
HFSQL Classic Full name of the transaction file (used to store the operations performed within the transaction). This file will be automatically deleted when using HTransactionEnd or HTransactionCancel.
If this name is not specified or if it corresponds to an empty string, the transaction file will be created in the directory of the data files of the application and it will be named: <Project Name>_$TRS_OPERATION.TRS.
HFSQL Client/ServerNative Connectors (Native Accesses) This parameter is ignored. This parameter is taken into account for the HFSQL Classic transactions only (ISAM transactions).
<List of files>: Optional character string
List of logical names of one or more data files to take into account (or not) in the transaction (in this case, the data file name is preceded by the "-" sign).
If this parameter is not specifiedAll data files used during the transaction will be taken into account in the transaction.
If all data files are prefixed with the "-" sign
For example: "-Customer, -Product"
All data files specified in the list and used during the transaction will not be taken into account by the transaction.
All data files not specified in the list will be taken into account and used during the transaction.
If no data file on the list is prefixed with the "-" sign
For example: "Customer, Product"
All data files specified in the list and used during the transaction will be taken into account in the transaction.
All data files not specified and manipulated during the transaction will be ignored in the transaction.
If some data files are prefixed with "-" and others are not
For example: "-Customer, Product" (equivalent to "Product")
All data files in the list prefixed with "-" and used during the transaction will be ignored in the transaction.
All data files in the list not prefixed with "-" and used during the transaction will be taken into account in the transaction.
Data files not specified in the list will be excluded from the transaction.
Remarks
HFSQL Classic

Network application (ISAM database)

In network, the transaction file can be created on a local disk or on a network drive.
  • If the transaction file is installed on a local computer, this file will contain information regarding the transactions performed by the current computer. In this case, the transaction file is deleted when the transaction is ended.
  • If the transaction file is installed on a network drive (recommended), this file will contain information regarding the transactions performed by several computers. Each computer is identified by a unique number. In this case, the transaction file is deleted when the last transaction is ended.

Locking records

The added, modified or deleted records in a transaction are locked in write mode.

Error cases

  • Nesting transactions: Transactions cannot be nested (i.e. HTransactionStart cannot be called in a transaction). In this case, error 70031 occurs.
  • 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 level is not "Read Uncommitted".
HFSQL Classic

Temporary files created during the transaction (ISAM database)

During the transaction, temporary files (".TRX" extension) are created in the directory containing the data files (".FIC" files). These temporary files must not be deleted. Otherwise, the data handled by the transaction could be damaged.
Remark: These temporary files are automatically deleted at the end of the transaction.

Handling records during a transaction

During a transaction, some rules must be complied with when handling the records. For more details, see Transactions: Handling records during a transaction.

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.
Native Connectors (Native Accesses)

OLE DB and Native Connectors

Only the syntaxes with connection are taken into account by the Native Accesses that support the transactions. You can also use SQLTransaction.
Component: wd300hf.dll
Minimum version required
  • Version 9
This page is also available for…
Comments
Exemplo 2
Procedure FazALGO

MyConnection1 is Connection

// Start transaction on data files associated with MyConnection1

HTransaction(MyConnection1)

// Add the order
Add_Nota()
Add_Faturamento()
Add_Comissao()

WHEN EXCEPTION IN

// Validate the addition Tudo ok

HTransactionEnd(MyConnection1)
//Commit

DO

//Algo deu errado Rollback

// Delete the order lines
HTransactionCancel(MyConnection1)
//Rollback

EnviaEmail()

End
Boller
19 Apr. 2024
Example 01
MyConnection1 is Connection

myErrors is int = 0

// Start transaction on data files associated with MyConnection1

HTransactionStart(MyConnection1)

WHEN EXCEPTION IN


if HAdd(tabelaEstoque) = false
myErrors += 1
end

if HAdd(TabelaFinanceiro)=false
myErrors += 1
end

if HAdd(TabelaContabil)=false
myErrors += 1
end

// Validate the addition

if myErrors = 0
HTransactionEnd(MyConnection1)
else
HTransactionCancel(MyConnection1)
end

DO

// Delete the order lines
HTransactionCancel(MyConnection1)

END
Boller
09 Aug. 2022

Last update: 06/04/2024

Send a report | Local help