Error when copying to File.DirDefaultExternal

CidTek

Active Member
Licensed User
Longtime User
I get an error when installing a file to SD storage executing this line. It worked since day one and now it just pops the error in the screenshot.

File.Copy(File.DirAssets,"grt.db",File.DirDefaultExternal,"grt.db")
 

Attachments

  • Clipboard01.jpg
    Clipboard01.jpg
    18.4 KB · Views: 351

CidTek

Active Member
Licensed User
Longtime User
You will need to take a screenshot for now.

Perhaps this is the problem. I found this entry when I unchecked Filter.

Data exceeds UNCOMPRESS_DATA_MAX (7897088 vs 1048576)

Does the emulator has a size restriction per application because it is well below the 16 meg size of the emulator SD?
 
Upvote 0

CidTek

Active Member
Licensed User
Longtime User
OK, I restarted the emulator and wiped user data as an startup option.

Running the app I now get a new error "Disk I/O Error" on this line...

SQL1.Initialize(File.DirDefaultExternal, "grt.jet", False)

Note that I renamed my db file with a .jet extension to prevent compression as suggested above.
 

Attachments

  • Clipboard02.jpg
    Clipboard02.jpg
    12.4 KB · Views: 269
  • Clipboard01.jpg
    Clipboard01.jpg
    39.6 KB · Views: 259
Upvote 0

CidTek

Active Member
Licensed User
Longtime User
It might be an "emulator only" problem. It is worth checking it on a real device.

Problem solved.

This applies only to SQLite databases created before uploading to the phone. Not to databases created on the phone.

For some reason Android requires every database to have a table called android_metadata that includes at least one locale.

Using your own SQLite database in Android applications | ReignDesign Blog

However there is a better solution which Basic4Android doesn't support as far as I can see and that is to use the SQLiteDatabase.NO_LOCALIZED_COLLATORS flag when opening the database.
 
Upvote 0

nfordbscndrd

Well-Known Member
Licensed User
Longtime User
That fix was also mentioned at in another thread, but the error I was getting was that the only table in my database was "not found". Strange that it was giving you different errors. I guess that the moral is that everyone putting an existing database on a device needs to make sure they have done the fix first.
 
Upvote 0

CidTek

Active Member
Licensed User
Longtime User
That fix was also mentioned at in another thread, but the error I was getting was that the only table in my database was "not found". Strange that it was giving you different errors. I guess that the moral is that everyone putting an existing database on a device needs to make sure they have done the fix first.

I found that adding the android_metadata table is all I needed to do and didn't bother with the instructions to rename the primary key field in all the other tables.

However there are plenty of mentions out there that passing SQLiteDatabase.NO_LOCALIZED_COLLATORS flag when initializing the database eliminates that hassle. I just wish that B4A supported that.
 
Last edited:
Upvote 0

CidTek

Active Member
Licensed User
Longtime User
Thanks Erel, I'll give it a test.

I removed the android_metadata table and tested the app and it works just fine.

Thanks again Erel, I am developing this transit app in tandem with a friend who is doing the iPhone version and it makes using a common SQLite db so much easier.
 
Upvote 0

alfcen

Well-Known Member
Licensed User
Longtime User
I guess that the moral is that everyone putting an existing database on a device needs to make sure they have done the fix first.

I have a database created with the SQLite Database Browser (CSV import).
After deployment to the phone, I copied the database file back to the PC and found that a table called "android_metadata" containing a field "locale" = en_US has been created automatically.

Apparently, not all phones or Android versions perform that step automatically, so I believe the modified library is neutral, thus safer (no such locale field added after switching to the new library).
 
Upvote 0
Top