We are getting the SQLite exception of "No such Table found". This issue is only reported on the device with brand ZTE(Z982 & N95630). On all other device the DB is working fine so not able to reproduce. Is ther issue with the Database path?
Below is the SQLite Helper class that we are using
public ExternalDbOpenHelper( Context context, String databaseName ) {
super( context, databaseName, null, DB_VERSION );
this.context = context;
String packageName = context.getPackageName();
DB_PATH = String.format( "//data//data//%s//databases//", packageName );
DB_NAME = databaseName;
openDataBase();
}
Method to create Database
public void createDataBase() {
boolean dbExist = checkDataBase();
if ( dbExist ) {
Log.i( this.getClass().toString(), "Database already exists" );
try {
this.getWritableDatabase();
}
catch ( SQLiteReadOnlyDatabaseException sqr ) {
this.getWritableDatabase();
sqr.printStackTrace();
}
}
else if ( !dbExist ) {
try {
this.getWritableDatabase();
}
catch ( SQLiteReadOnlyDatabaseException sqr ) {
this.getWritableDatabase();
sqr.printStackTrace();
}
try {
copyDataBase();
}
catch ( IOException e ) {
e.printStackTrace();
Log.e( this.getClass().toString(), "Copying error" );
}
}
}
Datbase exists or not
private boolean checkDataBase() {
SQLiteDatabase checkDb = null;
try {
String path = DB_PATH + DB_NAME;
File file = new File( path );
if ( file.exists() && !file.isDirectory() ) {
checkDb = SQLiteDatabase.openDatabase( path, null, SQLiteDatabase.OPEN_READWRITE );
}
}
catch ( SQLException e ) {
e.printStackTrace();
Log.e( this.getClass().toString(), "Error while checking db" );
}
if ( checkDb != null ) {
checkDb.close();
}
return checkDb != null;
}
public SQLiteDatabase openDataBase() throws SQLException {
String path = DB_PATH + DB_NAME;
if ( database == null ) {
createDataBase();
database = SQLiteDatabase.openDatabase( path, null, SQLiteDatabase.OPEN_READWRITE );
try {
database.setVersion(DB_VERSION);
}catch (SQLiteDiskIOException dio){
dio.printStackTrace();
database.setVersion(DB_VERSION);
}
}
return database;
}
public void onCreate( SQLiteDatabase db ) {
Log.e( "Node ", "onCreate Database Deleting and Copying latest DB" );
}
DB helper methods
public void onUpgrade( SQLiteDatabase db, int oldVersion, int newVersion ) {
Log.e( "Node ", "onUpgrade Database Deleting and Copying latest DB" );
if ( oldVersion < newVersion ) {
Log.v( "Test", "Within onUpgrade. Old is: " + oldVersion + " New is: " + newVersion );
//getFavorites( db) ;
context.deleteDatabase( DB_NAME );
try {
copyDataBase();
//setFavorites( db );
}
catch ( IOException e ) {
e.printStackTrace();
}
// new BackupDBAsync(context).execute();
}
}
This how we get the SQLiteHelper's instance
dbOpenHelper = new ExternalDbOpenHelper( getActivity(), AppConstants.DB_NAME );
database = dbOpenHelper.openDataBase();