vnshetty
vnshetty

Reputation: 20132

External SQLite File content accessing error

I've the following code, it gives a run time error as below. Why?

try{
String myPath = DB_PATH + DB_NAME;  
mDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);
}catch(SQLiteException e){} 

Runtime Error:

:sqlite returned: error code = 1, msg = no such table: android_metadata  
 :SELECT locale FROM android_metadata failed  
 :Failed to setLocale() when constructing, closing the database  
 :android.database.sqlite.SQLiteException: no such table: android_metadata

Upvotes: 6

Views: 6167

Answers (3)

Daniel  Magnusson
Daniel Magnusson

Reputation: 9674

When open read only db and its not already created, use NO_LOCALIZED_COLLATORS.

try{
    String myPath = DB_PATH + DB_NAME;  
    mDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY+ SQLiteDatabase.NO_LOCALIZED_COLLATORS);
}catch(SQLiteException e){} 

android_metadata table will be created if you open the database with write permissions.

Upvotes: 8

mr.doooger
mr.doooger

Reputation: 57

call openDatabase() with SQLiteDatabase.NO_LOCALIZED_COLLATORS flag,this is what i did when i met the problem last time...

Upvotes: 5

SteD
SteD

Reputation: 14027

Make sure the table name android_metadata is there, with a column name locale, you could insert en_US as value for locale.

Or rather execute this sql statement:

CREATE TABLE "android_metadata" ("locale" TEXT DEFAULT 'en_US');

Edit: If you call openDatabase() with SQLiteDatabase.NO_LOCALIZED_COLLATORS flag, you would not need to have this table, else you will need to have this table around.

See setLocale().

Upvotes: 24

Related Questions