Android Question Firebase Storage: upload file.db

WebQuest

Active Member
Licensed User
Hi Community I'm testing the features of FireBaseStorage, and I wanted to understand if it is possible to load file.db to be recovered later. The problem is that once the .db is populated, the UploadFile instruction saves an empty file.db in the storage by transcribing the data.

B4X:
If  File.Exists(File.DirInternal,"DB.db")= False Then
        File.Copy(File.DirAssets,"DB.db",File.DirInternal,"DB.db")
End If
 
My = File.DirInternal
 
s.Initialize(My,"DB.db",True)

B4X:
dim Variable as string ="Hello World"

s.ExecNonQuery("INSERT INTO Table1 (Culomn1)VALUES('"& Variable &"')")


I am trying to make a copy of the populated .db, but apparently there is something wrong with this instruction because the .db in the storage is empty.

B4X:
Starter.storage.UploadFile(File.DirInternal,"DB.db",$"/public/DB.db"$)

I left out the authentication part.

All this can be done with a .txt file passing the parameters of the .db, I wanted to know if a direct copy can be made without having to go through all the parameters.

Thanks in advance for availability
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
s.ExecNonQuery("INSERT INTO Table1 (Culomn1)VALUES('"& Variable &"')")
This code is not good. You should use parameterized commands.

If the database journal mode is set to WAL and it is the default mode in newer versions of Android then the database will be made of up to three files. You can either upload all three files (if they exist) or change the journal mode.
 
Upvote 0

WebQuest

Active Member
Licensed User
Thanks I modified this way and I can pass the parameters and load the file db into the storage.

B4X:
S.ExecNonQuery2("INSERT INTO Table1 (Parm1,Param2,Param3) VALUES(?,?,?)",Array As Object(Var1,Var2,Var3))

Now, however, this is the inverse problem, when I download the file.db from the storage the file.db is 0kb tables and columns are present but the inserted data are missing. Probably I have to use the DownloadStream method?

B4X:
Sub btnDownloadPublic_Click
 
Starter.storage.DownloadFile("/public/", File.DirDefaultExternal, "DB.db")
 
End Sub
 
Upvote 0

WebQuest

Active Member
Licensed User
I tried to change the journal like this
B4X:
Dim MyJournal As String

c = s.ExecQuery ("PRAGMA journal_mode = MEMORY")

MyJournal = s.ExecQuerySingleResult ("PRAGMA Journal_mode")

Log ("Myjournal:" & MyJournal)

But the register always returns me WAL. So I tried to change it from the setting (Journal Mode) in SQLiteBrowser, but from the documentation it turns out that only the creation of a new file.db can be set in Journal mode. If I try to modify it from an existing file.db, the changes are not saved. I will try to recreate the db file with the same parameters and set the journal mode to "off" even if it is not recommended.
 
Upvote 0

WebQuest

Active Member
Licensed User
Hi Erel I tested with a file.txt the upload works with both .db and .txt, the problem is the download even if I create a.txt file with data written inside the file is loaded into the storage correctly but if I want to download it I only receive an image of the file name of 0 kb with no internal data, at this point the problem does not only concern the .db. I set the rules with free write and read access but nothing keeps getting an empty file.

B4X:
Sub DownloadFileStorage
   
Starter.storage.DownloadFile("/public/", File.DirInternal, NameFile)

End Sub

The downloaded file does not contain data that happens?

B4X:
Dim Newrow As String
    If  File.Exists(File.DirInternal,"NewRow.txt") Then
             Newrow = File.ReadString(File.DirInternal,"NewRow.txt")
    Log(Newrow)
    End If

I'm getting this error for download ((IOException) java.io.IOException: Could not open resulting stream.) I've checked the rules I've set them to read and write without authentication but it doesn't work
 
Last edited:
Upvote 0
Top