Android SQLiteException在游标中“不是一个错误”。

时间:2021-03-18 23:07:10

I'm using writing a Trigger.io plugin to manage a native database on Android, and have recently begun getting this exception:

我在写一个触发器。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)

The functions mentioned in the stacktrace are thus:

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

and the query I'm using is:

我使用的查询是:

select distinct hashtags as name, count(hashtags) as count from NoteTag group by hashtags

选择不同的hashtags作为名称,count(hashtags),从NoteTag组到hashtags。

Has anyone experienced anything like this before? Thanks in advance for any suggestions you can make!

有人以前有过这样的经历吗?谢谢你的建议!

Update: There seems to be something fundamentally wrong with the Cursor: the call to "getColumnNames" returns an empty array, and calling c.getCount() produces the same error.

更新:似乎有一些根本错误的游标:调用“getColumnNames”返回一个空数组,调用c.getCount()会产生相同的错误。

Another Update:

另一个更新:

Some queries that do work:

一些确实有用的查询:

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

1 个解决方案

#1


4  

Solution: The source of the problem was the way I was calling forge function on the javascript side. I was passing an object where a string was expected (the "query" parameter), which was coerced into a string by the native bridge. This exception was SQLite's very roundabout way of saying "this is not a query".

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

#1


4  

Solution: The source of the problem was the way I was calling forge function on the javascript side. I was passing an object where a string was expected (the "query" parameter), which was coerced into a string by the native bridge. This exception was SQLite's very roundabout way of saying "this is not a query".

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