“没有这样的表格:游戏。常规适用于iPhone 5.1模拟器,但不适用于iPhone设备

时间:2013-02-23 08:16:17

标签: iphone

我在加载视图时遇到问题(请参阅下面的代码)。基本上,我正在从表中检索数据并将其显示在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;
}
}

0 个答案:

没有答案