0

I use the following code:

private static final String JUMP_COUNT_QUERY_FORMAT =
        "select count(*) " +
                "from log_entry " +
                "inner join log_entry_rig on log_entry._id = log_entry_rig.log_entry " +
                "where log_entry_rig.rig = {0}"; //TODO BUG crash in arabic

and then later:

String query = MessageFormat.format(JUMP_COUNT_QUERY_FORMAT, rigId);
Cursor cursor = null;
     try
     {
         cursor = db.rawQuery(query, null);
         ...
     }

which result in this error in the stacktrace, in which you can see that the 1 in rigId turned into an arabic 1 (١):

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: org.myapp, PID: 4913
    java.lang.RuntimeException: Unable to start activity ComponentInfo{org.myapp/org.myapp.appLog2}: android.database.sqlite.SQLiteException: no such column: ١ (code 1 SQLITE_ERROR): , while compiling: select count(*) from log_entry inner join log_entry_rig on log_entry._id = log_entry_rig.log_entry where log_entry_rig.rig = ١
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2925)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3060)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:110)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1800)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6649)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:826)
     Caused by: android.database.sqlite.SQLiteException: no such column: ١ (code 1 SQLITE_ERROR): , while compiling: select count(*) from log_entry inner join log_entry_rig on log_entry._id = log_entry_rig.log_entry where log_entry_rig.rig = ١
        at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
        at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:901)
        at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:512)
        at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
        at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
        at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
        at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:46)
        at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1408)
        at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1347)

Now, I know that MessageFormat has no real use for locales but I have many calls throughout the app to SQLite and I want to proof it against crashes such as this if it gets called on devices with locales that include different numeral systems (Arabic, Thai etc...). What can be done in this regard?

MikeT
  • 51,415
  • 16
  • 49
  • 68
PIXP
  • 2,382
  • 3
  • 19
  • 28

0 Answers0