简体   繁体   English

SQLite数据库不更新值

[英]Sqlite Database not updating values

My database is not updating it's values for some reason. 由于某种原因,我的数据库未更新其值。 According to the tutorials I've been following, I really don't know what could be wrong, here is the code on the databaseAdapter: 根据我一直关注的教程,我真的不知道出什么问题了,这是databaseAdapter上的代码:

  public boolean updatePhysicalActivity(String tableName, String recommendation, String activityDate, String activityDistance, String activityTime, String monitor, String activityVelocity ){
     ContentValues args = new ContentValues();
     args.put(RECOMMENDATION,recommendation);
     args.put(ACTIVITY_DATE, activityDate);
     args.put(ACTIVITY_DISTANCE, activityDistance);
     args.put(ACTIVITY_TIME, activityTime);
     args.put(ACTIVITY_VELOCITY, activityVelocity);
     args.put(MONITOR, monitor);
     return db.update(tableName, args, ACTIVITY_DATE + "=" + activityDate, null) > 0;
}

I have a few different tables that use the same columns, which is why I name the table when calling the update method. 我有一些使用相同列的不同表,这就是为什么在调用update方法时命名该表的原因。 I already debugged the program so I know the values are being passed on in this function, but when I check it later, nothing happens. 我已经调试了程序,所以我知道值将在此函数中传递,但是以后再检查时,什么都没有发生。 Also, I want to update the table that has the same ACTIVITY_DATE value, which is why I use ACTIVITY_DATE instead of KEYID (which was used in the tutorial). 另外,我想更新具有相同ACTIVITY_DATE值的表,这就是为什么我使用ACTIVITY_DATE而不是KEYID(在本教程中使用过)的原因。 Could that be the issue? 这可能是问题吗? If so, how do I fix it? 如果是这样,我该如何解决?

Thank you! 谢谢!

The update method has the following signature: update(table, values, whereClause, whereArgs) update方法具有以下签名: update(table, values, whereClause, whereArgs)

The proper way would be to do: 正确的方法是:

whereClause: 条款:

ACTIVITY_DATE+"=?" ACTIVITY_DATE +“ =?”

whereArgs: whereArgs:

new String[]{activityDate} 新的String [] {activityDate}

You have omit the single quotations in this line: 您已在此行中省略了单引号:

return db.update(tableName, args, ACTIVITY_DATE + "=" + activityDate, null) > 0;

change it to: 更改为:

return db.update(tableName, args, ACTIVITY_DATE + "='" + activityDate +"'", null) > 0;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM