To help anyone with similar needs, I'm answering my own question. I figured out a solution that works for pulling specific row and/or column data from my SQLite database in query form, rather than using Fetch with Predicate. (Note: code shows examples for extracting string and integer data types.)
First, add a Framework for libsqlite3.0.dylib
In the header add the following file:
#import <sqlite3.h>
@interface MyViewController : UIViewController {
NSMutableArray *dataArray; // This array will hold data you will extract
NSArray *summaryArray; // This holds an array of PKIDs that will be queried
}
@property (nonatomic, retain) NSMutableArray *dataArray;
@property (nonatomic, assign) NSArray *summaryArray;
- (void)getData:(NSInteger *)intPKID;
- (NSString *) getDBPath;
@end
In the implementation file add the following:
static sqlite3 *database = nil; // add this before the @implementation line
@synthesize dataArray;
@synthesize summaryArray;
- (NSString *) getDBPath {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES);
NSString *documentsDir = [paths objectAtIndex:0];
return [documentsDir stringByAppendingPathComponent:@"MyDatabaseName.sqlite"];
}
- (void)getData:(NSInteger *)intPKID {
NSString *dbPath = [self getDBPath];
if (sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK) {
NSString *strSQL;
NSString *strExtractedData;
NSUInteger count;
NSInteger intPK;
if (self.dataArray == nil) {
self.dataArray = [[[NSMutableArray alloc] init] autorelease];
} else {
[self.dataArray removeAllObjects];
}
count = [self.summaryArray count];
for (NSUInteger i = 0; i < count; ++i) {
// Extract a specific row matching a PK_ID:
strSQL = [NSString stringWithFormat: @"select intPKID, strColumnName from MyDatabaseName where (PKID = %i)", [[self.summaryArray objectAtIndex:i]intValue]];
// Extract a range of rows matching some search criteria:
// strSQL = [NSString stringWithFormat: @"select intPKID, strColumnName from MyDatabaseName where (ITEMTYPE = '%i')", 1];
const char *sql = (const char *) [strSQL UTF8String];
sqlite3_stmt *selectstmt;
if(sqlite3_prepare_v2(database, sql, -1, &selectstmt, NULL) == SQLITE_OK) {
while(sqlite3_step(selectstmt) == SQLITE_ROW) {
[self.dataArray addObject:[NSNumber numberWithInt:qlite3_column_int(selectstmt, 0)]];
[self.dataArray addObject:[NSString stringWithUTF8String:(char *)sqlite3_column_text(selectstmt, 1)]];
}
}
}
} else {
sqlite3_close(database); // Database not responding - close the database connection
}
}