Я создал таблицу sqlite, в которую я могу вставить данные для своего приложения Trip. Я пытаюсь обновить строки, но я не могу понять это. Я много искал, но я делаю что-то не так в части обновления, и я не знаю что.
public static final String DATABASE_NAME = "triptracker.db";
public static final String TABLE_NAME = "trip_table";
public static final String COL_1 = "trip_id";
public static final String COL_2 = "trip_title";
public static final String COL_3 = "trip_description";
public static final String COL_4 = "trip_image";
public static final String COL_5 = "trip_location";
Когда я вставляю данные:
public boolean insertData(String title, String description, String location) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(COL_2, title);
contentValues.put(COL_3, description);
// contentValues.put(COL_4, image);
contentValues.put(COL_5, location);
long result = db.insert(TABLE_NAME, null, contentValues);
if (result == -1)
return false;
else
return true;
}
//When I'm updating the database
public boolean update(String title, String description, String location){
SQLiteDatabase db = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(COL_2, title);
contentValues.put(COL_3, description);
contentValues.put(COL_5, location);
db.update(TABLE_NAME,contentValues, "location=?", new String[]{location} );
return true;
}
// I need to press a button in order to save the data
saveItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
if(!editLocation.getText().toString().equals("") && !editTitle.getText().toString().equals("") && !editDescription.getText().toString().equals("")){
boolean insert = myDb.update(editLocation.getText().toString(),
editDescription.getText().toString(),
editTitle.getText().toString());
}
else {
Toast.makeText(singlemomentactivity.this, "Your moment is not added ", Toast.LENGTH_LONG);
}