Reputation: 1560
I'm having a bit of trouble understanding why the below code is not working:
sqlite3_stmt *statement5;
NSString *databasePath2 = @"default-gameData.db";
NSInteger speed_int = 0;
const char *dbPath2 = [databasePath2 UTF8String];
if(sqlite3_open(dbPath2, &db)==SQLITE_OK){
NSString *getspeeds = @"SELECT * FROM planeInfo";
NSLog(@"%@",getspeeds);
const char *getspeed_stmt = [getspeeds UTF8String];
if(sqlite3_prepare_v2(db, getspeed_stmt, -1, &statement5, nil)==SQLITE_OK){
NSLog(@"%d",sqlite3_step(statement5));
NSString *org_plane_info_id = [[NSString alloc] init];
while(sqlite3_step(statement5) == SQLITE_ROW){
if((const char*)sqlite3_column_text(statement5, 1)==NULL){
org_plane_info_id = @"no";
}
else{
org_plane_info_id = [[NSString alloc] initWithUTF8String:(const char*)sqlite3_column_text(statement5, 1)];
}
NSLog(@"%@",org_plane_info_id);
if(org_plane_info_id==plane_info_id){
NSString *speed = [[NSString alloc] initWithUTF8String:(const char*)sqlite3_column_text(statement5, 2)];
NSLog(@"%@",speed);
speed_int = [speed integerValue];
return speed_int;
}
}
}
}
if(speed_int==0){
return 0;
}
sqlite3_close(db);
I've found the source of the problem being the database path, the file is stored where the .h and .m files are so I think that's where I am going wrong, but what do I have to do to get that to work?
Upvotes: 0
Views: 143
Reputation:
Cocoa/Foundation doesn't know where your file is. You need to tell it that it's in the app bundle.
NSString *databasePath2 = [[NSBundle mainBundle] pathForResource:@"default-gameData" ofType:@"db"];
Upvotes: 2