1

app is crashing in very specific case

  • if i install the app while the device local is English than no crash happen and everything is working as it should be.

  • if i change the device local to Arabic after the app being installed on English version than no crash too.

  • if i uninstall the app than change the device to local Arabic than install the app for first time, than the app crash and the logcat doesnt show where or which line, and the app crash even if i dont call the local database in splashscreen.

Error log is :

android.database.sqlite.SQLiteException: no such column: ١٥٦٤٤١٠١٢٩٥٤٢ (code 1): , while compiling: DELETE FROM workspec WHERE state IN (2, 3, 5) AND (period_start_time + minimum_retention_duration) < ١٥٦٤٤١٠١٢٩٥٤٢ AND(SELECT COUNT(*)=0 FROM dependency WHERE     prerequisite_id=id AND     work_spec_id NOT IN         (SELECT id FROM workspec WHERE state IN (2, 3, 5)))
#################################################################
Error Code : 1 (SQLITE_ERROR)
Caused By : SQL(query) error or missing database.
    (no such column: ١٥٦٤٤١٠١٢٩٥٤٢ (code 1): , while compiling: DELETE FROM workspec WHERE state IN (2, 3, 5) AND (period_start_time + minimum_retention_duration) < ١٥٦٤٤١٠١٢٩٥٤٢ AND(SELECT COUNT(*)=0 FROM dependency WHERE     prerequisite_id=id AND     work_spec_id NOT IN         (SELECT id FROM workspec WHERE state IN (2, 3, 5))))
#################################################################
    at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
    at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:1221)
    at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:695)
    at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
    at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:59)
    at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
    at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:2213)
    at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:2142)
    at android.arch.persistence.db.framework.FrameworkSQLiteDatabase.execSQL(FrameworkSQLiteDatabase.java:240)
    at androidx.work.impl.WorkDatabase$1.onOpen(WorkDatabase.java:114)
    at androidx.work.impl.WorkDatabase_Impl$1.onOpen(WorkDatabase_Impl.java:82)
    at android.arch.persistence.room.RoomOpenHelper.onOpen(RoomOpenHelper.java:101)
    at android.arch.persistence.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.onOpen(FrameworkSQLiteOpenHelper.java:133)
    at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:349)
    at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:238)
    at android.arch.persistence.db.framework.FrameworkSQLiteOpenHelper$OpenHelper.getWritableSupportDatabase(FrameworkSQLiteOpenHelper.java:93)
    at android.arch.persistence.db.framework.FrameworkSQLiteOpenHelper.getWritableDatabase(FrameworkSQLiteOpenHelper.java:54)
    at android.arch.persistence.room.RoomDatabase.compileStatement(RoomDatabase.java:204)
    at android.arch.persistence.room.SharedSQLiteStatement.createNewStatement(SharedSQLiteStatement.java:65)
    at android.arch.persistence.room.SharedSQLiteStatement.getStmt(SharedSQLiteStatement.java:72)
    at android.arch.persistence.room.SharedSQLiteStatement.acquire(SharedSQLiteStatement.java:87)
    at androidx.work.impl.model.WorkSpecDao_Impl.resetScheduledState(WorkSpecDao_Impl.java:326)
    at androidx.work.impl.WorkManagerImpl.rescheduleEligibleWork(WorkManagerImpl.java:393)
    at androidx.work.impl.utils.ForceStopRunnable.run(ForceStopRunnable.java:66)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
    at java.lang.Thread.run(Thread.java:764)

I have multi-able database but they are all the same as the following code :

    public static String getSqlCreation() {
        return "CREATE TABLE IF NOT EXISTS " + TB_NAME + " (" + "id INTEGER PRIMARY KEY AUTOINCREMENT," +
                Prodcut_id + " TEXT, " +
                Prodcut_code + " TEXT, " +
                Prodcut_name + " TEXT, " +
                Prodcut_new_price + " TEXT, " +
                Prodcut_old_price + " TEXT, " +
                Prodcut_image + " TEXT, " +
                Product_rating + " TEXT, " +
                Product_quantity + " TEXT NOT NULL)";
    }


public DBRecentViewHelper(Context context) {
    super(context, DB_NAME, null, DB_VERSION);
}


@Override
public void onCreate(SQLiteDatabase db) {
    try {
        db.execSQL(DBRecentViewConstants.getSqlCreation());
    } catch (SQLException e) {
        e.printStackTrace();
    }
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    db.execSQL("DROP TABLE IF EXISTS " + DBRecentViewConstants.TB_NAME);
    onCreate(db);
}

UPDATE

