0

我试图用AsyncQueryHandler一个单独的线程在我的数据库中插入项目但是当我去尝试插入一些东西时,我得到了一个 SQLException

例外

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)

这是我插入的地方

        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();
    } 

现在我知道错误说no such column,但是正如您在我的 for 循环中看到的那样,我在每次插入后清除了值,如果我只是使用正常值getContentResolver().insert(),我没有问题并且永远不会出现此错误,所以看起来值以某种方式混淆了?

在有人说只使用之前,AsyncTask我已经这样做了,并且在执行 for 循环时,插入仍然保持 UI。看到这个问题我正在经历什么

那么无论如何会导致这种情况?

4

2 回答 2

1

我认为您可能在进行异步更新时对同一个 ContentValues 对象进行并发访问。

您必须等到onInsertComplete收到回调或更简单的方法是每次都获取一个新的 ContentValues 对象

于 2012-08-17T00:41:31.623 回答
0

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

仅仅因为您认为您在数据库中有该列,并不意味着它确实存在。检查您的数据库的创建语句以及表的内容并确认。只有这样你才能确定你的问题。

于 2012-08-17T01:10:58.653 回答