Im trying to fetch a column of senderId's from my messages table and then store them in an array. However my while loop is not functioning correctly:
('senderIds' is an NSMutableArray declared in the header file.)
-(void)fetchsenderIds {
const char *dbpath = [_databasePath UTF8String];
sqlite3_stmt *statement;
if (sqlite3_open(dbpath, &_messagesDB) == SQLITE_OK)
{
NSString *querySQL = [NSString stringWithFormat:
@"SELECT senderId FROM messages"];
const char *query_stmt = [querySQL UTF8String];
if (sqlite3_prepare_v2(_messagesDB,
query_stmt, -1, &statement, NULL) == SQLITE_OK)
{
//Loop through the results and add them to the array
while(sqlite3_step(statement) == SQLITE_ROW)
{
// Init the Data Dictionary
NSMutableDictionary *dataDictionary2=[[NSMutableDictionary alloc] init];
NSString *recordModified = [[NSString alloc] initWithUTF8String:(const char *)sqlite3_column_text(statement, 0)];
[dataDictionary2 setObject:[NSString stringWithFormat:@"%@", recordModified] forKey:@"senderId"];
[self.senderIds addObject: dataDictionary2];
NSLog(@"self.senderIds = %@", self.senderIds);
}
sqlite3_finalize(statement);
}
sqlite3_close(_messagesDB);
}
}
Aucun commentaire:
Enregistrer un commentaire