While Executing SQLITE with SELECT statement and having COUNT (*) to count the total number of that column, gives me EXC_BAD_ACCESS.
It sends me the error while adding an array from one array to other. No idea why it does that but has anybody come across such issues can help around ?
-(void) title{
self.array = [[[NSMutableArray alloc] init] autorelease];
const char *query_stmt = "SELECT DISTINCT ID, KEY, COUNT (*) FROM TEST GROUP BY KEY";
if (sqlite3_prepare_v2(database, query_stmt, -1, &statement, NULL) == SQLITE_OK)
{
while(sqlite3_step(statement) == SQLITE_ROW)
{
NSString *ID = [NSString stringWithUTF8String:(char *) sqlite3_column_text(exhProduct_statement, 0)];
NSString *KEY = [NSString stringWithUTF8String:(char *) sqlite3_column_text(exhProduct_statement, 1)];
NSUInteger taskCount= sqlite3_column_int(exhProduct_statement, 2);
NSMutableArray *taskArray=[[NSMutableArray alloc]initWithObjects:ID, KEY, taskCount,nil] ; <--- Error
[self.array addObject:taskArray];
}
sqlite3_finalize(statement);
}
}
You need to change the
NSUIntegerinto anNSNumber:You can later retrieve the value using
The reason for this is that an
NSArraystoresNSObjects, so any time that you have anint,float,NSInteger,NSUInteger, etc, that you wish to store in anNSArrayorNSMutableArray, you will need to convert it into an object.NSNumberis a class build just for this.