Whats going to be the fastest way for me to insert 26,000 rows into a new sqlite3 table on the iphone?
My naive implementation was to create a file foo.sql looking like this:
BEGIN TRANSACTION;
CREATE TABLE user_db.places (
place_id integer primary key, -- cornell id less the leading L
lat real not null,
lng real not null,
name text not null,
country_code text not null,
admin1 text not null,
private integer not null);
INSERT INTO "places" VALUES(1,50.650002,-114.566666,'Windy Point',0,'CA','AB',0);
....
26k rows more
....
COMMIT;
and then running this code:
sql = [[[NSString alloc] initWithContentsOfFile:candidatePath
encoding:NSUTF8StringEncoding
error:NULL] autorelease];
if (sqlite3_exec(database,[sql UTF8String],NULL,NULL,&errorMsg) != SQLITE_OK) {
NSAssert1(0, @"Error loading update file: %s", errorMsg);
}
worked very poorly (35 seconds) probably because it was reading 2.8 MB of file into an NSString, then converting that string into a UTF8 string, and then doing it all at once.
(Hmm, this suggests a couple of improvements right off the bat... I think I'll go ahead and ask this and update it as I learn more.)