I am trying to delete a single row in my database through this method:
public boolean deleteNote(long row,String name){
int doneDelete = 0;
doneDelete = mDb.delete(SQLITE_TABLE,KEY_ROWID + " = " + row + " and " + KEY_TITLE + " = " + name, null) ;
Log.w(TAG, Integer.toString(doneDelete));
return doneDelete > 0;
}
my table schema is:
private static final String DATABASE_CREATE =
"CREATE TABLE if not exists " + SQLITE_TABLE + " (" +
KEY_ROWID + " integer PRIMARY KEY autoincrement," +
KEY_TITLE + "," +
KEY_CONTENT + "," +
KEY_TIME + "," +
" UNIQUE (" + KEY_TITLE +"));";
These variables are assigned as:
public static final String KEY_ROWID = "_id";
public static final String KEY_TITLE = "title";
public static final String KEY_CONTENT = "content";
public static final String KEY_TIME = "time";
private static final String DATABASE_NAME = "Notes Database";
private static final String SQLITE_TABLE = "Notes";
private static final int DATABASE_VERSION = 1;
I use this method when a button is click:
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "deleting: " + titleStr, Toast.LENGTH_SHORT).show();
dbHelper.deleteNote(position, titleStr);
Intent i = new Intent(DisplayNote.this, MainActivity.class);
dbHelper.close();
}
When the button is clicked, the user goes back to the main activity and the note is removed from the list, but when I press the button I get this error:
android.database.sqlite.SQLiteException: no such column: kevin (code 1): , while compiling: DELETE FROM Notes WHERE _id = 4 and title = kevin
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
at android.database.sqlite.SQLiteDatabase.delete(SQLiteDatabase.java:1494)
at com.kevguev.notesapp.NotesDBAdapter.deleteNote(NotesDBAdapter.java:95)
at com.kevguev.notesapp.DisplayNote$1.onClick(DisplayNote.java:51)
Aucun commentaire:
Enregistrer un commentaire