【发布时间】:2010-02-27 13:33:59
【问题描述】:
我的游戏中有一张高分表。游戏结束后,分数会显示在屏幕上,并会被插入到高分表中。我想知道如何将新分数与表中的最高分数进行比较,以便让用户知道他们是否获得了高分。下面我包含了用于更新分数并将其插入表中的代码。保留的分数是一个整数 globalScore。
-(void)updateScores:(NSInteger)Primary_key
{
sqlite3_stmt *statement=nil;
NSString *sql=nil;
@try
{
statement=nil;
sql=nil;
sql=[NSString stringWithFormat:@"update tblHard set Score=? where id=%d",Primary_key];
if(sqlite3_prepare_v2(database, [sql UTF8String], -1, &statement, NULL)!=SQLITE_OK)
{
NSAssert1(0, @"Error: failed to prepare statement with message '%s'.", sqlite3_errmsg(database));
}
sqlite3_bind_int(statement, 1, globalScore);
int success=sqlite3_step(statement);
if (success == SQLITE_ERROR) {
NSAssert1(0, @"Error: failed to insert into the database with message '%s'.", sqlite3_errmsg(database));
}
sqlite3_finalize(statement);
statement=nil;
sql=nil;
}
@catch (NSException *e)
{
NSLog(@"asd");
}
}
-(int)InsertGame
{
int i=0;
sqlite3_stmt *statement=nil;
NSString *sql=nil;
@try
{
statement=nil;
sql=nil;
sql=[NSString stringWithFormat:@"insert into tblHard(Score) values (?)"];
if(sqlite3_prepare_v2(database, [sql UTF8String], -1, &statement, NULL)!=SQLITE_OK)
{
NSAssert1(0, @"Error: failed to prepare statement with message '%s'.", sqlite3_errmsg(database));
}
sqlite3_bind_int(statement, 1, globalScore);
int success=sqlite3_step(statement);
if (success == SQLITE_ERROR) {
NSAssert1(0, @"Error: failed to insert into the database with message '%s'.", sqlite3_errmsg(database));
}
i= sqlite3_last_insert_rowid(database);
sqlite3_finalize(statement);
statement=nil;
sql=nil;
}
@catch (NSException *e)
{
NSLog(@"asd");
}
return i;
}
所以我要找的是这样的东西......
if(globalScore > "the highest score in the table"){
highscorelabel.hidden=NO;
}
【问题讨论】:
标签: ios iphone sqlite sdk compare