mardi 22 septembre 2015

Error creating SQLite table after DROP

Stay awhile and listen)

I've got about 50 devices running my application. Some users expirience a strange error (not all):

android.database.sqlite.SQLiteException: no such table: points (code 1)
at android.database.sqlite.SQLiteConnection.nativeExecuteForCursorWindow(Native Method)
at android.database.sqlite.SQLiteConnection.executeForCursorWindow(SQLiteConnection.java:840)
at android.database.sqlite.SQLiteSession.executeForCursorWindow(SQLiteSession.java:836)
at android.database.sqlite.SQLiteQuery.fillWindow(SQLiteQuery.java:62)
at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:143)
at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:133)
at android.database.AbstractCursor.moveToPosition(AbstractCursor.java:197)
at android.database.AbstractCursor.moveToNext(AbstractCursor.java:245)
at kgk_logic.Manager.reloadPoints(Manager.java:67)
at mobile.WorkActivity$WHandler.handleMessage(WorkActivity.java:544)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5124)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:783)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:550)
at dalvik.system.NativeStart.main(Native Method)

The logic is: once in 15 mins device checks its location and compares with remote bd data/ If device in specific radius - server returns a list of points (just coords). These points go to the SQLTable "points", but before that previus points table is dropped and new one created with new fresh data:

DB db = DB.getInstance(KGKMobile.getAppContext());
                    SQLiteDatabase wdb = db.getWritableDatabase();
                    wdb.execSQL(String.format("DROP TABLE %s", DB.POINTS_TABLE));
                    db.createPointsTable(wdb);

                    for (KGKPoint point : WorkActivity.getManager().getPoints()) {
                        wdb.insert(DB.POINTS_TABLE, null, point.getCV());
                    }

Method createPointsTable() contains only one query:

 - execSQL(String.format("CREATE TABLE %s (id integer PRIMARY KEY NOT NULL, name TEXT NOT NULL, lat real NOT NULL, lng real NOT NULL, code TEXT )", "points"));

My bet - table dropped but not created properly. But i don't know why. Or maybe there is another reason?

Aucun commentaire:

Enregistrer un commentaire