Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jul 6, 2012, 07:15 AM   #1
Narendar Singh
macrumors member
 
Join Date: Jun 2012
Location: INDIA
Send a message via Skype™ to Narendar Singh
How to convert SQLite schema to CSV format?

I have few rows in SQLite schema, I want to mail this data in CSV format from my iOS application.

How can I achieve this?

FYI my schema has following columns:
name | dob | mobile_number
Narendar Singh is offline   0 Reply With Quote
Old Jul 6, 2012, 03:01 PM   #2
CodeBreaker
macrumors 6502
 
Join Date: Nov 2010
Location: Sea of Tranquility
A dumb way would be to have three arrays, one for each column.

You have to write a SQL query for each column in the table.

Then you can easily create the CSV string:

Code:
NSString *csvString = @"name, dob, mobile_number";
for (int i = 0; i < totalRows; i++) {
    csvString = [csvString stringByAppendingString:[NSString stringWithFromat:@"\n%@, %@, %@", [names objectAtIndex:i], [dobs objectAtIndex:i], [mobile_numbers objectAtIndex:i]]];
}
__________________
.
CodeBreaker is offline   0 Reply With Quote
Old Jul 6, 2012, 06:55 PM   #3
chown33
macrumors 601
 
Join Date: Aug 2009
There is an NSArray method that returns all an array's components joined by a given string. If the array held one complete row, and the string is a comma, you'll get CSV (or the simple-minded version of it). The method is componentsJoinedByString:.

"Simple-minded" means it won't account for quotes or commas in a component string. So if one of the strings in the array was @"Oops, it broke", then you'd end up with a comma where it shouldn't be.

As with many things in programming, a better CSV generator can be built up from smaller simpler parts. If the OP isn't interested in doing that, then like many things in programming, a little searching can often find someone else's code. For example, google search terms: CSV objective-C or cocoa csv
chown33 is offline   0 Reply With Quote
Old Jul 15, 2012, 11:05 AM   #4
Narendar Singh
Thread Starter
macrumors member
 
Join Date: Jun 2012
Location: INDIA
Send a message via Skype™ to Narendar Singh
Thanks, make sense....
Narendar Singh is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 12:05 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

Privacy / DMCA contact / Affiliate and FTC Disclosure
Copyright 2002-2013, MacRumors.com, LLC