Take the 2-minute tour ×

I'm trying to add to my SQLite database (with fmdb) 10k rows but writing is stopped on 1000 row. And I have no any errors or warnings. My code:

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?

share|improve this question
OMG! A lowercase SQL query! –  user529758 Oct 29 '12 at 9:11
The world is going to end!!! –  0x7fffffff Oct 29 '12 at 9:13
... with a mixture of printf-formatting and bind variables?!? –  trojanfoe Oct 29 '12 at 9:13
@RomanHouse don't worry, it's fine. You just don't have enough experience with stuff yet to understand the punchline :) –  user529758 Oct 29 '12 at 9:49
@H2CO3 ok, I will be use uppercase queries and become professional at once :D –  RomanHouse Oct 29 '12 at 10:02
show 5 more comments

4 Answers

up vote 1 down vote accepted

Can you try the following code and see if there is any change:

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");
            NSLog(@"history NOT added");
share|improve this answer
You should only open your database only once, and don't forget to use [self.db commit]; –  Ravi Raman Oct 29 '12 at 12:21
add comment

Put the database open outside of the loop, so that it is called just the once. Calling it repeatedly inside the loop of 10,000 rows might be causing memory problems.

Check for lastErrorCode on the db object after each executeUpdate and NSLog the lastErrorMessage if it is non zero.

Commit at intervals by incrementing a counter and using modulus arithmetic, e.g.

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

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

share|improve this answer
add comment

For anyone with the same problem... make sure your sqlite viewer is not limiting the output of your query to 1000 results.

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

share|improve this answer
Old question, but you are right :) –  RomanHouse Jul 12 '13 at 16:18
add comment

Sounds like you need to commit your transactions. It appears that you have reached some limit on the amount of rows in a single transaction.

share|improve this answer
I already trying to commit each of transactions but it isn't help –  RomanHouse Oct 29 '12 at 9:49
add comment

Your Answer


