I have function named: - (void) AddSortedCustomFeed :(NSMutableArray*) rssList;
this function adds items(Articles) from sqlite database to NSMutableArray
here how this function works:
- (void) AddSortedCustomFeed :(NSMutableArray*)rssList {
NSLog(@"\n\n\n ----- Add Sorted SQL Database -----");
NSLog(@"Start");
// Create Query String.
NSString* sqliteQuery = [NSString stringWithFormat:@"SELECT mainLink, title, summary, pubDate, author, imageLink, body, favorites, pubdatetime FROM ARTICLES WHERE customfeed = 'Y' ORDER BY pubdatetime DESC"];
NSLog(@"Query String is: %@", sqliteQuery);
// Pointer to Article and Statement.
Article* article;
sqlite3_stmt* statement;
// Prepare SQL for work.
if( sqlite3_prepare_v2(articlesDB, [sqliteQuery UTF8String], -1, &statement, NULL) == SQLITE_OK ) {
// Get next row from database.
while( sqlite3_step(statement) == SQLITE_ROW ) {
// Alloc and init article.
article = [[Article alloc] initWithValues:[NSString stringWithUTF8String:(const char*)sqlite3_column_text(statement, 1)]
mainLink:[NSString stringWithUTF8String:(const char*)sqlite3_column_text(statement, 0)]
summary:[NSString stringWithUTF8String:(const char*)sqlite3_column_text(statement, 2)]
pubDate:[NSString stringWithUTF8String:(const char*)sqlite3_column_text(statement, 3)]
author:[NSString stringWithUTF8String:(const char*)sqlite3_column_text(statement, 4)]
imageLink:[NSString stringWithUTF8String:(const char*)sqlite3_column_text(statement, 5)] ];
//article.body = [NSString stringWithUTF8String:(const char*)sqlite3_column_text(statement, 6)];
NSString* favo = [NSString stringWithUTF8String:(const char*)sqlite3_column_text(statement, 7)];
article.favorite = [favo hasPrefix:@"N"] ? NO : YES;
// Add to list.
[rssList addObject:article];
// Release article.
[article release];
}
}
else NSLog( @"SortSQLDatabase: Failed from sqlite3_prepare_v2. Error is: %s", sqlite3_errmsg(articlesDB) );
// Finalize and close database.
sqlite3_finalize(statement);
NSLog(@"End\n\n\n");
}
How you can see in this function I create article Article* article;
and in while loop alloc and initialize it. After that I add Article object to NSMutableArray
and then release it, but then I call [article release];
witch must call delloc function it doesn't calls ? I cant understand why. I try different ways but all my tries crashes. This is article about Article Class - link