Unknown error (code 14): Failed to open the database

I have a working application that uses a database and SQLiteAssetHelper . The database file (sql.sqlite) is encrypted (sql.sqlite.zip) and placed in the assets / databases folder.

The program works fine. And when you start to the second / third / fourth ... time it starts quickly. But if I make a “forced stop” followed by “clear data”, then run it again, and then when I run it (view logs), I see the error “unknown error (code 14): could not open the database "... but then I wait a few seconds and it all loads and works great.

The log is as follows:

W/SQLiteAssetHelper(18393): could not open database SQL.sqlite - unknown error (code 14): Could not open database W/SQLiteAssetHelper(18393): copying database from assets... W/SQLiteAssetHelper(18393): extracting file: 'sql.sqlite'... W/SQLiteAssetHelper(18393): database copy complete I/SQLiteAssetHelper(18393): successfully opened database SQL.sqlite 

So it looks like he was somehow trying to find the database, failed, crashed, and then fixed it himself. So my question is: how could I avoid a clumsy start and a few seconds of delay?

EDIT: My first database link in my code ...

 public class Globals extends Application { Custom_SQLiteAssetHelper db; public void onCreate() { super.onCreate(); db = new Custom_SQLiteAssetHelper(this); cursor = db.get_first_species_common_name(); 

and i have ...

 public class Custom_SQLiteAssetHelper extends SQLiteAssetHelper { public Custom_SQLiteAssetHelper(Context context) { super(context, "SQL.sqlite", null, 1); } public Cursor get_first_species_common_name() { SQLiteDatabase db = getReadableDatabase(); SQLiteQueryBuilder querything = new SQLiteQueryBuilder(); // etc... 
+8
android sqlite
source share
3 answers

Try to change

 super(context, "SQL.sqlite", null, 1); 

from

  super(context, "SQL", null, 1); 
0
source share

YEEEESSS! I finally found the answer. you must use a newer version of SQLiteAssetHelper

0
source share
 public Custom_SQLiteAssetHelper(Context context) { super(context, "SQL.sqlite", null, 1); } 

Change to

 public Custom_SQLiteAssetHelper(Context context) { super(context, "SQL.sqlite", null, 1); close(); } 

@ haike00 it uses SQLiteAssetHelper, which is a library, it supports copying a pre-populated sqlite database to internal / external storage the first time the application is launched. When using this library you have to pin your sqlite file, no other parameters.

-one
source share

All Articles