ScriptForge (SF_Database) manage transactions

Transactions are managed by next UNO properties:
   XConnection.AutoCommit
   XConnection.TransactionIsolation
(They seem very easy to use but, in practice,
are not easy at all)

Usually all transactions are in auto-commit mode,
that means, a commit takes place after each
single SQL command.

Switching auto-commit off  means however that
the connection needs to be of type "ISOLATED"
and not of the default type "SHARED".

=> The usual shared connection must be closed.
   As a consequence, all rowsets/resultsets linked
   to the shared connection need to be closed as well.
=> Additionally the buffers must be emptied (flushed)
   to make committed data visible in the Base user
   interface.

All above aspects and constraints are managed in the
   database.SetTransactionMode(transactionmode)
   database.Commit()
   database.Rollback()
methods transparently for the user scripts.

The [transactionmode] argument has as value one of
the TransactionIsolation constants.
Without argument, database.SetTransactionMode()
restores the automatic mode.

The manual transaction mode is available for both
Basic and Python scripts.
Its implementation will require an update of the
documentation about the Database service.

Change-Id: I214bd91a1744d6d24609bc5efc987152c6e946c9
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/159867
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins
This commit is contained in:
Jean-Pierre Ledure
2023-11-24 09:54:59 +01:00
parent 9137bd2dd3
commit 9b5b313a2f
4 changed files with 340 additions and 20 deletions
@@ -1794,6 +1794,9 @@ class SFDatabases:
def CloseDatabase(self):
return self.ExecMethod(self.vbMethod, 'CloseDatabase')
def Commit(self):
return self.ExecMethod(self.vbMethod, 'Commit')
def CreateDataset(self, sqlcommand, directsql = False, filter = '', orderby = ''):
return self.ExecMethod(self.vbMethod, 'CreateDataset', sqlcommand, directsql, filter, orderby)
@@ -1831,9 +1834,15 @@ class SFDatabases:
def OpenTable(self, tablename):
return self.ExecMethod(self.vbMethod, 'OpenTable', tablename)
def Rollback(self):
return self.ExecMethod(self.vbMethod, 'Rollback')
def RunSql(self, sqlcommand, directsql = False):
return self.ExecMethod(self.vbMethod, 'RunSql', sqlcommand, directsql)
def SetTransactionMode(self, transactionmode = 0):
return self.ExecMethod(self.vbMethod, 'SetTransactionMode', transactionmode)
# #########################################################################
# SF_Dataset CLASS
# #########################################################################