我试图运行。在
选择其中。在
名单是动态的。类似于
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 ('connect','answer')
在code我徒劳的尝试是:
In the code my futile attempts were:
db.query(TABLE, new String[] { "id", ""}, " type NOT IN (?)", "connect,answer",
null, null, null); // didn't work
db.query(TABLE, new String[] { "id", ""}, " type NOT IN (?)", "'connect','answer'",
null, null, null); // didn't work
我拿上这是?
替换对待我的逗号列表作为一个参数。我没有找到一个解决方案,但它是相当难看,所以我不会张贴在这里,直到有人来着的东西更优雅
My take on this is that ?
substitution treats my comma list as single argument. I did find a solution but it is rather ugly so I won't post it here until someone comes forward with something more elegant
推荐答案
您不能将只是一个?代替值的列表。因此,很少有从试图参数化列表来获得。人们可以,当然,创建2,4,16价值prepared语句 ...型NOT IN(?,?),新的String [] {连接,答案},...
但即使远程RDBMS服务器上有可疑的价值。
Istead,做
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.
Istead, 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.
相关推荐
最新文章