[Solved] How to adjust connection string to changed location

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
gkick
Posts: 324
Joined: Wed Aug 07, 2019 5:24 pm
Location: Chile

[Solved] How to adjust connection string to changed location

Post by gkick »

Hi,

I am using NSIS to install front/HSQL backend dbs.
The connection string of the original db is
jdbc:hsqldb:file:///C:\LDS\icms\database/icms;default_schema=true;shutdown=true;hsqldb.default_table_

The code setup of the split wizard normally adjust the path if the db is moved (Code as below)

Code: Select all

'setup Class Path
  ClassPath:
	sClassPath = sPath & "driver/hsqldb.jar"
	If Not FileExists(sClassPath) Then 
		sLine1 = "Please add a copy of the HSQLDB engine (hsqldb.jar) to the current folder :  "
		sLine2 = "NOTE:  This is necessary for proper wizard function, but additional benefits include : " 
		sLine3 = "* enhanced portability of the database-folder"
		sLine4 = "* ensures database compatibility across computers and *Office installations"
		sLine5 = "* guards against inadvertent upgrade of your database since the results are uncertain and irreversible"
		sLine6 = "* hsqldb 2.x provides a built-in database management GUI accessible by clicking hsqldb.jar."
		iButton = MsgBox (chr(13) & sLine1 & chr(13) & chr(13) & sPath & chr(13) & chr(13) & sLine2 & _
		chr(13) & sLine3 & chr(13) & sLine4 & chr(13) & sLine5 & chr(13) & sLine6, 18, "hsqldb.jar not found")
		If iButton = 3 Then Exit Sub 'ThisDatabaseDocument.close(True)
		If iButton = 4 Then Goto ClassPath
	End If
	sClassPath = ConvertToURL(sClassPath)
	ThisDatabaseDocument.DataSource.Settings.JavaDriverClassPath = sClassPath 

  'get the HSQL database name from the current folder
	NextFile = Dir(sPath & "database/", 0)
	While NextFile <> ""
		If (Right(NextFile, 7) = ".script") Then dbName = (Left(NextFile, Len(NextFile)-7))
		NextFile = Dir
	Wend
	If dbName = Empty Then 
		sLine1 = "Optionally provide a name for your back-end data files. "
		sLine2 = "NOTE: The particular name is not important. The default below will suffice. "
		dbName = InputBox(sLine1 & chr(13) & chr(13) & sLine2, "Create a new database    *   JDBC  |  HSQL database engine  |  non-embedded data files   *", "mydb")
		If dbName = "" Then dbName = "mydb"
	End If
    
  'check for existing database
	sLine1 = "A new database will be created in the current folder:  "
	sLine2 = "NOTE: This folder with its ""database"" and ""driver"" subfolders constitutes your ""database folder."" "
	sLine3 = "A dedicated 'database folder' is fully portable, and as such it may be renamed or moved as desired."
	sLine4 = "NOTE: This Base front-end file (" & sName & ") must remain in this portable folder.  "
	sLine5 = "You may rename this file as desired, but do maintain the .odb extension if visible. Create a desktop shortcut to this file as desired."
	sLine6 = "NOTE: The back-end HSQL data files will be named: " & dbName & ".*  "
	sLine7 = "These files will reside in the ""database"" subfolder."
	If Not FileExists(sPath & "database/" & dbName & ".script") Then MsgBox sLine1 & chr(13)_
		& sPath & chr(13) & chr(13) & sLine2 & sLine3 _
		& chr(13) & chr(13) & sLine4 & sLine5 _
		& chr(13) & chr(13) & sLine6 & sLine7 _
		, 64, "Please Read"
     
  'setup Data Source URL
	sURL_prefix = "jdbc:hsqldb:"
	sURL_args = ";default_schema=true;shutdown=true;hsqldb.default_table_type=cached;get_column_name=false"
	sURL = sURL_prefix & "file:///" & sPath & "database/" & dbName & sURL_args
	ThisDatabaseDocument.DataSource.URL = sURL
	ThisDatabaseDocument.DataSource.Settings.JavaDriverClass = "org.hsqldb.jdbcDriver"
	ThisDatabaseDocument.DataSource.User = "SA"	
	
The installer copies all files and dirs to C:\LDS\sICMS ...however the clone does not adjust the path of the connection string and reverts back even when changed manually due to the code above.

How can I modify the setup code or change the connection string of the clone at runtime to use the correct backend as the original is still used for dvlp and bug fixes

Thank you
Last edited by gkick on Sun Sep 05, 2021 4:18 am, edited 1 time in total.
Libre Office 6.4.6 on Windows 10 HSQL 2.51 backend
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: How to adjust connection string to changed location

Post by Villeroy »

Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
gkick
Posts: 324
Joined: Wed Aug 07, 2019 5:24 pm
Location: Chile

Re: How to adjust connection string to changed location

Post by gkick »

@Villeroy
Thanks for that
Libre Office 6.4.6 on Windows 10 HSQL 2.51 backend
Post Reply