i have 10 csv(.csv) files with more records, and these files i m trying to add local DB like SQlte database, and here i used
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[[DBManager getSharedInstance] loadCSVData];
dispatch_async(dispatch_get_main_queue(), ^{
//Update UI
});
});
-(void)loadCSVData{
NSLog(@"%lu",(unsigned long)arrDictList.count);
for (int i=0; i<arrDictList.count; i++) {
NSString *strDictrictName = [NSString stringWithFormat:@"%@",[arrDictList objectAtIndex:i]];
NSLog(@"%@",strDictrictName);
NSString *path = [[NSBundle mainBundle] pathForResource:strDictrictName ofType:@"csv"];
NSString *fileDataString=[NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
NSArray *districtArr=[fileDataString componentsSeparatedByString:@"\n"];
NSLog(@"%lu",(unsigned long)districtArr.count);
if(districtArr)
{
for(int j=1;j<[districtArr count]-1;j++)
{
NSString *StrValue=[NSString stringWithFormat:@"%@",[districtArr objectAtIndex:j]];
StrValue=[StrValue stringByReplacingOccurrencesOfString:@"\"" withString:@""];
StrValue=[StrValue stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
//Here give whatever saperator you need to saperate data
NSArray *arr=[StrValue componentsSeparatedByString:@","];
NSString *insertStmt = [NSString stringWithFormat: @"INSERT INTO %@ (id,villiage_name) values(\"%@\",\"%@\")",[arrDictList objectAtIndex:i],[arr objectAtIndex:0],[arr objectAtIndex:1]];
//Here add logic to insert row in your database table
[self executeQuery:insertStmt];
}
}
}
}
Note: here problem is only first 5 csv file records only added (reading remaining 5 csv files data not reading, its just display null, data correct (like if i used to read single file its fyn to work)) to local DB, remaining 5 showing null. (i think maybe its thread (time delay) issue).
Aucun commentaire:
Enregistrer un commentaire