Android Sqlite IN, NOT IN syntax

前端 未结 3 474
臣服心动
臣服心动 2021-02-05 06:54

I\'m trying to run NOT IN select where NOT IN list is dynamic. Something like

SELECT id, type FROM CONTACTS where type NOT IN (\'connec         


        
3条回答
  •  情书的邮戳
    2021-02-05 07:20

    You cannot place just one '?' instead of a list of values. As such, there is little to gain from trying to parametrize lists. One can, of course, create 2,4,16-value prepared statements ..." type NOT IN (?,?)", new String[]{ "connect","answer" },... but even on a server with remote RDBMS it has questionable value. Instead, do

    db.query(TABLE, new String[] { "id", ""}, " type NOT IN ('connect','answer')", 
         null, null, null, null);
    
    if the list is dynamic, you will have to escape the strings and put them into single quoted list.

提交回复
热议问题