views:

104

answers:

3

hello,

i have a table. and 3 record.

and i have that code;

-(void) readScoreFromDatabase {

sqlite3 *database;


scores = [[NSMutableArray alloc] init];


if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {

 const char *sqlStatement = "select name,score from game";
 sqlite3_stmt *compiledStatement;
 if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {



  // Loop through the results and add them to the feeds array
  while(sqlite3_step(compiledStatement) == SQLITE_ROW) {
  //if(sqlite3_step(compiledStatement) == SQLITE_ROW) {
   // Read the data from the result row

   NSString *aName =[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 0)];
   NSString *aScore =[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)];


   DatabaseClass *dbOBJ = [[DatabaseClass alloc] initWithName:aName score:aScore];


   [scores addObject:dbOBJ];

   [dbOBJ release];
  } 
 }

 sqlite3_finalize(compiledStatement);

} else {
 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"No Connection" 
               delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
 [alert show];
}
sqlite3_close(database);

}

and iam using that code for show records;

-(IBAction)refreshClick:(id)sender {

// Navigation logic -- create and push a new view controller
IDRGameAppDelegate *appDelegate = (IDRGameAppDelegate *)[[UIApplication sharedApplication] delegate];
DatabaseClass *dbOBJ = (DatabaseClass *)[appDelegate.scores objectAtIndex:1];

game1NameLabel.text = dbOBJ.name;
score1Label.text = dbOBJ.score;

}

i have 3 record but i can take only one record. i mean changed that line "DatabaseClass *dbOBJ = (DatabaseClass *)[appDelegate.scores objectAtIndex:1];"
objectAtIndex:1 when i change this value 1 or 2 or 3 etc. result dont change. always showing one record from 3 record. i dont understand reason.

Thank you. and i am sory for my bad english.

A: 

May be you fogot to set score to your delegate?

scores = [[NSMutableArray alloc] init];
....
((IDRGameAppDelegate *)[[UIApplication sharedApplication] delegate]).score = score;    //I don't see this in your code
oxigen
A: 

This is'nt the answer you want, but you should really consider using Core Data now that it's in iPhone OS 3.0. It handles most of this for you and is very easyt o use.

Dan Lorenc
A: 

HI,

  1. Are you able to see the table rows, when you go to the SQite manager(From Firefox) and run the below query

    select name,score from game;

    If you are able to see 3 records.

    a. Then the possible answer is go to the IPhone simulator and do a Reset settings (Which will clear all the temp caches database and build files)

    b. Go to xcode and do a BUild and GO.

    Hope this will get you latest database and put it to the Build folder

Anand