Am i doing this right, because the array is returning a count of 0.
-(NSArray *)getAllFavourites{
NSMutableArray *arrFavourites = [[NSMutableArray alloc] init];
NSString *query = @"SELECT * FROM tbl_favourites;";
sqlite3_stmt *statement;
if (sqlite3_prepare_v2(database, [query UTF8String], -1, &statement, nil) == SQLITE_OK){
while (sqlite3_step(statement) == SQLITE_ROW ){
char *charSymbols = (char *) sqlite3_column_text(statement, 0);
NSString *strFetchedSymbol = [[NSString alloc] initWithUTF8String:charSymbols];
DBClassFavourites *dbClassFav = [[DBClassFavourites alloc] initWithString:strFetchedSymbol];
[arrFavourites addObject:dbClassFav];
}
sqlite3_finalize(statement);
}
NSLog(@"%i",[arrFavourites count]);
return arrFavourites;
}
I also have this class which initialises the variables needed.
@implementation DBClassFavourites
-(id) initWithString:(NSString *)symbol
{
self = [super init];
if (self) {
self.strSymbol = symbol;
}
return self;
}
-(void) dealloc
{
[strSymbol release];
[super dealloc];
}
This is where it all gets called, from my firstviewcontroller init function
@implementation FirstViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
arrFavourites = [[DatabaseManager database] getAllFavourites];
}
You should try to use FMDB wrapper
To find an error in your code you need to post whole database initialization method