AYUDA EN LÍNEA
 WINDEVWEBDEV Y WINDEV MOBILE

Ayuda / WLanguage / Administrar bases de datos / Funciones SQL
  • Example 1: Transaction on a database opened by SQLConnect
  • Example 2: Changing the name of the database (OLE DB)
SQLTransaction (Example)
Example 1: Transaction on a database opened by SQLConnect
Reportes y ConsultasOLE DB The following example is used to perform operations in a transaction during an access to a database performed by SQLConnect. Then, the transaction is canceled: the operations are not saved in the data file.
ConnectionNum is int = SQLConnect("MyDatabase", "User", "Password", "", "OLEDB", "MyProvider")
IF ConnectionNum = 0 THEN
  SQLInfo()
  Error("Error while opening the connection:" + SQL.MesError)
ELSE
  // Put the connection in transaction
  SQLTransaction(sqlStart)
  // Modify the value of all the AFile.AnItem items
  IF SQLExec("UPDATE AFile SET AnItem = 'new value'", "UpdateQuery") = 0 THEN
      SQLInfo("UpdateQuery")
      Error("Error while running the query:" + SQL.MesError)
      SQLTransaction(sqlCommit)
  END
  // Cancel the transaction
  SQLTransaction(sqlRollBack)
  // The content of AFile did not change
END
Example 2: Changing the name of the database (OLE DB)
Reportes y ConsultasOLE DB The following example is used to perform operations in a transaction during an access to a data file that uses a connection described in the analysis.
Then, the transaction is canceled: the operations are not saved in the data file.
In this example, AFile is an OLE DB data file described in the data model editor. This data file uses the connection named MyConnection described in the data model editor.
HReadFirst(AFile)
// Put the connection in transaction
SQLTransaction(sqlStart, MyConnection)
// Modify the value of the item
AFile.AnItem = "new item"
HModify(AFile)
// Cancel the transaction
SQLTransaction(sqlRollBack, MyConnection)
Versión mínima requerida
  • Versión 9
Esta página también está disponible para…
Comentarios
Haga clic en [Agregar] para publicar un comentario

Última modificación: 27/05/2022

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