0

I have android application . its working most of the devices , but it didn't work in the Samsung y duos only.

my application database contain 6 tables, 2 tables data is encrypted. Without this encryption , it was working fine, after put encrypted data only i am getting this issue.

Its error is :

    01-20 07:03:27.791: I/SqliteDatabaseCpp(13747): sqlite returned: error code = 11, msg = database corruption at line 48188 of [ed759d5a9e], db=/data/data/com_group_mylibs/databases/mylibs_db
01-20 07:03:27.791: I/SqliteDatabaseCpp(13747): sqlite returned: error code = 11, msg = database disk image is malformed, db=/data/data/com_group_mylibs/databases/mylibs_db
01-20 07:03:27.791: I/SqliteDatabaseCpp(13747): sqlite returned: error code = 11, msg = database corruption at line 48188 of [ed759d5a9e], db=/data/data/com_group_mylibs/databases/mylibs_db
01-20 07:03:27.791: I/SqliteDatabaseCpp(13747): sqlite returned: error code = 11, msg = database disk image is malformed, db=/data/data/com_group_mylibs/databases/mylibs_db
01-20 07:03:27.791: E/SqliteDatabaseCpp(13747): sqlite3_exec - Failed to set synchronous mode = 1(Normal) 
01-20 07:03:27.791: I/SqliteDatabaseCpp(13747): sqlite returned: error code = 11, msg = database corruption at line 48188 of [ed759d5a9e], db=/data/data/com_group_mylibs/databases/mylibs_db
01-20 07:03:27.791: I/SqliteDatabaseCpp(13747): sqlite returned: error code = 11, msg = database disk image is malformed, db=/data/data/com_group_mylibs/databases/mylibs_db
01-20 07:03:27.791: E/SqliteDatabaseCpp(13747): CREATE TABLE android_metadata failed
01-20 07:03:27.791: E/DefaultDatabaseErrorHandler(13747): Corruption reported by sqlite on database: /data/data/com.group.mylibs/databases/mylibs.db
01-20 07:03:27.801: E/DefaultDatabaseErrorHandler(13747): deleting the database file: /data/data/com.group.mylibs/databases/mylibs.db
01-20 07:03:28.001: I/SqliteDatabaseCpp(13747): sqlite returned: error code = 1, msg = no such table: hint, db=/data/data/com_group.mylibs/databases/mylibs_db
01-20 07:03:28.001: W/dalvikvm(13747): threadid=1: thread exiting with uncaught exception (group=0x40c31a68)
01-20 07:03:28.011: E/AndroidRuntime(13747): FATAL EXCEPTION: main
01-20 07:03:28.011: E/AndroidRuntime(13747): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.group.mylibs/com.group.mylibs.LibraryActivity}: android.database.sqlite.SQLiteException: no such table: hint: , while compiling: SELECT id, wordTypeId, hintText FROM hint WHERE wordTypeId= 0

This is my code :

public class MyLibsDatabaseHelper extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "mylibs.db";
private static final int DATABASE_VERSION = 5;
private static String DB_PATH = "/data/data/com.group.mylibs/databases/";
private static String DB_NAME = "mylibs.db";
private final Context myContext;
private SQLiteDatabase mylibsDataBase;

public SQLiteDatabase getMylibsDataBase() {
    return mylibsDataBase;
}

public void setMylibsDataBase(SQLiteDatabase mylibsDataBase) {
    this.mylibsDataBase = mylibsDataBase;
}



public MyLibsDatabaseHelper(Context context) {
    super(context, DATABASE_NAME, null, DATABASE_VERSION);
    myContext = context;
    DB_PATH = "/data/data/" + context.getPackageName() + "/databases/";
    try {
        createDataBase();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

@Override
public void onCreate(SQLiteDatabase database) {
}



@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}

public void createDataBase() throws IOException {

    boolean dbExist = checkDataBase();
    if (dbExist) {
    } else {
        this.getReadableDatabase();
        try {
            copyDataBase();
        } catch (IOException e) {

            throw new Error("Error copying database");
        }
    }
}

/**
 * Check if the database already exist to avoid re-copying the file each
 * time open the application.
 * 
 * @return true if it exists, false if it doesn't
 */
private boolean checkDataBase() {

    SQLiteDatabase checkDB = null;
    try
    {
    File dbFile = new File(DB_PATH + DB_NAME); 
    return dbFile.exists();
} catch (Exception ex) {
    Log.e("Error checkDataBase", ex.toString());
    return false;
}
}

private void copyDataBase() throws IOException {
    try {
        InputStream myInput = myContext.getAssets().open(DB_NAME);
        String outFileName = DB_PATH + DB_NAME;
        OutputStream myOutput = new FileOutputStream(outFileName);

        byte[] buffer = new byte[1024];
        int length;
        while ((length = myInput.read(buffer)) > 0) {
            myOutput.write(buffer, 0, length);
        }
        myOutput.flush();
        myOutput.close();
        myInput.close();
    } catch (Exception ex) {
        Log.e("Error copyDataBase", ex.toString());
    }
}

public void openDataBase() throws SQLException {
    // Open the database
    String myPath = DB_PATH + DB_NAME;

    this.mylibsDataBase = SQLiteDatabase.openDatabase(myPath, null,
            SQLiteDatabase.OPEN_READWRITE);
}

This application is working fine with most of the emulator & device , problem only in Samsung y duos .

I checked sqlite version 3.7 & i created database version is 3.6.18.

please tell me what is an issue.

Thanks in advance.

Piraba
  • 6,974
  • 17
  • 85
  • 135

1 Answers1

0

Looking into the Android Source code it seems that class DefaultDatabaseErrorHandler.java indicates that your database is corrupted. Looking into DefaultDatabaseErrorHandler.java and your logs suggests that onCorruption() of DefaultDatabaseErrorHandler.java class is being called and that method further deletes your database. So, the 2 tables that you have added for encryption may be causing the problem. I suggest you to please check those 2 table if they are creating any corruption to your whole database.

Lalit Poptani
  • 67,150
  • 23
  • 161
  • 242