WebQuest Active Member Licensed User Longtime User Oct 3, 2019 #1 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. Code: 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) Code: 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. Code: 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
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. Code: 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) Code: 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. Code: 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 Oct 4, 2019 #2 Lowegaterecords said: s.ExecNonQuery("INSERT INTO Table1 (Culomn1)VALUES('"& Variable &"')") Click to expand... 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
Lowegaterecords said: s.ExecNonQuery("INSERT INTO Table1 (Culomn1)VALUES('"& Variable &"')") Click to expand... 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.
WebQuest Active Member Licensed User Longtime User Oct 4, 2019 #3 Thanks I modified this way and I can pass the parameters and load the file db into the storage. Code: 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? Code: Sub btnDownloadPublic_Click Starter.storage.DownloadFile("/public/", File.DirDefaultExternal, "DB.db") End Sub Upvote 0
Thanks I modified this way and I can pass the parameters and load the file db into the storage. Code: 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? Code: Sub btnDownloadPublic_Click Starter.storage.DownloadFile("/public/", File.DirDefaultExternal, "DB.db") End Sub
Erel B4X founder Staff member Licensed User Longtime User Oct 6, 2019 #4 Never use File.DirDefaultExternal. See the runtime permissions video tutorial. Have you changed the journal mode? Otherwise your database will not be made of a single file. Upvote 0
Never use File.DirDefaultExternal. See the runtime permissions video tutorial. Have you changed the journal mode? Otherwise your database will not be made of a single file.
WebQuest Active Member Licensed User Longtime User Oct 6, 2019 #5 I tried to change the journal like this Code: 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
I tried to change the journal like this Code: 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.
Erel B4X founder Staff member Licensed User Longtime User Oct 6, 2019 #6 Another option is to copy and restore the three files. You can use the Archiver library to zip them if you like. Upvote 0
Another option is to copy and restore the three files. You can use the Archiver library to zip them if you like.
WebQuest Active Member Licensed User Longtime User Oct 17, 2019 #7 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. Code: Sub DownloadFileStorage Starter.storage.DownloadFile("/public/", File.DirInternal, NameFile) End Sub The downloaded file does not contain data that happens? Code: Dim Newrow As String If File.Exists(File.DirInternal,"NewRow.txt") Then Newrow = File.ReadString(File.DirInternal,"NewRow.txt") Log(Newrow) End If Click to expand... 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: Oct 17, 2019 Upvote 0
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. Code: Sub DownloadFileStorage Starter.storage.DownloadFile("/public/", File.DirInternal, NameFile) End Sub The downloaded file does not contain data that happens? Code: Dim Newrow As String If File.Exists(File.DirInternal,"NewRow.txt") Then Newrow = File.ReadString(File.DirInternal,"NewRow.txt") Log(Newrow) End If Click to expand... 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
Erel B4X founder Staff member Licensed User Longtime User Oct 18, 2019 #8 You should post all the relevant code and the full error message from the logs. Upvote 0