Android SQLiteException "not an error" in Cursor
android, sqlite, trigger.io
Solution
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".
Problem
I'm using writing a Trigger.io plugin to manage a native database on Android, and have recently begun getting this exception: ``` 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: ``` //"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 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. 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 ```