Raw Query无法将BLOB转换为字符串以选择String []的列

时间:2016-12-01 13:13:55

标签: java android mysql ormlite

我有一个问题,我收到此错误:

 Caused by: android.database.sqlite.SQLiteException: unknown error (code 0): Unable to convert BLOB to string

我在这段代码中遇到了这个问题:

GenericRawResults<String[]> rawResults;
                rawResults = DatabaseHelper.getHelper(this)
                        .getDaoForClass(Table1.class)
                        .queryRaw("SELECT idList, COUNT(*) FROM Table1 ORDER BY idList");
List<String[]> results = rawResults.getResults();

当我尝试将rawResult转换为结果时。 &#34; IDLIST&#34; field是String []

我还尝试使用此查询选择列:

SELECT idList FROM Table1

但同样的错误出现了。

基本上我要做的就是选择ID包含在idList字段String []中的对象的频率。

根据要求,我选择的表是:

@DatabaseField(canBeNull = false, columnName = "type")
@Expose
@SerializedName("type")
public Type type;

@DatabaseField(columnName = "idList",  dataType = DataType.SERIALIZABLE)
@Expose
@SerializedName("idList")
public String[] idList;

@DatabaseField(canBeNull = false, columnName = "occurredDate")
@Expose
@SerializedName("occurredDate")
public Date occurredDate;

1 个答案:

答案 0 :(得分:0)

Ii idList包含要查看计数的ID,然后查询可能就像

SELECT ID, COUNT(*) 
FROM Table1 
WHERE ID in (XXX)
GROUP BY ID
ORDER BY ID

XXX - 应该将idList转换为包含以ids分隔的字符串, 例如。 1,2,3,4,5或'1','2','3'如果id是字符串