我现在确定我做错了什么因为java和SQLite对我而言是新的。因此,如果存在需要更新的“day”和“week_type”的数据,我需要检查用户何时向DB输入新数据,否则需要更新,否则创建新行。
public long creatEntry(int day2, int week_type2,
String desc2, String place2, String lessnum2) {
// TODO Auto-generated method stub
ContentValues cv = new ContentValues() ;
String update = "SELECT * FROM info WHERE day="+day2+" AND week_type="+week_type;
Cursor cr = ourDatabase.rawQuery(update, null);
if(cr!= null){
cv.put(day, day2);
cv.put(week_type, week_type2);
cv.put(desc, desc2);
cv.put(place, place2);
cv.put(lessnum, lessnum2);
return ourDatabase.update(DATABASE_TABLE,cv, day+ "=" +day2+ " AND "+week_type+ "=" +week_type2, null);
}
else{
cv.put(day, day2);
cv.put(week_type, week_type2);
cv.put(desc, desc2);
cv.put(place, place2);
cv.put(lessnum, lessnum2);
return ourDatabase.insert(DATABASE_TABLE, null, cv);
}
}