【发布时间】:2012-05-20 12:21:39
【问题描述】:
我的数组包含一些元素:
(
"element 1",
"element 2",
"element 3"
)
我需要查询数据库,并获取存储在数据库中上述数组中的每个元素:
select * from table1 where type=?
我想到了for循环,对于数组,select查询会根据数组的大小重复,用处不大。
任何想法,提前谢谢:)
【问题讨论】:
我的数组包含一些元素:
(
"element 1",
"element 2",
"element 3"
)
我需要查询数据库,并获取存储在数据库中上述数组中的每个元素:
select * from table1 where type=?
我想到了for循环,对于数组,select查询会根据数组的大小重复,用处不大。
任何想法,提前谢谢:)
【问题讨论】:
使用IN operator:
select * from table1 where type in ('element1', 'element2');
【讨论】:
'element1', 'element2' 存储在NSMutableArray 中,那么如何将NSMutable 数组转换为这样的字符串?
select * from table where type in (?, ?) 然后bind them to your values
你的意思是像
select * from table1 where type in ('type1', 'type2', 'type3')
?
【讨论】: