-2

I'm getting an exception while deleting an entry from the table using the primary key "TransactionID". The TransactionID value is a aphanumeric sequence which contains "-" as well. Below is the LogCat message


android.database.sqlite.SQLiteException: unrecognized token : "29e7c8a8" (code 1):, while compiling: DELETE FROM Datas WHERE TransactionID=29e7c8a8-b38b-4812-8a2d

Is the TranscationID not valid?

Ajay
  • 189
  • 1
  • 4
  • 16

3 Answers3

2

Try this code

 db.delete(Datas,TransactionID + " = ?",new String[] { "29e7c8a8-b38b-4812-8a2d" });
CL.
  • 173,858
  • 17
  • 217
  • 259
Android Surya
  • 544
  • 3
  • 17
0

concate it with single quotes

DELETE FROM Datas WHERE TransactionID='29e7c8a8-b38b-4812-8a2d'
Ravi
  • 34,851
  • 21
  • 122
  • 183
0

You can also get this exception if you try to retrieve or insert a NULL control character like "\u0000" into an SQLite database, using a text query:

SELECT * FROM my_table WHERE text =
   "Here is a NULL control character \u0000 in the text";

Although there is no easy way for a keyboard to type a control character, it's still a valid character in Java String, and it will cause an exception when the String is sent to the Android SQLite database:

android.database.sqlite.SQLiteException: unrecognized token (code 1):
  "'Here is a NULL control character ": 
  , while compling: SELECT * FROM my_table WHERE text = '...';
  at android.database.sqlite.SQLiteDatabase.native_execSQL(Native Method)
  at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1763)

Because it's an invisible character and not easily spotted, you can use a Hex display of the string, to see all the characters. For example, use BBEdit's 'Hex dump front document' as UTF-16LE (Little-Endian).

To avoid this crash, you have to remove this NULL character, using String.replace(). See examples here:

Mr-IDE
  • 7,051
  • 1
  • 53
  • 59