Question

Friends I Used FMDB and it is working very well, but i tryed to select single row but it is gives me an error

this is code

FMResultSet *fResult= [db executeQuery:@"SELECT * FROM contents WHERE id = 1"];
[fResult next];
NSLog(@"%@",[fResult stringForColumn:@"title"]);

Thank you

Was it helpful?

Solution

You should check your results. For example:

FMResultSet *rs = [db executeQuery:@"SELECT * FROM contents WHERE id = 1"];

if (!rs) {
    NSLog(@"%s: executeQuery failed: %@", __FUNCTION__, [db lastErrorMessage]);
    return;
}

if ([rs next]) {
    NSString *title = [rs stringForColumn:@"title"];
    NSLog(@"title = %@", title);
} else {
    NSLog(@"%s: No record found", __FUNCTION__);
}

[rs close];

You are flying blind if you don't (a) check the executeQuery return code; and (b) if it failed, examine lastErrorMessage so you know why it didn't work.

OTHER TIPS

Can you try this ?

NSString *databasePath = [[NSBundle mainBundle] pathForResource:DBName ofType:@"sqlite"];
FMDatabase *db = [FMDatabase databaseWithPath:databasePath];

if (![db open]) {
    return;
}

FMDatabaseQueue *queue = [FMDatabaseQueue databaseQueueWithPath:databasePath];

[queue inDatabase:^(FMDatabase *db) {

    FMResultSet *results = [db executeQuery:@"SELECT * FROM TableName"];

    while ([results next]) {

        NSString *str = [results stringForColumn:@"your_column_name"];
    }
    [results close];
}];

[db close];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top