0
將數據插入我的數據庫時,我使用-1。我是否應該不使用0來指示是否插入了NOTHING,然後返回false。只是想知道這是正確的方式?將數據插入數據庫 - 爲什麼我使用-1而不是0?
非常感謝,
馬克
Routine.java
if (routineInserted) {
Toast.makeText(RoutineEdit.this, "Activity Inserted", Toast.LENGTH_LONG).show();
MediaPlayer mymedia = MediaPlayer.create(RoutineEdit.this, R.raw.whoosh);
mymedia.start();
} else {
Database.java
public boolean insertRoutine(int activityImage, String selectedDay, int activitySlot) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(RoutineColumn1,selectedDay);
contentValues.put(RoutineColumn2,activityImage);
contentValues.put(RoutineColumn3,activitySlot);
long result = db.insert(RoutineTable, null, contentValues); // The db.insert is responsible for insertion of the data into the database and stores the result of this action (either true or false) in result.
if(result == -1) // if the result is not equal to -1 or data is not successfully inserted it will return FALSE. otherwise TRUE
return false;
else
return true;}
雖然是什麼意思?只要閱讀文檔並理解我應該使用-1但理解爲什麼? – MarkW