0

I'm using the FMDB with the sqlite library in the iOS framework and having a problem where a query to the db gets no results, while if I run the same query from my Database Browser it brings me the expected results.

this is the code for fetching the data (works with hash and timestamp):

NSMutableArray* classes = [NSMutableArray array];
NSArray* args;
NSString* sqlQuery = @"SELECT * FROM " T_DATA " WHERE " F_QUERY_HASH "=? AND " F_QUERY_TIMESTAMP ">? AND " F_QUERY_DATA_TYPE "=?";
args = [NSArray arrayWithObjects:[NSNumber numberWithInteger:[query hash]], [NSDate dateWithTimeIntervalSinceNow:(-QUERY_VALIDITY_TIME)], [NSNumber numberWithInt:QueryDataTypeClasses],nil];
__block BOOL found = NO;
[self inDatabase:^(FMDatabase *db) {
    FMResultSet* res = [db executeQuery:sqlQuery withArgumentsInArray:args];
    if ([res next]) {//should not be more than one result
        found = YES;
        NSData* classesData = [res dataForColumn:F_QUERY_DATA];
        [classes addObjectsFromArray:[dataParser classesFromData:classesData query:query]];
    }
}];

when I print out the sql query and run it on my database, it returns results, but the code doesn't. This is not consistent but happening all the time. I would be happy for any pointers..
Thanks
Ayala

  • I assume that you've logged the resulting `sqlQuery` and the `args` array and confirmed the values look good? I assume you also confirmed that `res` was non-`nil`? If it's `nil`, you should examine `lastErrorMessage`. It's going to be hard for us to diagnose this remotely without seeing the database, the SQL, the values for the array, etc. I'd try taking out those WHERE clauses one by one and see if one of them is filtering out results incorrectly. – Rob Sep 15 '13 at 21:23
  • ok! solved. It was the FMDB cache ruining the whole thing. see https://github.com/ccgus/fmdb/issues/6. – user2730555 Sep 17 '13 at 12:22

0 Answers0