-1

inspectionid对于我的更新,我想使用,搜索正确的 pos activityidsubactivityid但是当调用更新语句时,我得到了这个错误。有人可以帮忙。

public int updateSubActivityActivityComment(String comment, int rating, int subActivityId, int activityId, int inspectionId){
    SQLiteDatabase db = this.getWritableDatabase();
    ContentValues contentValues = new ContentValues();

    contentValues.put(KEY_RATING, rating);
    contentValues.put(KEY_COMMENT, comment);

    return db.updateWithOnConflict(TABLE_INSPECTION, contentValues,KEY_SUB_ACTIVITY_ID+ " = ? "+subActivityId+" AND "+KEY_INSPECTION_ID + " = ? "+inspectionId +" AND "+KEY_ACTIVITY_ID +" = ? "+activityId,new String[]{String.valueOf(subActivityId)} ,SQLiteDatabase.CONFLICT_IGNORE);
}

日志猫-

java.lang.IllegalArgumentException: Too many bind arguments.  3 arguments were provided but the statement needs 2 arguments.
                                                     at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:68)
                                                     at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
                                                     at android.database.sqlite.SQLiteDatabase.updateWithOnConflict(SQLiteDatabase.java:1574)
                                                     at com.theavo.ck_app.DatabaseHelper.updateSubActivityActivityComment(DatabaseHelper.java:264)
                                                     at com.theavo.ck_app.FragmentSubInspectionComment.onClick(FragmentSubInspectionComment.java:470)
                                                     at android.view.View.performClick(View.java:4780)
                                                     at android.view.View$PerformClick.run(View.java:19866)
                                                     at android.os.Handler.handleCallback(Handler.java:739)
                                                     at android.os.Handler.dispatchMessage(Handler.java:95)
                                                     at android.os.Looper.loop(Looper.java:135)
                                                     at android.app.ActivityThread.main(ActivityThread.java:5254)
                                                     at java.lang.reflect.Method.invoke(Native Method)
                                                     at java.lang.reflect.Method.invoke(Method.java:372)
                                                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
                                                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
4

2 回答 2

5

你应该在这里传递三个值

String[] whereArgs =  new String[]{String.valueOf(subActivityId),String.valueOf(inspectionId),String.valueOf(activityId)};

db.updateWithOnConflict(TABLE_INSPECTION, contentValues,KEY_SUB_ACTIVITY_ID+ " = ? "+" AND "+KEY_INSPECTION_ID + " = ? "+" AND "+KEY_ACTIVITY_ID +" = ? ",whereArgs ,SQLiteDatabase.CONFLICT_IGNORE);
于 2016-01-30T06:39:34.337 回答
1

使用updateWithOnConflict方法 as 通过传递第 4 个参数作为null?从第 3 个参数中删除:

db.updateWithOnConflict(TABLE_INSPECTION,contentValues,
          KEY_SUB_ACTIVITY_ID+ " = "
          +subActivityId+" AND "+KEY_INSPECTION_ID + " = "
          +inspectionId +" AND "+KEY_ACTIVITY_ID +" = "
          +activityId,null ,SQLiteDatabase.CONFLICT_IGNORE);

因为已经在第三个参数中传递了列名的值,所以不需要再次传递它。

于 2016-01-30T06:43:48.453 回答