in my program i have a database and two tables in it
my first function readLocationsFromDatabase
// Setup the database object
sqlite3 *database;
locations = [[NSMutableArray alloc] init];
// Open the database from the users filessytem
if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {
// Setup the SQL Statement and compile it for faster access
const char *sqlStatement = "select * from locations";
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) {
// Read the data from the result row
NSString *aName = [NSStringstringWithUTF8String:(char*)sqlite3_column_text(compiledStatement, 1)];
NSNumber *aLat = [NSNumber numberWithFloat:(float)sqlite3_column_double(compiledStatement, 2)];
NSNumber *aLon = [NSNumber numberWithFloat:(float)sqlite3_column_double(compiledStatement, 3)];
NSLog(@"NSInteger aLat : %@",aLat);
NSLog(@"NSInteger aLon : %@",aLon);
Location *location = [[Location alloc] initWithName:aName lat:aLat lon:aLon];
// Add the animal object to the animals Array
[locations addObject:location];
[location release];
}
}
// Release the compiled statement from memory
sqlite3_finalize(compiledStatement);
}
sqlite3_close(database);
works good no problems
i have a second function as readDirectoriesFromDatabase
// Setup the database object
sqlite3 *database2;
directories = [[NSMutableArray alloc] init];
if(sqlite3_open([databasePath UTF8String], &database2) == SQLITE_OK) {
NSLog(@"Test 2");
// Setup the SQL Statement and compile it for faster access
const char *sqlStatement2 = "select * from directory";
sqlite3_stmt *compiledStatement2;
if(sqlite3_prepare_v2(database2, sqlStatement2, -1, &compiledStatement2, NULL) == SQLITE_OK) {
NSLog(@"Test3");
// Loop through the results and add them to the feeds array
while(sqlite3_step(compiledStatement2) == SQLITE_ROW) {
NSLog(@"Test4");
// Read the data from the result row
NSString *aName = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement2, 1)];
NSString *aTel = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement2, 2)];
NSString *aUrl = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement2, 3)];
NSString *aMail = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement2, 4)];
NSString *aRoom = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement2, 5)];
NSLog(@"aName : ");
NSLog(@"aTel");
Directory *directory = [[Directory alloc] initWithName:aName telephone:aTel weburl:aUrl email:aMail roomno:aRoom];
[directories addObject:directory];
[directory release];
}
}
// Release the compiled statement from memory
sqlite3_finalize(compiledStatement2);
}
sqlite3_close(database2);
Gives no build errors but doesnt get inside if and prints Test3 neither gets inside while and prints test 4