我正在使用编写Trigger.io插件来管理Android上的本机数据库,并且最近开始获得此异常:
android.database.sqlite.SQLiteException: not an error
at android.database.sqlite.SQLiteQuery.nativeFillWindow(Native Method)
at android.database.sqlite.SQLiteQuery.fillWindow(SQLiteQuery.java:86)
at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:164)
at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:156)
at android.database.AbstractCursor.moveToPosition(AbstractCursor.java:161)
at android.database.AbstractCursor.moveToFirst(AbstractCursor.java:201)
at io.trigger.forge.android.modules.database.NotesDatabase.cursorToArray(NotesDatabase.java:176)
at io.trigger.forge.android.modules.database.NotesDatabase.queryToObjects(NotesDatabase.java:127)
at io.trigger.forge.android.modules.database.NotesDatabase.queryToObjects(NotesDatabase.java:120)
at io.trigger.forge.android.modules.database.API.query(API.java:50)
stacktrace中提到的函数是:
//"atomic" is always true when this is called
public synchronized JSONArray queryToObjects(String query, boolean atomic) throws JSONException{
if(atomic) open();
Cursor c = db.rawQuery(query, null);
JSONArray notes = cursorToArray(c);
c.close();
if(atomic) close();
return notes;
}
private JSONArray cursorToArray(Cursor c) throws JSONException{
final String[] columnNames = c.getColumnNames();
JSONArray results = new JSONArray();
for (c.moveToFirst();!c.isAfterLast();c.moveToNext()){
JSONObject object = new JSONObject();
for(String name : columnNames){
int index = c.getColumnIndex(name);
//"get" is defined elsewhere, but this line never executes
object.put(name, get(c, index));
}
results.put(object);
}
return results;
}
我正在使用的查询是:
通过hashtags选择不同的hashtags作为名称,count(hashtags)作为NoteTag组的计数
以前有没有经历过这样的事情?提前感谢您提出的任何建议!
更新 Cursor似乎存在根本性的错误:对“getColumnNames”的调用返回一个空数组,并且调用c.getCount()会产生相同的错误。
另一个更新:
一些有效的查询:
select * from Notes where localID in (select distinct localID from NoteTag where hashtags == '#gold') and status != 'delete' order by timestamp desc limit 0,25
select * from Notes where localID in (select distinct localID from NoteTag where hashtags == '#woot' intersect select distinct localID from NoteTag where hashtags == '#yeah') and status != 'delete' order by timestamp desc limit 0,25
答案 0 :(得分:4)
解决方案:问题的根源是我在javascript端调用forge函数的方式。我传递的是一个预期字符串的对象(“查询”参数),它被本机桥强制转换为字符串。这个例外是SQLite非常迂回地说“这不是一个查询”。