Create a blank Firebird database by BASIC

I used codes Sub CreateBinaryDB shown in AndrewBase.odt of Andrewrey Pitonyak’s.
This code works so good. All blank HSQLDB database files were created rapidly.

REM  *****  BASIC  *****

Option Explicit
Option Compatible

Sub CreateANewBlankDatabaseOfHSQLDB
	Dim sPath 			As String : sPath = Environ("HOME") & "/" & "TestDatabaseFolder" & GetPathSeparator()
	Dim sDatabaseFile 	As String
	Dim i As Integer
	For i = 0 To 9
		sDatabaseFile = sPath & "TestHSQLDBDatabase" & i & ".odb"
		CreateBinaryDBHSQLDB(sDatabaseFile, 0)
	Next
End Sub

Sub CreateBinaryDBHSQLDB(Optional dbURL$ = "", Optional bVerbose = False)
  Dim oDBContext   'DatabaseContext service.
  Dim oDB          'Database data source.

  REM No URL Specified, get one.
  If dbURL = "" Then : dbURL = ChooseAFile(OOoBaseFilters(), False) : End If

  REM Still No URL Specified, exit.
  If dbURL = "" Then : Exit Sub : End If

  If FileExists(dbURL) Then
    If bVerbose Then : Print "The file already exists." : End If
  Else
    If bVerbose Then : Print "Creating " & dbURL : End If
    oDBContext = createUnoService( "com.sun.star.sdb.DatabaseContext" )
    oDB = oDBContext.createInstance()
    oDB.URL = "sdbc:embedded:hsqldb"
    oDB.DatabaseDocument.storeAsURL(dbURL, Array())
  End If
End Sub

'AndrewBase.odt
'Listing 2: Create an empty Base document.  
REM Use "Option Compatible", or you can not use a default argument.
Sub CreateBinaryDB(Optional dbURL$ = "", Optional bVerbose = False)
  Dim oDBContext   'DatabaseContext service.
  Dim oDB          'Database data source.

  REM No URL Specified, get one.
  If dbURL = "" Then dbURL = ChooseAFile(OOoBaseFilters(), False)

  REM Still No URL Specified, exit.
  If dbURL = "" Then Exit Sub

  If FileExists(dbURL) Then
    If bVerbose Then Print "The file already exists."
  Else
    If bVerbose Then Print "Creating " & dbURL
    oDBContext = createUnoService( "com.sun.star.sdb.DatabaseContext" )
    oDB = oDBContext.createInstance()
    oDB.URL = "sdbc:embedded:hsqldb"
    oDB.DatabaseDocument.storeAsURL(dbURL, Array())
  End If
End Sub

On the other hand, I have been with embedded Firebird for many years and my next project will be non-embedded Firebird.

Is it possible to create either embedded Firebird or non-embedded Firebird database files like this way ?
And can you please help add more codes for either embedded Firebird or non-embedded Firebird database file ?

LOCalcBASIC_CreateNewBlankDatabaseFileFromCalc_hsqldb.ods (13.4 KB)

Ubuntu 22.04 LTS + LibreOffice 7.3.3.2

You have only to change the URL here: "sdbc:embedded:firebird" for an embedded Firebird database.

For an external Firebird database you will need the database file. If file has been created it will work with "sdbc:firebird:file:///home/…/firebird.fdb" You could get such a blank file if you open an existing embedded Firebird database file and look in tmp-folder for “firebird.fdb”, which will be extracted form “firebird.fbk”.

1 Like