Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>So your problem is that you placed only one placeholder which will be replaced only with one value and array of args should have only one item. It should potentially work if you had 9x <strong><code>?</code></strong> for each item in array.</p> <p>It works as one placeholder - one value <strong>(same order)</strong>. I wrote for you this snippet of code. Check it out.</p> <pre><code>int[] ids = new int[] {1,2,3,4,6,7,8,9,10}; StringBuilder query = new StringBuilder(); query.append("delete from table where column_id not in ("); for (int i = 0; i &lt; ids.length; i++) { query.append("?"); if (i &lt; ids.length - 1) { query.append(","); } } query.append(")"); db.execSQL(query.toString(), ids); </code></pre> <p>Now it should works. Also <strong><code>?</code></strong> character in dynamically created query is called <strong>placeholder</strong> and each placeholder will be replaced with value from <code>String[]</code> in same order.</p> <p>I pretty recommend an usage of placeholders, whenever you will work with database. This approach is cleaner, safer and better looking.</p> <h2>Update for API 11+</h2> <pre><code>public int delete() { int[] ids = new int[] {1,2,3,4,6,7,8,9,10}; String[] args = new String[ids.length]; StringBuilder query = new StringBuilder(); query.append("delete from table where column_id not in ("); SQLiteStatement stmt = null; for (int i = 0; i &lt; ids.length; i++) { args[i] = String.valueOf(ids[i]); query.append("?"); if (i &lt; ids.length - 1) { query.append(","); } } query.append(")"); stmt = db.compileStatement(query.toString()); stmt.bindAllArgsAsStrings(args); return stmt.executeUpdateDelete(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

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