wizards/source/scriptforge/python/scriptforge.py |   19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

New commits:
commit 5dac0fe157a5c35824cab2c27e391ff7a0d1d421
Author:     Jean-Pierre Ledure <j...@ledure.be>
AuthorDate: Sun Nov 12 16:33:02 2023 +0100
Commit:     Jean-Pierre Ledure <j...@ledure.be>
CommitDate: Sun Nov 12 17:44:55 2023 +0100

    ScriptForge (SFDatabases) fix dates processing in GetRows
    
    The
       database.GetRows()
       dataset.GetRows()
    methods return an array of data collected
    in a database table or query.
    
    When a column has the type DATE, the transmission
    of their values through the Basic-Python bridge
    require them to be converted upfront to UNO
    DateTime structures.
    
    The later conversion from UNO DateTime to the python
    datetime.datetime structure has been added with
    this patch.
    
    No impact on Basic scripts.
    
    The documentation does not need to be changed.
    
    Change-Id: I7a6533aff70d2d1402bfc3f057b65a4940148cc4
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/159348
    Reviewed-by: Jean-Pierre Ledure <j...@ledure.be>
    Tested-by: Jenkins

diff --git a/wizards/source/scriptforge/python/scriptforge.py 
b/wizards/source/scriptforge/python/scriptforge.py
index bcaff12f5cc5..77e0119809da 100644
--- a/wizards/source/scriptforge/python/scriptforge.py
+++ b/wizards/source/scriptforge/python/scriptforge.py
@@ -348,8 +348,8 @@ class ScriptForge(object, metaclass = _Singleton):
         #   A Basic object to be mapped onto a new Python class instance
         #   A UNO object
         #   A set of property values to be returned as a dict()
-        #   An array, tuple or tuple of tuples
-        #   A scalar or Nothing
+        #   An array, tuple or tuple of tuples - manage dates inside
+        #   A scalar, Nothing, a date
         returnvalue = returntuple[cstValue]
         if returntuple[cstVarType] == ScriptForge.V_OBJECT and 
len(returntuple) > cstClass:  # Skip Nothing
             if returntuple[cstClass] == ScriptForge.objUNO:
@@ -372,6 +372,16 @@ class ScriptForge(object, metaclass = _Singleton):
             # Intercept empty array
             if isinstance(returnvalue, uno.ByteSequence):
                 return ()
+            if flags & SFServices.flgDateRet == SFServices.flgDateRet:  # Bits 
comparison
+                # Intercept all UNO dates in the 1D or 2D array
+                if isinstance(returnvalue[0], tuple):   # tuple of tuples
+                    arr = []
+                    for i in range(len(returnvalue)):
+                        row = 
tuple(map(SFScriptForge.SF_Basic.CDateFromUnoDateTime, returnvalue[i]))
+                        arr.append(row)
+                    returnvalue = tuple(arr)
+                else:                                   # 1D tuple
+                    returnvalue = 
tuple(map(SFScriptForge.SF_Basic.CDateFromUnoDateTime, returnvalue))
         elif returntuple[cstVarType] == ScriptForge.V_DATE:
             dat = SFScriptForge.SF_Basic.CDateFromUnoDateTime(returnvalue)
             return dat
@@ -1806,7 +1816,8 @@ class SFDatabases:
             return self.ExecMethod(self.vbMethod, 'DSum', expression, 
tablename, criteria)
 
         def GetRows(self, sqlcommand, directsql = False, header = False, 
maxrows = 0):
-            return self.ExecMethod(self.vbMethod + self.flgArrayRet, 
'GetRows', sqlcommand, directsql, header, maxrows)
+            return self.ExecMethod(self.vbMethod + self.flgArrayRet + 
self.flgDateRet, 'GetRows', sqlcommand,
+                                   directsql, header, maxrows)
 
         def OpenFormDocument(self, formdocument):
             return self.ExecMethod(self.vbMethod, 'OpenFormDocument', 
formdocument)
@@ -1870,7 +1881,7 @@ class SFDatabases:
             return self.ExecMethod(self.vbMethod, 'ExportValueToFile', 
fieldname, filename, overwrite)
 
         def GetRows(self, header = False, maxrows = 0):
-            return self.ExecMethod(self.vbMethod + self.flgArrayRet, 
'GetRows', header, maxrows)
+            return self.ExecMethod(self.vbMethod + self.flgArrayRet + 
self.flgDateRet, 'GetRows', header, maxrows)
 
         def GetValue(self, fieldname):
             return self.ExecMethod(self.vbMethod, 'GetValue', fieldname)

Reply via email to