Android Question SQLite viewer

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Just started with B4A and installed on Windows 7 Pro. I downloaded the SQLite viewer demo project and it compiled fine and runs (via the bridge app) on a Samsung S9. All good sofar. I copied a SQLite database from the PC to the SD card. File extension is .db3. When I try to load the file I get: Error loading database.
I runs fine on the PC in my own custom Excel SQLite add-in. There is no encryption.
Any idea what the problem could be? On the PC I run latest 3.22.0. Do I need to install SQLite on the phone?
Thanks for any advice.

RBS
 

Star-Dust

Expert
Licensed User
Longtime User
Yes
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
I made some further investigations with my Samsung Tab S2 with an external SD card and Android 7.0.

I added a subfolder on the SD card and a database in it.
Running the program I get the same error!
It is a permission limit in Android.

Then I checked for the GetSafeDirDefaultExternal:
Private rp As RuntimePermissions
SafeDir = rp.GetSafeDirDefaultExternal("SQLite")
Added the database file.
With the FileDialog I see the database file, I select it.
SQL.Initialize(Dir, FileName, False) doesn't throw an error, before the error was thrown here, nor does DBUtils.ExecuteListView.
But it seems that the database is considered as empty, no table.
I tested with
Private curs As Cursor
curs = SQL.ExecQuery("SELECT * FROM persons")

The Cursor is empty.

Then, to check write permissions, I saved a simple text file in the same folder and read it back. This works!

So, to me it seems that there is a problem reading databases from an externa SD card.
I'm afraid that Erel needs to look at this.

Attached, my test project. The "persons.db" database, I used, is included in the zip file.
 

Attachments

  • SQLiteViewerSDCard.zip
    15.9 KB · Views: 198
Upvote 0

Mahares

Expert
Licensed User
Longtime User
So, to me it seems that there is a problem reading databases from an externa SD card.
I'm afraid that Erel needs to look at this.
I slightly changed your code on your above project to this and was able to read the database on the SD removable external folder(tested on OS 7.1.1 device):
B4X:
Private rp As RuntimePermissions
'    SafeDir = rp.GetSafeDirDefaultExternal("SQLite")    'klaus
    SafeDir = rp.GetAllSafeDirsExternal("SQLite")(1)    'mahares
    File.Copy(File.DirAssets,"persons.db",SafeDir,"persons.db")      'mahares
    LoadDatabase(SafeDir, "persons.db")
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Especially (1) after rp.GetAllSafeDirsExternal("SQLite")
I ran this code first to determine which is my removable SD card and if there is an SD card:
B4X:
For Each s As String In rp.GetAllSafeDirsExternal("")  'returns a string array
        Log(s)
Next
 
Upvote 0
Top