Reputation: 33
I get an unrecognized token exception when I try to delete from my database.
I have tried to include my strings in ''
instead of ""
, I have tried storing the values in dedicated string variables and nothing.
I just don't know what to do, here is the code as it is currently:
public void deleteCrime(Crime crime) {
ContentValues values = getContentValues(crime);
mDatabase.delete(CrimeTable.NAME,
values.getAsString(CrimeTable.Cols.UUID) + "= ?",
new String[]{crime.getId().toString()});
}
I have tried it this way too:
public void deleteCrime(Crime crime) {
ContentValues values = getContentValues(crime);
mDatabase.delete(CrimeTable.NAME,
values.getAsString(CrimeTable.Cols.UUID) + "= " + crime.getId().toString(),
null);
}
And this:
public void deleteCrime(Crime crime) {
ContentValues values = getContentValues(crime);
String databaseId = values.getAsString(CrimeTable.Cols.UUID);
String crimeId = crime.getId().toString();
mDatabase.delete(CrimeTable.NAME,
databaseId + "= ?",
new String[]{crimeId});
}
And:
public void deleteCrime(Crime crime) {
ContentValues values = getContentValues(crime);
String databaseId = values.getAsString(CrimeTable.Cols.UUID);
String crimeId = crime.getId().toString();
mDatabase.delete(CrimeTable.NAME,
databaseId + "= " + crimeId,
null);
}
And all the combinations and permutations of applying ''
and " "
to the strings...
Even if I don't parse them into strings and use ''
or ""
on them, I always get the same error (from the first 4 codes in this post):
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.ricardo.criminalintent, PID: 27841
android.database.sqlite.SQLiteException: unrecognized token: "46cf" (code 1): , while compiling: DELETE FROM crimes WHERE fe950f06-dd38-46cf-898e-f4a7f7f27dab = fe950f06-dd38-46cf-898e-f4a7f7f27dab
And if I try another row in my database:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.ricardo.criminalintent, PID: 28258
android.database.sqlite.SQLiteException: no such column: b09902bc (code 1): , while compiling: DELETE FROM crimes WHERE b09902bc-0829-4989-8395-ed24dc397a85 = b09902bc-0829-4989-8395-ed24dc397a85
And...
public void deleteCrime(Crime crime) {
mDatabase.delete(CrimeTable.NAME,
CrimeTable.Cols.UUID + "=? ",
new String[]{crime.getId().toString()});
}
Or (from the last code in this post, the one with the And...):
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.ricardo.criminalintent, PID: 3418
android.database.sqlite.SQLiteException: unrecognized token: "46cf" (code 1): , while compiling: DELETE FROM crimes WHERE uuid= fe950f06-dd38-46cf-898e-f4a7f7f27dab
I don't know what else to do... I'm desperate, please help me!
Upvotes: 0
Views: 1283
Reputation: 38098
Try this code, instead:
public void deleteCrime(Crime crime)
{
mDatabase.execSQL("DELETE FROM crimes WHERE uuid = ?", new String([] {crime.getId()}));
}
Upvotes: 1