I am using FMDB to implement a SQLite based apps, which I need to insert a large amount of data into SQLite, say 1000 rows of data, but I dont want to insert them one by one, I just want to do this with a single query, this make the insert progress much faster, like this:
NSString *query = @"insert into table (c1,c2,c3,c4) values " ;
NSString *middle = @"" ;
for ( int i = 0 ; i < 1000 ; i++ ) {
NSDictionary *tmpItem = [data objectAtIndex:i] ;
if ( i == 999 ) {
middle = [NSString stringWithFormat:@"%@('%@','%@','%@','%@')", middle,[tmpItem objectForKey:@"c1"],[tmpItem objectForKey:@"c2"],[tmpItem objectForKey:@"c3"],[tmpItem objectForKey:@"c4"]] ;
}
else {
middle = [NSString stringWithFormat:@"%@('%@','%@','%@','%@') ,", middle,[tmpItem objectForKey:@"c1"],[tmpItem objectForKey:@"c2"],[tmpItem objectForKey:@"c3"],[tmpItem objectForKey:@"c4"]] ;
}
}
query = [NSString stringWithFormat:@"%@%@", query, middle] ;
[db executeUpdate:query];
Above code cannot insert any data on "table", but when I change the for-loop to run only 10 times, data inserted correctly, that means there is no syntax error.
I tried by error that, the data is inserted correctly with the for-loop set up to i<500, while setting i<501, no data is inserted.
Then I search http://www.sqlite.org/limits.html , there is a Maximum Depth Of An Expression Tree on this page, and it should be what I want to set, but how can I set this property while using FMDB?
Or the only method I can insert a large amount of data is just insert them one by one?