Autore Topic: Packaged SQLite database becomes read only on installation  (Letto 343 volte)

ujlain

  • Visitatore
Q1: I packaged an application that uses a file-based Sqlite database (both read/write). However on installation of package, the database by virtue of Linux ownership/folder permissions, becomes read only. Any hints on how this could be avoided and the packaged Sqlite DB could be accessed in both read/write upon install ?

Q2: Has anyone used the connection created in the GAMBAS IDE ?
 - I am keen to understand how does this connection get used in GAMBAS code ?
 - Sqlite DB has to be specifically marked as additional file to be loaded into package (and the path where it shall reside on install). Does connection created in IDE give any additional benefit with regards to package creation ?
« Ultima modifica: 11 Luglio 2018, 08:01:53 da ujlain »

Offline Gianluigi

  • Moderatore globale
  • Senatore Gambero
  • *****
  • Post: 4.244
  • Tonno verde
    • Mostra profilo
Re:Packaged SQLite database becomes read only on installation
« Risposta #1 il: 11 Luglio 2018, 10:33:03 »
Q1: I packaged an application that uses a file-based Sqlite database (both read/write). However on installation of package, the database by virtue of Linux ownership/folder permissions, becomes read only. Any hints on how this could be avoided and the packaged Sqlite DB could be accessed in both read/write upon install ?
If possible, the best thing to do the first time you open the program is to create the database from scratch.
Otherwise, when the database is opened for the first time, it must be copied to the user's folder (usually hidden) eg. User.Home &/ ".FolderName".
In packaging, all the files inserted in Data become read-only files.
Citazione
Q2: Has anyone used the connection created in the GAMBAS IDE ?
 - I am keen to understand how does this connection get used in GAMBAS code ?
 - Sqlite DB has to be specifically marked as additional file to be loaded into package (and the path where it shall reside on install). Does connection created in IDE give any additional benefit with regards to package creation ?
Sorry, I've never used it, you'd better ask yourself on the mailing list

 :ciao: :ciao:
nuoto in attesa del bacio di una principessa che mi trasformi in un gambero azzurro

ujlain

  • Visitatore
Re:Packaged SQLite database becomes read only on installation
« Risposta #2 il: 11 Luglio 2018, 15:12:37 »
Q1 Resolved. Thanks very much Gianluigi. The suggestion to copy from install path to home directory worked (Note : not move .. move needs SUDO)
   
   
Codice: [Seleziona]
  Dim InstPath As String = "/opt/.stnDB"     ' This is where package gets installed
    Dim ExecPath As String = User.Home &/ ".stnDB"    ' This is where installed package will be moved on 1st run
   
    If Exist(ExecPath) Then
        Initialize_application   ' All fine , run the code
    Else If Exist(InstPath)
        Shell Subst("cp &1 &2 ", InstPath, ExecPath) Wait     ' 1st time run , move DB to User.home
        Initialize_application
    Else
        ' Trouble my DB not found where it ought to be !
        Message.Title = "Fatal Error"
        Message.Error("Database file not found, Exit.")
        Quit
    End If
« Ultima modifica: 12 Luglio 2018, 19:26:16 da Gianluigi »

Offline Gianluigi

  • Moderatore globale
  • Senatore Gambero
  • *****
  • Post: 4.244
  • Tonno verde
    • Mostra profilo
Re:Packaged SQLite database becomes read only on installation
« Risposta #3 il: 12 Luglio 2018, 19:21:14 »
Hi Ujlain,
I apologise for the delay in the reply.
Generally in a Gambas application we have an MMain.module and an FMain.class etc.
The application starts from MMain, sub main creates the conditions and opens the FMain.
FMain is normally set as Application.MainWindow = Me so that when you close FMain you close the entire application.
You could use Mkdir to create the directories e.g.:
Codice: [Seleziona]
  Private $sPath As String = User.Home &/ "." & Application.Name
  If Not Exist($sPath) Then
    Mkdir $sPath
    Mkdir $sPath &/ "database"
  Endif

And use Copy to copy the database from the Data folder to $sPath e.g.:
Codice: [Seleziona]
  Copy "./MyDat.sqlite3" To $sPath &/ "database/MyDat.sqlite3"

 :ciao: :ciao:
« Ultima modifica: 12 Luglio 2018, 19:22:57 da Gianluigi »
nuoto in attesa del bacio di una principessa che mi trasformi in un gambero azzurro