R Ruben García New Member Licensed User Longtime User Jun 3, 2014 #1 Hello, I have a problem in SQLite. First open database : If File.Exists(File.DirDefaultExternal , DBName) = False Then If FirstTime Then File.Copy(File.DirAssets, DBName, File.DirDefaultExternal, DBName) sql1.Initialize(File.DirDefaultExternal , DBName, True) End If Else If FirstTime Then sql1.Initialize(File.DirDefaultExternal , DBName, True) End If End If Then I update a table, close activity, open activity and changes are OK. But when I close application and open again I have lost the changes. ¿can anybody help me? Thank you
Hello, I have a problem in SQLite. First open database : If File.Exists(File.DirDefaultExternal , DBName) = False Then If FirstTime Then File.Copy(File.DirAssets, DBName, File.DirDefaultExternal, DBName) sql1.Initialize(File.DirDefaultExternal , DBName, True) End If Else If FirstTime Then sql1.Initialize(File.DirDefaultExternal , DBName, True) End If End If Then I update a table, close activity, open activity and changes are OK. But when I close application and open again I have lost the changes. ¿can anybody help me? Thank you
M Mahares Expert Licensed User Longtime User Jun 3, 2014 #2 You code should be like this: Code: Copy If FirstTime Then if File.Exists(File.DirDefaultExternal , DBName) = False Then File.Copy(File.DirAssets,DBName, File.DirDefaultExternal,DBName) end if sql1.Initialize(File.DirDefaultExternal ,DBName, True) end if Upvote 0
You code should be like this: Code: Copy If FirstTime Then if File.Exists(File.DirDefaultExternal , DBName) = False Then File.Copy(File.DirAssets,DBName, File.DirDefaultExternal,DBName) end if sql1.Initialize(File.DirDefaultExternal ,DBName, True) end if
eps Expert Licensed User Longtime User Jun 3, 2014 #3 Whilst the code Mahares has posted is a lot neater and easier to read it should produce the same result. Are you sure the DirDefaultExternal is a useable and maintainable filespace? What device have you got? I usually use DirInternal instead as it's a more useable filespace in most devices. ETA: I would also confirm, whilst you're in your App that the Update has worked. i.e. Open App Update / Add record Check record has been updated Close App Reopen and View. If you step through the processing in your App I'm sure the issue will become apparent. The Android App lifecycle can be a little misleading sometimes and it causes you to make assumptions about what code is being executed. Sometimes it can surprise you (I've been surprised more than once by B4A code!!) Last edited: Jun 3, 2014 Upvote 0
Whilst the code Mahares has posted is a lot neater and easier to read it should produce the same result. Are you sure the DirDefaultExternal is a useable and maintainable filespace? What device have you got? I usually use DirInternal instead as it's a more useable filespace in most devices. ETA: I would also confirm, whilst you're in your App that the Update has worked. i.e. Open App Update / Add record Check record has been updated Close App Reopen and View. If you step through the processing in your App I'm sure the issue will become apparent. The Android App lifecycle can be a little misleading sometimes and it causes you to make assumptions about what code is being executed. Sometimes it can surprise you (I've been surprised more than once by B4A code!!)
eps Expert Licensed User Longtime User Jun 3, 2014 #4 What Android Version are you testing with? Upvote 0
Erel B4X founder Staff member Licensed User Longtime User Jun 4, 2014 #5 Note that there is a method in DBUtils named CopyDBFromAssets. It is similar to the code posted by @Mahares however it also checks that the external storage is writable. If not it copies it to an internal folder (and returns the actual folder). Upvote 0
Note that there is a method in DBUtils named CopyDBFromAssets. It is similar to the code posted by @Mahares however it also checks that the external storage is writable. If not it copies it to an internal folder (and returns the actual folder).
R Ruben García New Member Licensed User Longtime User Jun 4, 2014 #6 Thanks for the replies. The problem persists. I step through the processing , and check record has been updated. The problem is when I close the application and reopen, the changes are lost, as if I had not recorded. The android version is 4.2.2. I have seen the sql file does not change the modification date. But there is another file in the same directory (bd.sqlite-journal) that changed the modification date. any idea to investigate? Upvote 0
Thanks for the replies. The problem persists. I step through the processing , and check record has been updated. The problem is when I close the application and reopen, the changes are lost, as if I had not recorded. The android version is 4.2.2. I have seen the sql file does not change the modification date. But there is another file in the same directory (bd.sqlite-journal) that changed the modification date. any idea to investigate?
klaus Expert Licensed User Longtime User Jun 4, 2014 #7 Are you sure you don't have File.Delete(File.DirDefaultExternal, DBName) somewhere before the code you posted ? Upvote 0
Are you sure you don't have File.Delete(File.DirDefaultExternal, DBName) somewhere before the code you posted ?
R Ruben García New Member Licensed User Longtime User Jun 4, 2014 #8 I'm sure Klaus. Also I check the program jump this conditional instruction. If File.Exists(TargetDir, FileName) = False Then File.Copy(File.DirAssets, FileName, TargetDir, FileName) End If Upvote 0
I'm sure Klaus. Also I check the program jump this conditional instruction. If File.Exists(TargetDir, FileName) = False Then File.Copy(File.DirAssets, FileName, TargetDir, FileName) End If
klaus Expert Licensed User Longtime User Jun 4, 2014 #9 Can you post your project as a zip file. Upvote 0
R Ruben García New Member Licensed User Longtime User Jun 5, 2014 #10 Resolved!!!! I began a SQL transaction that never completed. I have completed the transaction and works fine. Thank you all for your help. Upvote 0
Resolved!!!! I began a SQL transaction that never completed. I have completed the transaction and works fine. Thank you all for your help.