[Libreoffice-commits] core.git: wizards/source
Jean-Pierre Ledure (via logerrit)
logerrit at kemper.freedesktop.org
Sun Apr 11 16:34:37 UTC 2021
wizards/source/scriptforge/SF_PythonHelper.xba | 12 ++--
wizards/source/scriptforge/python/scriptforge.py | 60 ++++++++++++++++++++++-
wizards/source/sfdatabases/SF_Database.xba | 3 -
3 files changed, 67 insertions(+), 8 deletions(-)
New commits:
commit 77cb68db10cdd0dac9409cff0f59637b25e6d9a7
Author: Jean-Pierre Ledure <jp at ledure.be>
AuthorDate: Sun Apr 11 17:17:46 2021 +0200
Commit: Jean-Pierre Ledure <jp at ledure.be>
CommitDate: Sun Apr 11 18:33:59 2021 +0200
ScriptForge - (scriptforge.py) Database class
New class to run from Python DDL + DML SQL commands
on databases embedded in or connected to Base documents.
GetRows() is hardcoded as an exception (cfr. bug #138155) in
_PythonDispatcher() - SF_PythonHelper.xba
to be able to return 2D arrays to Python.
Fix returned empty arrays in the Basic-Python engine:
the standard bridge ignores them and returns a null byte
sequence instead of an empty tuple.
Change-Id: I336ea0b585b759b998af0871d25bfd384a2e66ae
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113953
Tested-by: Jean-Pierre Ledure <jp at ledure.be>
Tested-by: Jenkins
Reviewed-by: Jean-Pierre Ledure <jp at ledure.be>
diff --git a/wizards/source/scriptforge/SF_PythonHelper.xba b/wizards/source/scriptforge/SF_PythonHelper.xba
index 328978033290..69306d1f8884 100644
--- a/wizards/source/scriptforge/SF_PythonHelper.xba
+++ b/wizards/source/scriptforge/SF_PythonHelper.xba
@@ -708,8 +708,10 @@ Try:
ElseIf ((CallType And vbMethod) + (CallType And cstArgArray)) = vbMethod + cstArgArray Or _
((CallType And vbMethod) + (CallType And cstRetArray)) = vbMethod + cstRetArray Then
Select Case sServiceName
+ Case "SFDatabases.Database"
+ If Script = "GetRows" Then vReturn = vBasicObject.GetRows(vArgs(0), vArgs(1), vArgs(2), vArgs(3))
Case "SFDocuments.Document"
- If Script = "Forms" Then vReturn = vBasicObject.Forms(vArgs(0))
+ If Script = "Forms" Then vReturn = vBasicObject.Forms(vArgs(0))
Case "SFDocuments.Base"
Select Case Script
Case "FormDocuments" : vReturn = vBasicObject.FormDocuments()
@@ -726,13 +728,11 @@ Try:
End Select
Case "SFDocuments.Form"
Select Case Script
- Case "Controls" : vReturn = vBasicObject.Controls(vArgs(0))
- Case "Subforms" : vReturn = vBasicObject.Subforms(vArgs(0))
+ Case "Controls" : vReturn = vBasicObject.Controls(vArgs(0))
+ Case "Subforms" : vReturn = vBasicObject.Subforms(vArgs(0))
End Select
Case "SFDocuments.FormControl"
- Select Case Script
- Case "Controls" : vReturn = vBasicObject.Controls(vArgs(0))
- End Select
+ If Script = "Controls" Then vReturn = vBasicObject.Controls(vArgs(0))
End Select
' Methods in class modules are invoked with CallByName
diff --git a/wizards/source/scriptforge/python/scriptforge.py b/wizards/source/scriptforge/python/scriptforge.py
index e3d4bdfa63e6..d722b3ca2f1a 100644
--- a/wizards/source/scriptforge/python/scriptforge.py
+++ b/wizards/source/scriptforge/python/scriptforge.py
@@ -311,7 +311,9 @@ class ScriptForge(object, metaclass = _Singleton):
return subcls(returntuple[cstValue], returntuple[cstType], returntuple[cstClass],
returntuple[cstName])
elif returntuple[cstVarType] >= ScriptForge.V_ARRAY:
- pass
+ # Intercept empty array
+ if isinstance(returntuple[cstValue], uno.ByteSequence):
+ return ()
elif returntuple[cstVarType] == ScriptForge.V_DATE:
try: # Anticipate fromisoformat('00:00:00') and alike
dat = None
@@ -1339,6 +1341,62 @@ class SFScriptForge:
return self.Execute(self.vbMethod, 'WindowExists', windowname)
+# #####################################################################################################################
+# SFDatabases CLASS (alias of SFDatabases Basic library) ###
+# #####################################################################################################################
+class SFDatabases:
+ """
+ The SFDatabases class manages databases embedded in or connected to Base documents
+ """
+ pass
+
+ # #########################################################################
+ # SF_Document CLASS
+ # #########################################################################
+ class SF_Database(SFServices):
+ """
+ Each instance of the current class represents a single database, with essentially its tables, queries
+ and data
+ The exchanges with the database are done in SQL only.
+ To make them more readable, use optionally square brackets to surround table/query/field names
+ instead of the (RDBMS-dependent) normal surrounding character.
+ SQL statements may be run in direct or indirect mode. In direct mode the statement is transferred literally
+ without syntax checking nor review to the database engine.
+ """
+ # Mandatory class properties for service registration
+ serviceimplementation = 'basic'
+ servicename = 'SFDatabases.Database'
+ servicesynonyms = ('database', 'sfdatabases.database')
+ serviceproperties = dict(Queries = False, Tables = False, XConnection = False, XMetaData = False)
+
+ def CloseDatabase(self):
+ return self.Execute(self.vbMethod, 'CloseDatabase')
+
+ def DAvg(self, expression, tablename, criteria = ''):
+ return self.Execute(self.vbMethod, 'DAvg', expression, tablename, criteria)
+
+ def DCount(self, expression, tablename, criteria = ''):
+ return self.Execute(self.vbMethod, 'DCount', expression, tablename, criteria)
+
+ def DLookup(self, expression, tablename, criteria = '', orderclause = ''):
+ return self.Execute(self.vbMethod, 'DLookup', expression, tablename, criteria, orderclause)
+
+ def DMax(self, expression, tablename, criteria = ''):
+ return self.Execute(self.vbMethod, 'DMax', expression, tablename, criteria)
+
+ def DMin(self, expression, tablename, criteria = ''):
+ return self.Execute(self.vbMethod, 'DMin', expression, tablename, criteria)
+
+ def DSum(self, expression, tablename, criteria = ''):
+ return self.Execute(self.vbMethod, 'DSum', expression, tablename, criteria)
+
+ def GetRows(self, sqlcommand, directsql = False, header = False, maxrows = 0):
+ return self.Execute(self.vbMethod + self.flgArrayRet, 'GetRows', sqlcommand, directsql, header, maxrows)
+
+ def RunSql(self, sqlcommand, directsql = False):
+ return self.Execute(self.vbMethod, 'RunSql', sqlcommand, directsql)
+
+
# #####################################################################################################################
# SFDocuments CLASS (alias of SFDocuments Basic library) ###
# #####################################################################################################################
diff --git a/wizards/source/sfdatabases/SF_Database.xba b/wizards/source/sfdatabases/SF_Database.xba
index 0c39c5742adf..d76ae575cc6e 100644
--- a/wizards/source/sfdatabases/SF_Database.xba
+++ b/wizards/source/sfdatabases/SF_Database.xba
@@ -391,7 +391,8 @@ Public Function Methods() As Variant
''' Return the list of public methods of the Database service as an array
Methods = Array( _
- "DAvg" _
+ "CloseDatabase" _
+ , "DAvg" _
, "DCount" _
, "DLookup" _
, "DMax" _
More information about the Libreoffice-commits
mailing list