I am stuck.
Is there any function which can import CSV records directly to sqlite table ?
Any help will be appreciable.
I am stuck. Is there any function which can import CSV records directly to
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Here is a rough code to do that. Please do some changes as per your requirement.
//Now start to process each single line.
if(messArr)
{
for(int i=0;i<=[messArr count]-1;i++)
{
NSMutableDictionary *d=[[NSMutableDictionary alloc] init];
NSString *StrValue=[NSString stringWithFormat:@"%@",[messArr objectAtIndex:i]];
StrValue=[StrValue stringByReplacingOccurrencesOfString:@"\"" withString:@""];
StrValue=[StrValue stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSArray *arr=[StrValue componentsSeparatedByString:@","];
/*Add value for each column into dictionary*/
[d setValue:[arr objectAtIndex:0] forKey:@"columnName"];
//Add this dictionary "d" into database
[d release]; //Cleanup.
}
}
[path1 release];
}
Please also refer the following question's answers. There is a nice explanation of creating your own custom CSV parser.
Load data from csv file (iphone SDk)
[How to import CSV data to sqlite dynamically in iphone application
[2]: How to import CSV data to sqlite dynamically in iphone application
I hope this will helps you.