SQLite Cannot add more than 1000 lines

I am trying to add 10k rows to my SQLite database (with fmdb), but the record is stopped for 1000 rows. And I have no errors or warnings. My code is:

NSString *queryString = [NSString stringWithFormat:@"insert into histories (storyid, text, date, storyurl) values (%li, ?, ?, ?)",history.storyIndex]; if ([self.db open]) { if([self.db executeUpdate:queryString, history.storyText, history.storyDate, history.storyUrl]) { NSLog(@"history added"); } } 

Any suggestions?

+4
source share
4 answers

Can you try the following code and see if there are any changes:

 NSString *queryString = @"INSERT INTO histories (storyid, text, date, storyurl) VALUES ( ?, ?, ?, ?)"; BOOL executeUpdateStatus = NO; if ([self.db open]) { executeUpdateStatus = [self.db executeUpdate:queryString, [NSNumber numberWithLong:history.storyIndex], history.storyText, history.storyDate, history.storyUrl]; if(executeUpdateStatus == YES) NSLog(@"history added"); else NSLog(@"history NOT added"); } 
+1
source

For those who have the same problem ... make sure your sqlite viewer does not limit the output of your query to 1000 results.

Just lost a few minutes with the same problem and the answer was so simple!

+2
source

Put the database open outside the loop so that it is called only once. Re-accessing it from a loop of 10,000 lines can cause memory problems.

Check lastErrorCode on the db object after each executeUpdate and NSLog lastErrorMessage if it is not equal to zero.

Fix at intervals by increasing the counter and using module arithmetic, for example

 counter++; if (mod(counter,500) ){ [self.db commit]; } 

Consider using python to load the database outside of your iOS project.

+1
source

It looks like you need to complete a transaction. It looks like you have reached some limit on the number of rows in a single transaction.

0
source

Source: https://habr.com/ru/post/1442700/


All Articles