0

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
jb11
  • 557
  • 5
  • 18

2 Answers2

3

I'm sure this is not possible.

Open the .sql file in any text editor and you'll see it's a list of SQL statements.

An SQLite database file is an entirely different format as you'll see if you open it in a text editor.

Martin Pearman
  • 592
  • 5
  • 5
  • Thanks. I've just had a closer look at the SQL file and it makes sense that you can't import the statements. There should be a method somehow though to export a file from SQLite that can be used in B4A. – jb11 Dec 09 '11 at 04:58
  • If you have phpMyAdmin installed then you can export a MySQL database to various formats - not just .sql format. CSV and XML are possible export formats - maybe they would be of use to you? – Martin Pearman Dec 10 '11 at 05:16
2

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.

Erel
  • 1,802
  • 2
  • 15
  • 58