0

I am trying to use AsyncQueryHandler to insert items in my Database in a separate thread but when I go and try to insert something I get a SQLException

exception

08-16 18:57:13.662: E/SQLiteLog(17319): (1) table Part1s has no column named name
08-16 18:57:13.672: E/SQLiteDatabase(17319): Error inserting frame_number=2 name=Jeff game_id=1
08-16 18:57:13.672: E/SQLiteDatabase(17319): android.database.sqlite.SQLiteException: table Part1s has no column named name (code 1): , while compiling: INSERT INTO Part1s(frame_number,name,game_id) VALUES (?,?,?)
08-16 18:57:13.672: E/SQLiteDatabase(17319):    at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
08-16 18:57:13.672: E/SQLiteDatabase(17319):    at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:882)
08-16 18:57:13.672: E/SQLiteDatabase(17319):    at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:493)
08-16 18:57:13.672: E/SQLiteDatabase(17319):    at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
08-16 18:57:13.672: E/SQLiteDatabase(17319):    at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
08-16 18:57:13.672: E/SQLiteDatabase(17319):    at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
08-16 18:57:13.672: E/SQLiteDatabase(17319):    at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1467)
08-16 18:57:13.672: E/SQLiteDatabase(17319):    at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1339)
08-16 18:57:13.672: E/SQLiteDatabase(17319):    at com.tyczj.bowling.providers.Games.insert(Games.java:382)
08-16 18:57:13.672: E/SQLiteDatabase(17319):    at android.content.ContentProvider$Transport.insert(ContentProvider.java:201)
08-16 18:57:13.672: E/SQLiteDatabase(17319):    at android.content.ContentResolver.insert(ContentResolver.java:864)
08-16 18:57:13.672: E/SQLiteDatabase(17319):    at android.content.AsyncQueryHandler$WorkerHandler.handleMessage(AsyncQueryHandler.java:96)
08-16 18:57:13.672: E/SQLiteDatabase(17319):    at android.os.Handler.dispatchMessage(Handler.java:99)
08-16 18:57:13.672: E/SQLiteDatabase(17319):    at android.os.Looper.loop(Looper.java:137)
08-16 18:57:13.672: E/SQLiteDatabase(17319):    at android.os.HandlerThread.run(HandlerThread.java:60)
08-16 18:57:13.672: E/AndroidRuntime(17319): FATAL EXCEPTION: AsyncQueryWorker
08-16 18:57:13.672: E/AndroidRuntime(17319): android.database.SQLException: Failed to insert row into content://com.tyczj.bowling.providers.Games/Part1s
08-16 18:57:13.672: E/AndroidRuntime(17319):    at com.tyczj.bowling.providers.Games.insert(Games.java:387)
08-16 18:57:13.672: E/AndroidRuntime(17319):    at android.content.ContentProvider$Transport.insert(ContentProvider.java:201)
08-16 18:57:13.672: E/AndroidRuntime(17319):    at android.content.ContentResolver.insert(ContentResolver.java:864)
08-16 18:57:13.672: E/AndroidRuntime(17319):    at android.content.AsyncQueryHandler$WorkerHandler.handleMessage(AsyncQueryHandler.java:96)
08-16 18:57:13.672: E/AndroidRuntime(17319):    at android.os.Handler.dispatchMessage(Handler.java:99)
08-16 18:57:13.672: E/AndroidRuntime(17319):    at android.os.Looper.loop(Looper.java:137)
08-16 18:57:13.672: E/AndroidRuntime(17319):    at android.os.HandlerThread.run(HandlerThread.java:60)

here is where I do my inserting

        for(int i = 0;i<10;i++){
        int num = i+1;
        values.put(Games.NAMES_FRAME_NUM,num);
        values.put(Games.NAMES_GAME_ID,gameid);
        values.put(Games.NAMES_NAME,name);
        qHandler.startInsert(0, null, Games.NAMES_URI,values);
//          getContentResolver().insert(Games.NAMES_URI, values);
        names(i,name);
        values.clear();
        values.put(Games.PART1_FRAME_NUM,num);
        values.put(Games.PART1_NUM,"0");
        values.put(Games.PART1_GAME_ID,gameid);
        qHandler.startInsert(0, null, Games.PART1_URI,values);
//          getContentResolver().insert(Games.PART1_URI, values);
        values.clear();
        values.put(Games.PART2_FRAME_NUM,num);
        values.put(Games.PART2_NUM,"0");
        values.put(Games.PART2_GAME_ID,gameid);
        qHandler.startInsert(0, null, Games.PART2_URI,values);
//          getContentResolver().insert(Games.PART2_URI, values);
        values.clear();
        values.put(Games.TOTALS_FRAME_NUM,num);
        values.put(Games.TOTALS_FRAME_TOTAL,"0");
        values.put(Games.TOTALS_GAME_ID,gameid);
        qHandler.startInsert(0, null, Games.TOTALS_URI,values);
//          getContentResolver().insert(Games.TOTALS_URI, values);
        values.clear();
//          ContentValues values = new ContentValues();
        values.put(Games.POCKETS_BOWLER_ID,bowlerClickedID);
        values.put(Games.POCKETS_FRAME_NUM,i);
        values.put(Games.POCKETS_GAME_ID,gameID);
        values.put(Games.POCKETS_TEAM_ID, teamSelectedID);
        values.put(Games.POCKETS_TOURNAMENT_ID, tournamentID);
        values.put(Games.POCKETS_NUM, 0);
        values.put(Games.POCKETS_SEASON, pref.getLong(Preferences.SELECTED_SEASON, 1));
        qHandler.startInsert(0, null, Games.POCKETS_URI,values);
//          getContentResolver().insert(Games.POCKETS_URI, values);
        values.clear();
    } 

Now I know the error says no such column but as you can see in my for loop I clear the values after each insert and if I just use the normal getContentResolver().insert() I have no problems and never get this error so it seems the values are getting mixed up somehow?

and before anyone says says just use an AsyncTask I already did that and when executing the for loop the inserts still hold up the UI. see this question for what I am experiencing

So anyway what would be causing this?

Community
  • 1
  • 1
tyczj
  • 71,600
  • 54
  • 194
  • 296

2 Answers2

1

I think you might be doing a concurrent access on the same ContentValues object while Async update is going on.

You have to wait until onInsertComplete callback is recieved or easier way is to just get a new object of ContentValues each time

nandeesh
  • 24,740
  • 6
  • 69
  • 79
0

android.database.sqlite.SQLiteException: table Part1s has no column named name (code 1): , while compiling: INSERT INTO Part1s(frame_number,name,game_id) VALUES (?,?,?)

Just because you think you have the column in the database, does not mean that it actually exists. Check your create statement of you database as well as the contents of the tables and CONFIRM this. Only then can you pinpoint your problem.

JoxTraex
  • 13,423
  • 6
  • 32
  • 45
  • 1
    like I said the inserting of the databases work perfectly if I use `getContentResolver().insert()` so there is nothing wrong with the database – tyczj Aug 17 '12 at 02:37