我有這個奇怪的錯誤,我在查詢我的表'兒童'與一個相當複雜的查詢。它工作正常,但由於某種原因它錯誤地從更新數據庫的另一種觀點。你會看到這個數據庫擁有不乾膠標籤,一個簡單的方法就是訪問這個管理頁面,這是它的bug。我可以查詢信息好,但!當我更新表時它討厭並且不起作用。但是它在覈心視圖控制器中的奇怪現象,當我在那裏更新表時,它並沒有問題。我縮小代碼這個問題的原因:sqlite3 IOS查詢竊聽表
-(void)leaderboardsystem
{
NSString *nexttargetsql = [NSString stringWithFormat:@"SELECT * FROM Children WHERE Completed > %d OR (Completed = %d AND Current_Stickers > %d) ORDER BY Completed ASC, Current_Stickers ASC LIMIT 1",completecount,completecount,stickercount]; //Queries table for the childs name and returns more data.
NSString *behindyousql = [NSString stringWithFormat:@"SELECT * FROM Children WHERE Completed < %d OR (Completed = %d AND Current_Stickers < %d) ORDER BY Completed DESC, Current_Stickers DESC LIMIT 1",completecount,completecount,stickercount];
nexttarget.text = [self leaderboardQuery:nexttargetsql];
behindyou.text = [self leaderboardQuery:behindyousql];
}
-(NSString*)leaderboardQuery:(NSString*)sql//does the querying
{
sqlite3_stmt *statement;
if (sqlite3_prepare_v2(Childdb, [sql UTF8String], -1, &statement, nil)==SQLITE_OK) {
while (sqlite3_step(statement)==SQLITE_ROW) {
char *ffield1 = (char *) sqlite3_column_text(statement, 0);
NSString *ffield1Str = [[NSString alloc]initWithUTF8String:ffield1];
char *ffield2 = (char *) sqlite3_column_text(statement, 8);
NSString *ffield2Str = [[NSString alloc]initWithUTF8String:ffield2];
char *ffield3 = (char *) sqlite3_column_text(statement, 10);
NSString *ffield3Str = [[NSString alloc]initWithUTF8String:ffield3];
NSLog(@"Name:%@",ffield1Str);
NSLog(@"this is completecount: %@", ffield2Str);
NSLog(@"this is stickcount: %@",ffield3Str);
return ffield1Str;
}
}
return NULL;
}
每當我調用該方法leaderboardsystem它會導致這個錯誤,但如果我不那麼它工作正常!有趣的是,我有點驚訝說實話。這令我感到驚訝,因爲它會影響與主視圖無關的完全不同的視圖控制器。該表的佈局是:
[self createTable:@"Children" withField1:@"Name" withField2:@"Password" withField3:@"House" withField4:@"Sticker Collection" withField5:@"Tickets Gathered" withField6:@"Tickets Removed" withField7:@"Last Ticket Scanned" withField8:@"Current Tickets" withField9:@"Completed" withField10:@"Complete" withField11:@"Current_Stickers"];
這是更新代碼,似乎當我包括在主視圖中的排行榜系統(這是一個完全不同的視圖控制器上)
-(void)UpdateDatabase//update table, if value has been incremented
{
NSString *sql = [NSString stringWithFormat:@"UPDATE Children SET 'Current Tickets' = %d, 'Tickets Removed' = %d, 'Tickets Gathered' = %d WHERE Name = '%@'",[self.currenttickets.text integerValue], [self.removedtickets.text integerValue], [self.totaltickets.text integerValue], name];
[self updatetable:sql];
}
-(void)updatetable:(NSString*)sql
{
char *err;
if (sqlite3_exec(Childdb, [sql UTF8String], NULL, NULL, &err)!=SQLITE_OK) {
sqlite3_close(Childdb);
NSAssert(0, @"Could not update Table");
} else {
NSLog(@"Table updated");
}
}
I」失敗如果你需要更多的信息讓我知道,我不想讓這裏的描述超載並保持簡短我的程序非常大。但我保證排行榜系統正在導致問題。如果你能解決這個問題,感謝一百萬人,一整天都在努力! :(
此外,它也擾亂了那裏我將記錄添加到表的地方,所以更新的代碼不會導致它。它是領先的查詢,不知道爲什麼:(