My question is:
I have a Class PersonViewController
This Class access to a sqlite database through the method readFromDatabase,
this is the method readFromDatabase:
Code:
############################################
- (void) readDataFromDatabase{
sqlite3 *database;
persons = [[NSMutableArray alloc]init];
if (sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {
// Randon numbers (0, 1 y 3)
int r = arc4random() % 3;
NSLog(@"%i",r);
if (r==0) {
r=3;
}
NSString *s = [NSString stringWithFormat:@"SELECT * from person WHERE id = %i", r];
const char *sqlStatement = [s cStringUsingEncoding:NSASCIIStringEncoding];
//const char *sqlStatement = "SELECT * FROM person WHERE id=1";
sqlite3_stmt *compiledStatement;
if (sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {
while (sqlite3_step(compiledStatement) == SQLITE_ROW) {
NSInteger pID = sqlite3_column_int(compiledStatement, 0);
NSString *pName = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)];
NSInteger pAge = sqlite3_column_int(compiledStatement, 2);
Person *temp = [[Person alloc] initWhitID:pID name:pName andage:pAge];
//[consulta ]
[persons addObject:temp];
[temp release];
NSLog(@"ID: %i, Nombre: %@, Edad: %i",pID,pName,pAge);
}
}
sqlite3_finalize(compiledStatement);
}
sqlite3_close(database);
############################################
I need to pass result in the while of the method to another class.
when i try to pass it to another class i only see many numbers, i think that is a reference to the value, I think!
for example inside the while is possible to do this:
NSLog(@"Value: %@",pName);
but in another class is possible to see any value inside this method, but is not possible to see the value from the array, because only see many numbers.
Sorry for the question, I`m very very new in the OOP...
Thanks for all...