android.database.sqlite.SQLiteException:无法识别的令牌

时间:2016-07-21 12:02:05

标签: android sqlite

我在使用主键" TransactionID"从表中删除条目时遇到异常。 TransactionID值是一个包含" - "的非数字序列。同样。以下是LogCat消息

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

TranscationID无效吗?

3 个答案:

答案 0 :(得分:2)

试用此代码

{{1}}

答案 1 :(得分:0)

用单引号

连接
DELETE FROM Datas WHERE TransactionID='29e7c8a8-b38b-4812-8a2d'

答案 2 :(得分:0)

如果您尝试使用文本查询检索或插入NULL control character "\u0000"到SQLite数据库中,您也可以获得此异常:

class Shape
{
    public int Width { get; set; }
    public int Height { get; set; }
}

class Circle : Shape
{
    public int Radius { get; set; }
    public bool FillColor { get; set; }
}

虽然键盘没有简单的方法来键入控制字符,但它仍然是Java String中的有效字符,并且在将String发送到Android SQLite数据库时会导致异常:

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

因为它是一个不可见的字符并且不容易被发现,所以你可以使用字符串的Hex显示来查看所有字符。例如,使用BBEdit的'Hex dump front document'作为UTF-16LE(Little-Endian)。

要避免此崩溃,您必须使用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) 删除此NULL字符。请参见此处的示例: