PC SOFT

ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Home | Sign in | English EN
This content has been translated automatically. Click here to view the French version.
  • 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 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
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).
Remark: 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.
Remark: From version 19, HFSQL is the new name of HyperFileSQL.
Example
Versions 19 and later
MaConnexion is Connection
 
// Début de la transaction sur les fichiers de données associés à la connexion MaConnexion
HTransactionStart(MaConnexion)
Ajout_Commande()
WHEN EXCEPTION IN
// Ajout de la commande
HAdd(Commande)
// Validation de l'ajout
HTransactionEnd(MaConnexion)
DO
// Suppression des lignes de commandes
HTransactionCancel(MaConnexion)
END
New in version 19
MaConnexion is Connection
 
// Début de la transaction sur les fichiers de données associés à la connexion MaConnexion
HTransactionStart(MaConnexion)
Ajout_Commande()
WHEN EXCEPTION IN
// Ajout de la commande
HAdd(Commande)
// Validation de l'ajout
HTransactionEnd(MaConnexion)
DO
// Suppression des lignes de commandes
HTransactionCancel(MaConnexion)
END
MaConnexion is Connection
 
// Début de la transaction sur les fichiers de données associés à la connexion MaConnexion
HTransactionStart(MaConnexion)
Ajout_Commande()
WHEN EXCEPTION IN
// Ajout de la commande
HAdd(Commande)
// Validation de l'ajout
HTransactionEnd(MaConnexion)
DO
// Suppression des lignes de commandes
HTransactionCancel(MaConnexion)
END
WEBDEV - Server codeAjaxHFSQL
// Début de la transaction sur les fichiers de données Commande et LigneCde
HTransactionStart("C:\Temp\Transaction.trs", "Commande, LigneCde, -Client")
Ajout_Commande()
WHEN EXCEPTION IN
// Ajout de la commande
HAdd(Commande)
// Validation de l'ajout
HTransactionEnd()
DO
// Suppression des lignes de commandes
HTransactionCancel()
END
WEBDEV - Server codeAjaxHFSQL Client/Server
// Début de la transaction sur les fichiers de données Commande et LigneCde
HTransactionStart("Commande,LigneCde,-Client")
Ajout_Commande()
WHEN EXCEPTION IN
// Ajout de la commande
HAdd(Commande)
// Validation de l'ajout
HTransactionEnd()
DO
// Suppression des lignes de commandes
HTransactionCancel()
END
Syntax
Versions 19 and later

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

<Result> = HTransactionCancel(<Connection>)
<Result>: Boolean
  • True if the transaction was canceled,
  • False if a problem occurred. The HErrorInfo function provides more information 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>: Character string or Connection variable
Connection to use. This connection corresponds to: If this parameter corresponds to the hAccessHF7 constant, the transaction will be canceled on the HFSQL Classic (ISAM) files.
New in version 19

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

<Result> = HTransactionCancel(<Connection>)
<Result>: Boolean
  • True if the transaction was canceled,
  • False if a problem occurred. The HErrorInfo function provides more information 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>: Character string or Connection variable
Connection to use. This connection corresponds to: If this parameter corresponds to the hAccessHF7 constant, the transaction will be canceled on the HFSQL Classic (ISAM) files.

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

<Result> = HTransactionCancel(<Connection>)
<Result>: Boolean
  • True if the transaction was canceled,
  • False if a problem occurred. The HErrorInfo function provides more information 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>: Character string or Connection variable
Connection to use. This connection corresponds to: If this parameter corresponds to the hAccessHF7 constant, the transaction will be canceled on the HFSQL Classic (ISAM) files.

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

<Result> = HTransactionCancel([<Transaction file>])
<Result>: Boolean
  • True if the transaction was canceled,
  • False if a problem occurred. The HErrorInfo function provides more information about the error.
Caution:
  • HFSQL If the <Transaction file> parameter 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).
<Transaction file>: Optional character string
HFSQL Name and path of transaction file to cancel:
  • 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 Connectors (Native Accesses) This parameter is ignored.

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

<Result> = HTransactionCancel(<Connection> , <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>: Character string or Connection variable
Connection to use. This connection corresponds to: If this parameter corresponds to the hAccessHF7 constant, only transactions interrupted in HFSQL Classic mode will be canceled.
<Database>: Character string
Name of relevant database. An error occurs if this parameter corresponds to an empty string ("").
WEBDEV - Server codeAjaxHFSQL

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

<Result> = HTransactionCancel(<Transaction file> , <Connection>)
<Result>: Boolean
  • True if the transaction was canceled,
  • False if a problem occurred. The HErrorInfo function provides more information about the error.
Caution:
  • If the <Transaction file> parameter 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.
<Transaction file>: Character string
Name and path of transaction file to cancel.
This parameter must be identical to the name specified in HTransactionStart (or in HTransaction).
<Connection>: Character string or Connection variable
Connection to use. This connection corresponds to: If this parameter corresponds to the hAccessHF7 constant, only transactions interrupted in HFSQL Classic mode will be canceled.

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

<Result> = HTransactionCancel(<Connection> , <Transaction to cancel>)
<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>: Character string or Connection variable
Connection to use. This connection corresponds to: If this parameter corresponds to the hAccessHF7 constant, only the transaction interrupted in HFSQL Classic mode will be canceled.
<Transaction to cancel>: 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 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.
Remark: this operation can be quite long (according to the number of operations performed in transaction).

Error cases

  • Nesting transactions: Transactions cannot be nested (that is, function HTransactionStart or function HTransaction cannot be called within a transaction). In this case, 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 (or HTransaction) to start a transaction in the new context.
WEBDEV - Server codeAjaxOLE DBNative Connectors (Native Accesses)

OLE DB and Native Connectors

Only syntaxes with connection are taken into account by the Native Connectors that support transactions. You can also use SQLTransaction.
Component: wd270hf.dll
Minimum version required
  • Version 9
This page is also available for…
Comments
Click [Add] to post a comment