サーバーからアプリにロードしてデータベースに挿入する5000を超えるレコードがあります。挿入が成功した後にこれらのレコードを挿入しているときに、この種のエラーが発生し、アプリがクラッシュします。
iPhoneでデータベースの形式が正しくない+エラーディスクi/oエラー
以下は、役立つ可能性のあるコードスニペットです。ここでは、5つのカテゴリのレコードを1つずつ取得し、データベースに挿入しています。
if (tag==1) {
NSMutableDictionary *catDic=[dic valueForKeyPath:@"GetAllRecords.results.categories.category"];
[self performSelectorInBackground:@selector(insertDataInCategoryMaster:) withObject:catDic];
NSMutableDictionary *levelDic=[dic valueForKeyPath:@"GetAllRecords.results.levels.level"];
[self performSelectorInBackground:@selector(insertDataInLevelMaster:) withObject:levelDic];
NSMutableDictionary *queDic=[dic valueForKeyPath:@"GetAllRecords.results.questions.question"];
[self performSelectorInBackground:@selector(insertDataInQueMaster:) withObject:queDic];
[self getQueCatLevelData:2];
}
else if(tag==2){
NSMutableDictionary *queDic=[dic valueForKeyPath:@"GetAllRecords.results.questions.question"];
[self performSelectorInBackground:@selector(insertDataInQueMaster:) withObject:queDic];
[self getQueCatLevelData:3];
}
else if(tag==3){
NSMutableDictionary *queDic=[dic valueForKeyPath:@"GetAllRecords.results.questions.question"];
[self performSelectorInBackground:@selector(insertDataInQueMaster:) withObject:queDic];
[self getQueCatLevelData:4];
}//and so on for 5 also
各insertDataInQueMasterで、私は次のことを行っています。
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];
for(NSDictionary *queDictionary in dictionary)
{
NSString *strQuery = [NSString stringWithFormat:@"insert into QuestionMaster values(%d,'%@','%@',%d,%d,%d,%d,%d,0,'%@')",[[queDictionary valueForKey:@"questionid"]intValue], [queDictionary valueForKey:@"questiontext"],[queDictionary valueForKey:@"answertext"],[[queDictionary valueForKey:@"categoryid"]intValue],[[queDictionary valueForKey:@"levelid"] intValue],[[queDictionary valueForKey:@"status"]intValue],[[queDictionary valueForKey:@"RangeFrom"]intValue],[[queDictionary valueForKey:@"RangeTo"]intValue],[queDictionary valueForKey:@"Fact"]];
[NSNumber requestWithSynchronousExcuteQuery:strQuery withReturnningError:&error];
if(error)
{
NSLog(@"error description:%@",[[error userInfo] description]);
[[NSUserDefaults standardUserDefaults]setBool:NO forKey:@"FirstTime"];
}
}
count++;
[[NSUserDefaults standardUserDefaults]setInteger:count forKey:@"CheckCount"];
[[NSUserDefaults standardUserDefaults]synchronize];
[pool drain];
私はアプリがAppDelegate.mにロードされている間にこれらすべてのことを行っていますが、これもバックグラウンドでエラーが発生しますデータベースにいくつかのレコードを正常に挿入した後、データベースを開いて挿入することに問題はないと思います。
はっきりしているといいのですが、混乱があればコメントしてください。返事を待っています。前もって感謝します。