summaryrefslogtreecommitdiff
path: root/wizards
diff options
context:
space:
mode:
authorJean-Pierre Ledure <jp@ledure.be>2021-04-11 17:17:46 +0200
committerJean-Pierre Ledure <jp@ledure.be>2021-04-11 18:33:59 +0200
commit77cb68db10cdd0dac9409cff0f59637b25e6d9a7 (patch)
tree30e099b483335a1a6b11f87838e9a397510513ce /wizards
parent84962c21b41d2e65546486cb73e7f3785487265a (diff)
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@ledure.be> Tested-by: Jenkins Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Diffstat (limited to 'wizards')
-rw-r--r--wizards/source/scriptforge/SF_PythonHelper.xba12
-rw-r--r--wizards/source/scriptforge/python/scriptforge.py60
-rw-r--r--wizards/source/sfdatabases/SF_Database.xba3
3 files changed, 67 insertions, 8 deletions
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 &quot;SFDatabases.Database&quot;
+ If Script = &quot;GetRows&quot; Then vReturn = vBasicObject.GetRows(vArgs(0), vArgs(1), vArgs(2), vArgs(3))
Case &quot;SFDocuments.Document&quot;
- If Script = &quot;Forms&quot; Then vReturn = vBasicObject.Forms(vArgs(0))
+ If Script = &quot;Forms&quot; Then vReturn = vBasicObject.Forms(vArgs(0))
Case &quot;SFDocuments.Base&quot;
Select Case Script
Case &quot;FormDocuments&quot; : vReturn = vBasicObject.FormDocuments()
@@ -726,13 +728,11 @@ Try:
End Select
Case &quot;SFDocuments.Form&quot;
Select Case Script
- Case &quot;Controls&quot; : vReturn = vBasicObject.Controls(vArgs(0))
- Case &quot;Subforms&quot; : vReturn = vBasicObject.Subforms(vArgs(0))
+ Case &quot;Controls&quot; : vReturn = vBasicObject.Controls(vArgs(0))
+ Case &quot;Subforms&quot; : vReturn = vBasicObject.Subforms(vArgs(0))
End Select
Case &quot;SFDocuments.FormControl&quot;
- Select Case Script
- Case &quot;Controls&quot; : vReturn = vBasicObject.Controls(vArgs(0))
- End Select
+ If Script = &quot;Controls&quot; Then vReturn = vBasicObject.Controls(vArgs(0))
End Select
&apos; 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
@@ -1340,6 +1342,62 @@ class SFScriptForge:
# #####################################################################################################################
+# 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) ###
# #####################################################################################################################
class SFDocuments:
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
&apos;&apos;&apos; Return the list of public methods of the Database service as an array
Methods = Array( _
- &quot;DAvg&quot; _
+ &quot;CloseDatabase&quot; _
+ , &quot;DAvg&quot; _
, &quot;DCount&quot; _
, &quot;DLookup&quot; _
, &quot;DMax&quot; _