Promotic
WikipediaLinkedInYoutubeTwitterFacebook

DbBeginTrans - method of object PmAdo

Description:
Starts new transaction over the connected database.
Syntax:
DbBeginTrans
Calling:
oDb.DbBeginTrans
Note:
The DbBeginTrans method starts a new transaction over the connected database. All following operations over this database will be confirmed as complete transaction by the DbCommitTrans method or cancelled by DbRollbackTrans method. The transaction must be supported by both the connected database and the provider.
Example:
Adding new recort into tables table1 and table2 using transaction. If adding the record to any of the tables fails then all operations from the beginning of the transaction are cancelled. I.e. both records are added or no record is added. The failure of the operation can be detected in PmAdo object by LastErr property.
Dim oDb, nLastErr1, nLastErr2
Set oDb = pMe.Pm("/TestAdoDb")
If oDb.LastErr() = 0 Then
  oDb.DbExecute "", "INSERT table1 (name, value) VALUES ('pi', 3.14)", ""
  nLastErr1 = oDb.LastErr()
  oDb.DbExecute "", "INSERT table2 (name, value) VALUES ('pi', 3.14)", ""
  nLastErr2 = oDb.LastErr()
  If nLastErr1 = 0 And nLastErr2 = 0 Then
    oDb.DbCommitTrans
  Else
    Pm.Debug oDb.LastTextErr
    oDb.DbRollbackTrans
End If
© MICROSYS, spol. s r. o.Tavičská 845/21 703 00 Ostrava-Vítkovice