SQLite Update方法有什么问题?

时间:2014-01-25 03:26:09

标签: android database sqlite sql-update

由于某种原因,更新方法不会更改我的SQLite数据库值!为什么呢?

for (int go = 0; go < assignmentList.size(); go++) {

        dateBefore = assignmentList.get(go).assignmentDate;
        assDaysUntilDue = assignmentList.get(go).assignmentDaysUntilDue;
        daysElapsed = dateNow - dateBefore;
        newDays = assDaysUntilDue - daysElapsed;


        ContentValues values = new ContentValues();
        values.put(DBRecordsLayer.ASSIGNMENT_DAYS_UNTIL_DUE, 1);

        dataBase.update(DBRecordsLayer.ASSIGNMENT_TABLE, values, DBRecordsLayer.ASSIGNMENT_NUM + " = " + go, null);

// UP HERE ^^只是在变量出现问题时将值更改为1,     //但即使这样也没有给我列下1的值     //第二次尝试更改值...

        dataBase.execSQL("UPDATE " + DBRecordsLayer.ASSIGNMENT_TABLE + " SET " + DBRecordsLayer.ASSIGNMENT_ENTRY_DATE + " = " + 
                dateNow + " WHERE " +  DBRecordsLayer.ASSIGNMENT_NUM + " = " +  go + ";");
            dataBase.execSQL("UPDATE " + DBRecordsLayer.ASSIGNMENT_TABLE + " SET " + DBRecordsLayer.ASSIGNMENT_DAYS_UNTIL_DUE + " = " + 
                newDays + " WHERE " +  DBRecordsLayer.ASSIGNMENT_NUM + " = " +  go + ";");


        }

1 个答案:

答案 0 :(得分:0)

我想出了我的问题: 由于这不是运行时问题,我发现我的问题是(go + 1)问题。由于数据库ID值不一定从'1'开始,它将更新数据库中不存在的值。