private DB_Tags_Helper DBhelper;
private SQLiteDatabase db;

public DB_Tags_Adapter(Context ctx) {
    this.context = ctx;
    DBhelper = new DB_Tags_Helper(context);
}

public DB_Tags_Adapter openDB() {
    try {
        db = DBhelper.getWritableDatabase();
    } catch (SQLException e) {
        e.printStackTrace();
    }
    return this;
}

public DB_Tags_Adapter open() throws SQLiteException {
    db = DBhelper.getWritableDatabase();
    return this;
}

public boolean isCreated() {
    if (db != null) {
        return db.isOpen();
    }

    return false;
}

public boolean isOpen() {
    return db.isOpen();
}

public void close() {
    try {
        DBhelper.close();
        db.close();
    } catch (SQLException e) {
        e.printStackTrace();
    }

}
public Cursor getAllData() {
    String[] columns = {DB_Tags_Constants.ROW_ID, DB_Tags_Constants.Tag_name_Ar, DB_Tags_Constants.Tag_name_EN,
            DB_Tags_Constants.Tag_Code};
    return db.query(DB_Tags_Constants.TB_NAME, columns, null, null, null, null, null);
}


public void clear() { /// to clear whole DB
    db.execSQL("delete from " + DB_Tags_Constants.TB_NAME);
}

public void Delete(String tablename, String pos) {
    try {
        db.delete(tablename, "tag_code" + "='" + pos + "'", null);
    } catch (SQLException e) {
        e.printStackTrace();
Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
Hossam Hassan
  • 795
  • 2
  • 13
  • 39
  • Post the code containing the DELETE statement. – forpas Aug 05 '19 at 14:47
  • The stacktrace points to androidx workmanager and not your code. There has been a bug there: https://issuetracker.google.com/issues/79993860 – laalto Aug 05 '19 at 14:47
  • updated all of it – Hossam Hassan Aug 05 '19 at 14:52
  • This is not the code corresponding to the DELETE statement that produces the error. – forpas Aug 05 '19 at 14:55
  • how do i get it? considering it doesnt show which line and app crash before i even get the chance to debug anything – Hossam Hassan Aug 05 '19 at 14:58
  • The error points to a statement like: `DELETE FROM workspec WHERE state IN .....` – forpas Aug 05 '19 at 15:00
  • i dont even have any db that has prerequisite_id, might be library ? is there's way to fix it – Hossam Hassan Aug 05 '19 at 15:07
  • at @laalto answer it says change Locale.getDefault() to Locale.ENGLISH, but where to change it – Hossam Hassan Aug 05 '19 at 15:11
  • Check your manifest for a line like: `android:allowBackup="true"`. If there is one, change it to: `android:allowBackup="false"`, then run the app, uninstall and rerun. – forpas Aug 05 '19 at 15:17
  • The bug report was closed as "fixed" relatively long time ago but crosschecking with release notes did not say which version has the fix. Anyway, update your library dependencies, especially workmanager. – laalto Aug 05 '19 at 15:19
  • @forpas changing it to false did not fix the issue – Hossam Hassan Aug 05 '19 at 15:22
  • @laalto i dont even use any library called workmanager – Hossam Hassan Aug 05 '19 at 15:22
  • If you changed it to false now check your code for dependencies. Remove anything unnecessary and rebuild your project. Then install preferably in a clean device and test there: uninstall/reinstall. – forpas Aug 05 '19 at 15:27
  • You can examine `gradle androidDependencies` task output to learn where those (transitive) dependencies are coming from. – laalto Aug 05 '19 at 15:30
  • after inspecting the app databases i found out that theres database called (androidx.work.workdb) that uses work_space_id and prerequisite_id, is theres way change it to be Locale.ENGLISH ? note my own gradle doesnt have androidx so might be library i have using androidx – Hossam Hassan Aug 05 '19 at 15:42

2 Answers2

0

The error message is loud and clear

android.database.sqlite.SQLiteException: no such column: ١٥٦٤٤١٠١٢٩٥٤٢

The following condition is the issue

(period_start_time + minimum_retention_duration) < ١٥٦٤٤١٠١٢٩٥٤٢

SQLite expects a column or a number (0123456789) to compare. Here you have given numbers in arabic(١٥٦٤٤١٠١٢٩٥٤٢). Ensure that its in english

Indra Kumar S
  • 2,818
  • 2
  • 16
  • 27
0

I managed to track the issue and it was in android.arch.work library implementation "android.arch.work:work-runtime:1.0.0-alpha01" it seems like they use local database and they use default local for query instead of English

Hossam Hassan
  • 795
  • 2
  • 13
  • 39