Greum
Well-Known Member
I have the following method.
The delete process works fine but I have added the check at the beginning to see if the input is empty, and it's not working. If I try to delete a row with empty input, the Toast message is "0 record(s) deleted" rather than "No input".
The log is reporting
I/delete() =: DELETE FROM names_and_addresses WHERE name = '';
From the delete point of view the result is the same, but I plan to put a similar check in the input method as I don't want my db table filled will null records.
Can anyone see where I'm going wrong?
Java:
public void delete(String name, Context x) {
String msg;
// Check if anything input
if (name == null) {
msg = "No input";
} else {
// Count the number of rows
String query = "SELECT COUNT(*) FROM " + TABLE_NA +
" WHERE " +
NA_NAME + " = '" + name + "';";
Cursor c = mDB.rawQuery(query, null);
int count = 0;
if (null != c)
if (c.getCount() > 0) {
c.moveToFirst();
count = c.getInt(0);
}
c.close();
// Now run the delete
query = "DELETE FROM " + TABLE_NA +
" WHERE " +
NA_NAME + " = '" + name + "';";
Log.i("delete() = ", query);
mDB.execSQL(query);
msg = count + " record(s) deleted";
}
makeToast(msg, x);
}
The delete process works fine but I have added the check at the beginning to see if the input is empty, and it's not working. If I try to delete a row with empty input, the Toast message is "0 record(s) deleted" rather than "No input".
The log is reporting
I/delete() =: DELETE FROM names_and_addresses WHERE name = '';
From the delete point of view the result is the same, but I plan to put a similar check in the input method as I don't want my db table filled will null records.
Can anyone see where I'm going wrong?