0

I've been trying to get the IN operator to work with FMDB but have had zero luck. I've tried many different google searches and the only relevant post I found was on Stack Overflow but it is returning 0 records. Passing an array to sqlite WHERE IN clause via FMDB?...

If there are any existing examples or if someone knows how to do this, I would greatly appreciate any help.

Thanks

Community
  • 1
  • 1
user684360
  • 47
  • 1
  • 6

1 Answers1

3

I was having the same issue, and I believe I figured it out, at least for my own app. First, structure your query like so, matching the number of question marks as the amount of data in the array:

NSString *getDataSql = @"SELECT * FROM data WHERE dataID IN (?, ?, ?)";

Then use the executeQuery:withArgumentsInArray call:

FMResultSet *results = [database executeQuery:getDataSql withArgumentsInArray:dataIDs];

In my case, I had an array of NSString objects inside the NSArray named dataIDs. I tried all sorts of things to get this call working, but with this combination of sql / function, I was able to get results.

dreadpirateryan
  • 545
  • 1
  • 7
  • 16