wizards/source/scriptforge/SF_UI.xba              |   43 ++++++++++++++--------
 wizards/source/scriptforge/python/scriptforge.py  |    7 ++-
 wizards/source/scriptforge/python/scriptforge.pyi |   15 ++++---
 wizards/source/scriptforge/script.xlb             |   28 +++++++-------
 4 files changed, 57 insertions(+), 36 deletions(-)

New commits:
commit 11d8753e0351ffaddb862c288f4b200e6f8ff925
Author:     Jean-Pierre Ledure <j...@ledure.be>
AuthorDate: Sat May 3 17:26:42 2025 +0200
Commit:     Jean-Pierre Ledure <j...@ledure.be>
CommitDate: Sun May 4 10:18:48 2025 +0200

    ScriptForge (UI) extend scope of CreateBaseDocument
    
    The
        ui.CreateBaseDocument()
    method accepted so far to create Base documents
    either embedding HSQLDB or FIREBIRD databases
    or linked to a Cals spreadsheet.
    
    It is now extended to make the new Base document
    finding its datasource in an external Firebird
    database file.
    
    The previous signature
        ui.CreateBaseDocument(FileName, EmbeddedDatabase,
            CalcFileName)
    is replaced by
        ui.CreateBaseDocument(FileName, EmbeddedDatabase,
            DataFileName, CalcFileName)
    => The CalcFileName argument is deprecated. When present,
       it is copied to DataFileName.
    The EmbeddedDatabase argument may take next values:
        HSQLDB (default), FIREBIRD, FIREBIRD_EXTERNAL or CALC.
    
    The change is valid for both Basic and Python scripts.
    The documentation should be upgraded.
    
    Change-Id: I5daf418f50739baca6be899eb1444d1b99cf89aa
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/184935
    Reviewed-by: Jean-Pierre Ledure <j...@ledure.be>
    Tested-by: Jenkins

diff --git a/wizards/source/scriptforge/SF_UI.xba 
b/wizards/source/scriptforge/SF_UI.xba
index b560c26b9067..656cc9553551 100644
--- a/wizards/source/scriptforge/SF_UI.xba
+++ b/wizards/source/scriptforge/SF_UI.xba
@@ -263,9 +263,11 @@ REM 
----------------------------------------------------------------------------
 Public Function CreateBaseDocument(Optional ByVal FileName As Variant _
                                                        , Optional ByVal 
EmbeddedDatabase As Variant _
                                                        , Optional ByVal 
RegistrationName As Variant _
+                                                       , Optional ByVal 
DataFileName As Variant _
                                                        , Optional ByVal 
CalcFileName As Variant _
                                                        ) As Object
 &apos;&apos;&apos; Create a new LibreOffice Base document embedding an empty 
database of the given type
+&apos;&apos;&apos;     or finding its datasource in an external database file 
(Calc or Firebird).
 &apos;&apos;&apos;     Args:
 &apos;&apos;&apos;             FileName: Identifies the file to create. It 
must follow the SF_FileSystem.FileNaming notation
 &apos;&apos;&apos;                     If the file already exists, it is 
overwritten without warning
@@ -273,11 +275,14 @@ Public Function CreateBaseDocument(Optional ByVal 
FileName As Variant _
 &apos;&apos;&apos;             RegistrationName: the name used to store the 
new database in the databases register
 &apos;&apos;&apos;                     If &quot;&quot; (default), no 
registration takes place
 &apos;&apos;&apos;                     If the name already exists it is 
overwritten without warning
-&apos;&apos;&apos;             CalcFileName: only when EmbedddedDatabase = 
&quot;CALC&quot;, the name of the file containing the tables as Calc sheets
+&apos;&apos;&apos;             DataFileName: when EmbedddedDatabase = 
&quot;CALC&quot;, the name of the file containing the tables as Calc sheets,
+&apos;&apos;&apos;                     when EmbeddedDatabase = 
&quot;FIREBIRD_EXTERNAL&quot;, the Firebird external database file.
 &apos;&apos;&apos;                     The name of the file must be given in 
SF_FileSystem.FileNaming notation
 &apos;&apos;&apos;                     The file must exist
+&apos;&apos;&apos;             CalcFileName: only when EmbedddedDatabase = 
&quot;CALC&quot;, the name of the file containing the tables as Calc sheets
+&apos;&apos;&apos;                     The argument is obsolete as from SF 
25.8.
 &apos;&apos;&apos;     Returns:
-&apos;&apos;&apos;              A SFDocuments.SF_Document object or one of its 
subclasses
+&apos;&apos;&apos;              A SFDocuments.SF_Base object or Nothing
 &apos;&apos;&apos;     Exceptions
 &apos;&apos;&apos;             UNKNOWNFILEERROR                                
Calc datasource does not exist
 &apos;&apos;&apos;     Examples:
@@ -288,12 +293,13 @@ Public Function CreateBaseDocument(Optional ByVal 
FileName As Variant _
 Dim oCreate As Variant                         &apos;  Return value
 Dim oDBContext As Object                       &apos;  
com.sun.star.sdb.DatabaseContext
 Dim oDatabase As Object                                &apos;  
com.sun.star.comp.dba.ODatabaseSource
-Dim oComp As Object                                    &apos;  Loaded 
component com.sun.star.lang.XComponent
+Dim sTarget As String                          &apos;  sdbc abbreviation
 Dim sFileName As String                                &apos;  Alias of 
FileName
 Dim FSO As Object                                      &apos;  Alias for 
FileSystem service
 Const cstDocType = &quot;private:factory/s&quot;
 Const cstThisSub = &quot;UI.CreateBaseDocument&quot;
-Const cstSubArgs = &quot;FileName, 
[EmbeddedDatabase=&quot;&quot;HSQLDB&quot;&quot;|&quot;&quot;FIREBIRD&quot;&quot;|&quot;&quot;CALC&quot;&quot;],
 [RegistrationName=&quot;&quot;&quot;&quot;], [CalcFileName]&quot;
+Const cstSubArgs = &quot;FileName, 
[EmbeddedDatabase=&quot;&quot;HSQLDB&quot;&quot;|&quot;&quot;FIREBIRD&quot;&quot;|&quot;&quot;FIREBIRD_EXTERNAL&quot;&quot;|&quot;&quot;CALC&quot;&quot;],
 &quot; _
+                                       &amp; 
&quot;[RegistrationName=&quot;&quot;&quot;&quot;], [DataFileName]&quot;
 
        If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
        Set oCreate = Nothing
@@ -302,34 +308,43 @@ Const cstSubArgs = &quot;FileName, 
[EmbeddedDatabase=&quot;&quot;HSQLDB&quot;&qu
 Check:
        If IsMissing(EmbeddedDatabase) Or IsEmpty(EmbeddedDatabase) Then 
EmbeddedDatabase = &quot;HSQLDB&quot;
        If IsMissing(RegistrationName) Or IsEmpty(RegistrationName) Then 
RegistrationName = &quot;&quot;
+       If IsMissing(DataFileName) Or IsEmpty(DataFileName) Then DataFileName = 
&quot;&quot;
        If IsMissing(CalcFileName) Or IsEmpty(CalcFileName) Then CalcFileName = 
&quot;&quot;
        If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
                If Not SF_Utils._ValidateFile(FileName, &quot;FileName&quot;) 
Then GoTo Finally
-               If Not SF_Utils._Validate(EmbeddedDatabase, 
&quot;EmbeddedDatabase&quot;, V_STRING, Array(&quot;CALC&quot;, 
&quot;HSQLDB&quot;, &quot;FIREBIRD&quot;)) Then GoTo Finally
+               If Not SF_Utils._Validate(EmbeddedDatabase, 
&quot;EmbeddedDatabase&quot;, V_STRING, _
+                                                                       
Array(&quot;CALC&quot;, &quot;HSQLDB&quot;, &quot;FIREBIRD&quot;, 
&quot;FIREBIRD_EXTERNAL&quot;)) Then GoTo Finally
                If Not SF_Utils._Validate(RegistrationName, 
&quot;RegistrationName&quot;, V_STRING) Then GoTo Finally
-               If UCase(EmbeddedDatabase) = &quot;CALC&quot; Then
-                       If Not SF_Utils._ValidateFile(CalcFileName, 
&quot;CalcFileName&quot;) Then GoTo Finally
-                       If Not FSO.FileExists(CalcFileName) Then GoTo 
CatchNotExists
+               If InStr(UCase(EmbeddedDatabase), 
&quot;CALC,FIREBIRD_EXTERNAL&quot;) &gt; 0 Then
+                       If Len(CalcFileName) &gt; 0 And Len(DataFileName) = 0 
Then DataFileName = CalcFileName
+                       If Not SF_Utils._ValidateFile(DataFileName, 
&quot;DataFileName&quot;) Then GoTo Finally
+                       If Not FSO.FileExists(DataFileName) Then GoTo 
CatchNotExists
                End If
        End If
 
 Try:
+       sFileName = FSO._ConvertToUrl(FileName)
+
        Set oDBContext = SF_Utils._GetUNOService(&quot;DatabaseContext&quot;)
        With oDBContext
                Set oDatabase = .createInstance()
-               &apos;  Build the url link to the database
+
+               &apos;  Build the url links in the database descriptors
+               oDatabase.URL = sFileName
                Select Case UCase(EmbeddedDatabase)
                        Case &quot;HSQLDB&quot;, &quot;FIREBIRD&quot;
-                               oDatabase.URL = &quot;sdbc:embedded:&quot; 
&amp; LCase(EmbeddedDatabase)
-                       Case &quot;CALC&quot;
-                               oDatabase.URL = &quot;sdbc:calc:&quot; &amp; 
FSO._ConvertToUrl(CalcFileName)
+                               oDatabase.DatabaseDocument.DataSource.URL = 
&quot;sdbc:embedded:&quot; &amp; LCase(EmbeddedDatabase)
+                       Case &quot;CALC&quot;, &quot;FIREBIRD_EXTERNAL&quot;
+                               If UCase(EmbeddedDatabase) = &quot;CALC&quot; 
Then sTarget = &quot;calc&quot; Else sTarget = &quot;firebird&quot;
+                               oDatabase.DatabaseDocument.DataSource.URL = 
&quot;sdbc:&quot; &amp; sTarget &amp; &quot;:&quot; &amp; 
FSO._ConvertToUrl(DataFileName)
                End Select
+
                &apos;  Create empty Base document
-               sFileName = FSO._ConvertToUrl(FileName)
                &apos;  An existing file is overwritten without warning
                If FSO.FileExists(FileName) Then FSO.DeleteFile(FileName)
                If FSO.FileExists(FileName &amp; &quot;.lck&quot;) Then 
FSO.DeleteFile(FileName &amp; &quot;.lck&quot;)
                oDatabase.DatabaseDocument.storeAsURL(sFileName, 
Array(SF_Utils._MakePropertyValue(&quot;Overwrite&quot;, True)))
+
                &apos;  Register database if requested
                If Len(RegistrationName) &gt; 0 Then
                        If .hasRegisteredDatabase(RegistrationName) Then
@@ -349,7 +364,7 @@ Finally:
 Catch:
        GoTo Finally
 CatchNotExists:
-       SF_Exception.RaiseFatal(UNKNOWNFILEERROR, &quot;CalcFileName&quot;, 
CalcFileName)
+       SF_Exception.RaiseFatal(UNKNOWNFILEERROR, &quot;DataFileName&quot;, 
DataFileName)
        GoTo Finally
 End Function    &apos;   ScriptForge.SF_UI.CreateBaseDocument
 
diff --git a/wizards/source/scriptforge/python/scriptforge.py 
b/wizards/source/scriptforge/python/scriptforge.py
index 0f4b2a8bf4c2..807d8462b5fb 100644
--- a/wizards/source/scriptforge/python/scriptforge.py
+++ b/wizards/source/scriptforge/python/scriptforge.py
@@ -1752,9 +1752,12 @@ class SFScriptForge:
         def Activate(self, windowname = ''):
             return self.ExecMethod(self.vbMethod, 'Activate', windowname)
 
-        def CreateBaseDocument(self, filename, embeddeddatabase = 'HSQLDB', 
registrationname = '', calcfilename = ''):
+        def CreateBaseDocument(self, filename, embeddeddatabase = 'HSQLDB', 
registrationname = '', datafilename = '',
+                               calcfilename = ''):
+            if len(calcfilename) > 0 and len(datafilename) == 0:
+                datafilename = calcfilename
             return self.ExecMethod(self.vbMethod, 'CreateBaseDocument', 
filename, embeddeddatabase, registrationname,
-                                   calcfilename)
+                                   datafilename)
 
         def CreateDocument(self, documenttype = '', templatefile = '', hidden 
= False):
             return self.ExecMethod(self.vbMethod, 'CreateDocument', 
documenttype, templatefile, hidden)
diff --git a/wizards/source/scriptforge/python/scriptforge.pyi 
b/wizards/source/scriptforge/python/scriptforge.pyi
index f37bd5ee343d..fc30510a0f51 100644
--- a/wizards/source/scriptforge/python/scriptforge.pyi
+++ b/wizards/source/scriptforge/python/scriptforge.pyi
@@ -2392,24 +2392,27 @@ class SFScriptForge:
 
         def CreateBaseDocument(self,
                                filename: str,
-                               embeddeddatabase: Literal['HSQLDB', 'FIREBIRD', 
'CALC'] = ...,
+                               embeddeddatabase: Literal['HSQLDB', 'FIREBIRD', 
'FIREBIRD_EXTERNAL', 'CALC'] = ...,
                                registrationname: str = ...,
-                               calcfilename: str = ...,
+                               datafilename: str = ...,
                                ) -> BASE:
             """
-                Create a new LibreOffice Base document embedding an empty 
database of the given type.
+                Create a new LibreOffice Base document embedding an empty 
database of the given type
+                or finding its datasource in an external database file (Calc 
or Firebird).
                     Args
                         ``filename``: identifies the file to create. It must 
follow the ``FileSystem.FileNaming``
                         notation. If the file already exists, it is 
overwritten without warning.
 
-                        ``embeddeddatabase``: either ``HSQLDB`` or 
``FIREBIRD`` or ``CALC``. Defaults to ``HSQLDB``.
+                        ``embeddeddatabase``: either ``HSQLDB``, ``FIREBIRD``, 
``FIREBIRD_EXTERNAL`` or ``CALC``.
+                        Defaults to ``HSQLDB``.
 
                         ``registrationname``: the name used to store the new 
database in the databases register.
                         If "" (default), no registration takes place. If the 
name already exists it is overwritten
                         without warning.
 
-                        ``calcfilename``: only when ``embeddeddatabase`` = 
``CALC``, the name of the file containing
-                        the tables as Calc sheets. The name of the file must 
be given in ``FileSystem.FileNaming``
+                        ``datafilename``: when ``embeddeddatabase`` = 
``CALC``, the name of the file containing
+                        the tables as Calc sheets. When ``embeddeddatabase`` = 
``FIREBIRD_EXTERNAL``, the name of the
+                        Firebird external database file. The name of the file 
must be given in ``FileSystem.FileNaming``
                         notation. The file must exist.
                     Returns
                         A ``Base`` service instance.
diff --git a/wizards/source/scriptforge/script.xlb 
b/wizards/source/scriptforge/script.xlb
index 54e48f703054..3318b6c54a1c 100644
--- a/wizards/source/scriptforge/script.xlb
+++ b/wizards/source/scriptforge/script.xlb
@@ -1,23 +1,23 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE library:library PUBLIC "-//OpenOffice.org//DTD OfficeDocument 
1.0//EN" "library.dtd">
 <library:library xmlns:library="http://openoffice.org/2000/library"; 
library:name="ScriptForge" library:readonly="false" 
library:passwordprotected="false">
- <library:element library:name="SF_TextStream"/>
- <library:element library:name="SF_Array"/>
- <library:element library:name="SF_Region"/>
- <library:element library:name="SF_L10N"/>
- <library:element library:name="SF_PythonHelper"/>
- <library:element library:name="SF_Platform"/>
  <library:element library:name="SF_Utils"/>
- <library:element library:name="SF_Root"/>
- <library:element library:name="__License"/>
- <library:element library:name="SF_Timer"/>
- <library:element library:name="SF_FileSystem"/>
- <library:element library:name="SF_Session"/>
+ <library:element library:name="SF_Platform"/>
+ <library:element library:name="SF_PythonHelper"/>
+ <library:element library:name="SF_L10N"/>
+ <library:element library:name="SF_Region"/>
+ <library:element library:name="SF_Array"/>
  <library:element library:name="SF_UI"/>
  <library:element library:name="SF_Services"/>
- <library:element library:name="SF_Dictionary"/>
+ <library:element library:name="SF_Session"/>
  <library:element library:name="SF_Exception"/>
- <library:element library:name="_CodingConventions"/>
- <library:element library:name="_ModuleModel"/>
+ <library:element library:name="SF_Dictionary"/>
+ <library:element library:name="SF_Timer"/>
+ <library:element library:name="SF_FileSystem"/>
+ <library:element library:name="SF_TextStream"/>
+ <library:element library:name="SF_Root"/>
+ <library:element library:name="__License"/>
  <library:element library:name="SF_String"/>
+ <library:element library:name="_ModuleModel"/>
+ <library:element library:name="_CodingConventions"/>
 </library:library>
\ No newline at end of file

Reply via email to