AYUDA EN LÍNEA
 WINDEVWEBDEV Y WINDEV MOBILE

Este contenido se ha traducido automáticamente.  Haga clic aquí  para ver la versión en inglés.
Ayuda / WLanguage / Administrar bases de datos / HFSQL / Gestión de transacciones / Funciones WLanguage
  • Location and access to data files
  • Detecting an error
  • Tip: Restoring the consistency of the database
  • Error cases
  • Transactions and independent HFSQL context
  • OLE DB and Native Connectors
WINDEV
WindowsLinuxJavaReportes y ConsultasCódigo de Usuario (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Código Navegador
WINDEV Mobile
AndroidWidget Android iPhone/iPadIOS WidgetApple WatchMac Catalyst
Otros
Procedimientos almacenados
If a transaction is in progressrolls back all operations performed on data files in transactions since the start of the transaction. In this case, the transaction is canceled without interrupting the program execution.
If no transaction is in progressrestores database consistency and rolls back a failed transaction (e.g. in the event of a power failure).
Note: A failed transaction can be rolled back 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.
Note The HTransactionFree function transforms all records "in transaction" into "normal" records if they do not belong to a transaction currently in progress.
Ejemplo
MyConnection is Connection

// Start transaction on data files associated with MyConnection
HTransactionStart(MyConnection)
Add_Order()
WHEN EXCEPTION IN
	// Add the order
	HAdd(Orders) 
	// Validate the addition
	HTransactionEnd(MyConnection)
DO
	// Delete the order lines
	HTransactionCancel(MyConnection)
END
WEBDEV - Código ServidorAjaxHFSQL Classic
// Start transaction on the Orders and OrdLine data 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
WEBDEV - Código ServidorAjaxHFSQL Client/Server
// Start transaction on the Orders and OrdLine data 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
Sintaxis

Canceling a current transaction or an interrupted transaction on a Client/Server connection Ocultar los detalles

<Result> = HTransactionCancel(<Connection>)
<Result>: Boolean
  • True if the transaction was canceled,
  • False if a problem occurs. 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>: Character string or Connection variable
Connection to use. This connection corresponds to: If this parameter corresponds to the constant hAccessHF7the transaction is rolled back on HFSQL Classic (ISAM) data files.

Canceling a current transaction or an interrupted transaction on all connections (HFSQL Classic or Client/Server) Ocultar los detalles

<Result> = HTransactionCancel([<Transaction file>])
<Result>: Boolean
  • True if the transaction was canceled,
  • False if a problem occurs. HErrorInfo returns more details about the error.
Caution:
  • HFSQL Classic If the <Transaction file> parameter is not specified, the current transaction is canceled.
  • If a transaction is in progressALL transactions in progress are rolled back (HFSQL Classic transactions and/or HFSQL Client/Server transactions).
  • If there is no transaction in progressALL interrupted transactions are rolled back (in HFSQL Classic and Client/Server).
<Transaction file>: Optional character string
HFSQL Classic 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 DBConectores Nativos This parameter is ignored.

Canceling an interrupted transaction on a Client/Server database (to be used if no transaction is in progress) Ocultar los detalles

<Result> = HTransactionCancel(<Connection> , <Database>)
<Result>: Boolean
  • True if the transaction was canceled,
  • False if a problem occurs. 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 the relevant database. An error occurs if this parameter corresponds to an empty string ("").
WEBDEV - Código ServidorAjaxHFSQL Classic

Canceling a transaction (to be used if no transaction is in progress) Ocultar los detalles

<Result> = HTransactionCancel(<Transaction file> , <Connection>)
<Result>: Boolean
  • True if the transaction was canceled,
  • False if a problem occurs. HErrorInfo returns more details 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 Ocultar los detalles

<Result> = HTransactionCancel(<Connection> , <Transaction to cancel>)
<Result>: Boolean
  • True if the transaction was canceled,
  • False if a problem occurs. HErrorInfo returns more details about the error.
Warning: Only interrupted transactions on the specified database are rolled back.
<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.
Observaciones

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 consistency of the database

If a breakdown (power outage, 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 project initialization code 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 take a relatively long time (depending on the number of transactions performed).

Error cases

  • Transaction nesting: it is not possible to nest transactions (i.e. to call function HTransactionStart or function HTransaction within 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".

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 - Código ServidorAjaxOLE DBConectores Nativos

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.
Componente: wd300hf.dll
Versión mínima requerida
  • Versión 9
Esta página también está disponible para…
Comentarios
Uso de HTransactionCancel()
El uso de HTransactionCancel en el caso de no grabar correctamente un Registro.

// Se Inicia Transaccion
IF HTransactionStart(Conn)=<True THEN
HReset(Cliente)
ScreenToFile()
// Se intenta Registrar al Cliente
IF HAdd(Cliente)=False THEN
// EN caso de tener un problena se Cancela la transaccion
HTransactionCancel(Conn)
Result ("Error Registrando Cliente")
END
// Se Finaliza la transaccion
IF HTransactionEND(Conn)=False THEN
// EN caso de tener un problena se Cancela la transaccion
HTransactionCancel(Conn)
Result ("Error al Finalizar Transaccion")
ELSE
Result ("")
END
ELSE
Result ("No se logró iniciar transacción")
END
Mecias SAMUEL
02 08 2022
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
13 04 2017

Última modificación: 28/03/2025

Señalar un error o enviar una sugerencia | Ayuda local