I am developing one application. In that iam using the NSMutableArray for storing the database data. After getting the data from database into this array. I am performing the search operation on that data. In that time everytime that array returns last object only. But at the time of retrieving the data from database it retrives different data. So please tell me how to solve this one. Part of my code is shown below.
-(void)searchData
{
list=[db getlanguages];
for(for i=0;i<[list count];i++) {
databasefields *dbfield = [list objectAtIndex:i];
NSLog(@"%@",dbfield.lang);
}
}
In this code list is the NSMutableArray.I will assign the memory for that one. And st the property for that one.
and code for [db getlanguages] is below.
-(NSMutableArray*)getlanguages
{
NSString *query = [NSString stringWithFormat:@"SELECT * FROM A"];
sqlite3_stmt *stStatement;
NSMutableArray *getdata = [[NSMutableArray alloc]init];
if(sqlite3_prepare_v2(dbfile, [query UTF8String], -1, &stStatement, nil)==SQLITE_OK)
{
databasefields *dbfields=[[databasefields alloc]init];
while (sqlite3_step(stStatement)==SQLITE_ROW)
{
dbfields.num=sqlite3_column_int(stStatement, 0);
dbfields.lang=[NSString stringWithUTF8String:(char*)sqlite3_column_text(stStatement, 1)];
[getdata addObject:dbfields];
[dbfields release];
}
if (stStatement!= nil) {
sqlite3_finalize(stStatement);
}
}
sqlite3_close(dbfile);
return getdata;
}
Modify the following line
to
and try.
Edit
You are using a single object and that you are releasing that too..
Make your statements as follows: