3

我正在使用编写 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)

因此,堆栈跟踪中提到的函数是:

//"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;
}

我正在使用的查询是:

从 NoteTag 组中选择不同的主题标签作为名称,计数(主题标签)作为主题标签

有没有人经历过这样的事情?提前感谢您提出的任何建议!

更新: 光标似乎有一些根本性的错误:对“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
4

1 回答 1

4

解决方案:问题的根源是我在javascript端调用forge函数的方式。我正在传递一个需要字符串的对象(“查询”参数),该对象被本机桥强制转换为字符串。这个例外是 SQLite 非常迂回的说法“这不是一个查询”。

于 2013-02-22T18:30:49.960 回答