Search code examples
androidsqlbasic4android

Can an SQL file be imported into Basic4Android?


I am trying to directly import an SQL file from a SQLite database into Basic4Android. I exported a .sql file and then I loaded the SQL file into the Basic4Android assets in the IDE.

Then I put this in my Process_Globals

Dim access As SQL
access.Initialize(File.DirAssets,"example.sql",True)

However the application crashes immediately on load when I try to run this code.

There's two things that I think could be wrong:

  1. File.DirAssets is read-only and perhaps SQL can not be used from a read only directory. If that is the case then how else would I import an SQL file into the application.
  2. Possibly the databases are incompatible but I would think they should be compatible

Solution

  • You do not need to export anything. Just copy the SQLite file to your project.

    As you wrote it is not possible to open a database that is located in the assets folder. You should first copy it to a writable location. DBUtils can help you with this task.