Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: SQLite Query not binding integer parameters?
    text
    copied!<p>I have problems when making queries with parameters to DB on Android platform (2.2). I have created table like this:</p> <pre><code>db.execSQL("CREATE VIRTUAL TABLE " + Msg._TABLE_NAME + " USING FTS3 (" + Msg._ID + " INTEGER, " (...) + Msg.READ + " SHORT DEFAULT 0," + Msg.URGENT + " SHORT DEFAULT 0" + ");"); </code></pre> <p>Then I am trying to query this using parametrized query:</p> <pre><code>String[] columns = new String[] {Msg.ROWID, Msg.TITLE, Msg.READ, Msg.URGENT}; (...) getContentResolver().query(Msg.CONTENT_URI, columns, Msg.URGENT + "=? AND " + Msg.READ + "=?" + , whereArgs, null); </code></pre> <p>where <code>whereArgs</code> varies for each query:</p> <pre><code>String[] urgentUnread = new String[]{"1", "0"}; String[] regularUnread = new String[]{"0", "0"}; </code></pre> <p>but no matter what it returns 0 results/rows even though data exist. The content provider does not change the params and the query returns nothing using QueryBuilder as well as when calling query "directly":</p> <pre><code>Cursor c = db.query(tables, columns, where, whereArgs, groupBy, having, orderBy, limit); </code></pre> <p>The query works if I do just String concat:</p> <pre><code>getContentResolver().query(Msg.CONTENT_URI, columns, Msg.READ + "=0 AND " + Msg.URGENT + "=1", null, null); </code></pre> <p>but that seems to kill the purpose of param queries and is nasty to cache. Dalvik complains (after making lot of queries) that there is no space in cache for query and, ironically, tells me to use parametrized queries with '?'. I would love to, trust me :)</p> <p>I know JavaDoc states that parameters are bound as StringS but I just simply can't believe that... because that would be major ...ahem, ... <em>WTF</em></p> <p>Where did I go wrong here?</p> <p>Thanks in advance.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload