Android SQLite更新和随WHERE子句递增

Android SQLite更新和随WHERE子句递增,android,sqlite,Android,Sqlite,我正在使用SQLite,并且我正在使用where子句来更新数据库中的一行,如果它存在,并且如果它不存在,则需要插入一个新行 public long createEntry(int x, int y, String date, int Version_Zero_HoursTable_One_DateTable) { /* * first grab the values needed to increment the database values * */

我正在使用SQLite,并且我正在使用where子句来更新数据库中的一行,如果它存在,并且如果它不存在,则需要插入一个新行

    public long createEntry(int x, int y, String date, int Version_Zero_HoursTable_One_DateTable)
{
    /*
     * first grab the values needed to increment the database values
     * */
    String[] column = new String[]{DATE,NUM_X,NUM_Y};
    Cursor c = ourDatabase.query(HOURS_TABLE, column, date, null, null,
            null, null);    
    int current_x =0;
    int current_y  = 0;
    int iX = c.getColumnIndex(NUM_X);
    int iY = c.getColumnIndex(NUM_Y);
    for(c.moveToFirst(); !c.isAfterLast(); c.moveToNext()){
        current_Y += c.getInt(iY);
        current_X += c.getInt(iX);
    }
    ContentValues cv = new ContentValues();
    cv.put(NUM_X, x + current_X);
    cv.put(NUM_Y, y + current_Y);
    cv.put(DATE, date);
    String WHEREargs = DATE+"="+date;
    if(Version_Zero_HoursTable_One_DateTable == 0)
    {
    return ourDatabase.update(HOURS_TABLE, cv, WHEREargs, null);
    //return ourDatabase.insert(HOURS_TABLE, null, cv);
    }
    else
    {
        return ourDatabase.update(HOURS_TABLE, cv, WHEREargs, null);
        //return ourDatabase.insert(DATE_TABLE, null, cv);
    }
}

我不能编译它,因为我在打电话。 我想你可以运行2个脚本 首先,您可以运行Update**这没有问题,因为如果行不存在,则什么都没有**

其次,您可以使用where子句插入脚本关于行的子句不存在

当我回家的时候,如果你不写,我可以写剧本

你能看看这个链接吗

您好,您能解释清楚吗,问题是当您要更新一行时,两行都会更新?我说得对吗?不完全正确,我现在正在编辑我的问题,现在的问题是我无法更新一个尚不存在的行,因此我试图找出一种方法,如果无法更新该行(因为不存在具有当前日期值的行),我如何插入一行并仍然返回值?感谢您的帮助您的意思是最后一个字,仍然返回值是,它确实返回值,我在编码是否返回更新或插入时遇到问题,您如何确定光标是否正在收集值?您是否可以查看我的答案和答案的结尾有一个链接您刚才发送的链接正是我的代码缺少的链接,使用insert或replace可以消除我刚刚完成的嵌套if循环(确定是更新还是插入)的需要,我将重构我的代码,并在可能的情况下更新我的答案,谢谢你们的帮助