PC SOFT

WINDEVWEBDEV AND WINDEV MOBILE
ONLINE HELP

Home | Sign in | English UK
  • 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
WEBDEV - Server codeAjaxOLE 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)
WEBDEV - Server codeAjaxOLE 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)
Minimum version required
  • Version 9
This page is also available for…
Comments
Click [Add] to post a comment