我在加载视图时遇到问题(请参阅下面的代码)。基本上,我从表中检索数据并将其显示在 iPhone 屏幕上。
iPhone 5.1 模拟器有效,但是,我在设备上收到消息
“准备语句的问题:没有这样的表:游戏”
谁能给我一点方向?
提前感谢您的时间和评论。
这是代码:
-(NSMutableArray *) gameList{
thegames = [[NSMutableArray alloc] initWithCapacity:5];
@try {
NSDate* date = [NSDate date];
NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"MM/dd/yyyy"];
[formatter setDateFormat:@"MMdd"];
NSString* str1 = [formatter stringFromDate:date];
[toDaysDate setText:str1];
NSFileManager *fileMgr = [NSFileManager defaultManager];
NSString *docsDir;
NSArray *dirPaths;
dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
docsDir = [dirPaths objectAtIndex:0];
NSString *dbPath = [[NSString alloc]initWithString: [docsDir stringByAppendingPathComponent:@"sportretortdatab2.sqlite"]];
BOOL success = [fileMgr fileExistsAtPath:dbPath];
if(!success)
{
NSLog(@"Cannot locate database file '%@'.", dbPath);
}
if(!(sqlite3_open([dbPath UTF8String], &db) == SQLITE_OK))
{
NSLog(@"An error has occured: %s", sqlite3_errmsg(db));
}
const char* GamesSQLString(NSString* str1);
NSString* sql= [NSString stringWithFormat:@"SELECT * FROM Games WHERE SeqNo= \"5\" AND GameDate < \"%@\"", str1];
sqlite3_stmt *sqlStatement;
// THIS IS WERE I GET THE ERROR - THIS STATEMENT WORKS ON iPhone Simulator 5.1, NOT on iPhone device ///////
if(sqlite3_prepare_v2(db, [sql cStringUsingEncoding:NSASCIIStringEncoding], -1, &sqlStatement, NULL) != SQLITE_OK)
////////////////////////////////////////////////////////////////////////////////////////
{
NSLog(@"Problem with prepare statement: %s", sqlite3_errmsg(db));
}else{
while (sqlite3_step(sqlStatement)==SQLITE_ROW) {
Game * game = [[Game alloc] init];
game.GameDate = [NSString stringWithUTF8String:(char *) sqlite3_column_text(sqlStatement,1)];
game.Completed = [NSString stringWithUTF8String:(char *) sqlite3_column_text(sqlStatement,13)];
if ([game.Completed isEqualToString:@"N"]) {
NSString * strRR = [NSString stringWithFormat:@"%@%@", game.GameDate, @" - Open"];
game.GameDate = strRR;}
else {
NSString * strRR = [NSString stringWithFormat:@"%@%@", game.GameDate, @" - Completed"];
game.GameDate = strRR;}
[thegames addObject:game ];
}
}
}
@catch (NSException *exception) {
NSLog(@"Problem with prepare statement: %s", sqlite3_errmsg(db));
}
@finally {
sqlite3_close(db);
return thegames;
}
}