SQLite的。 不能添加超过1000行

我试图添加到我的SQLite数据库(与FMDB)10K行,但写入停止在1000行。 我没有任何错误或警告。 我的代码:

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"); } } 

有什么build议么?

你可以尝试下面的代码,看看是否有任何改变:

 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"); } 

对于任何人有同样的问题…确保您的SQLite查看器不限制您的查询输出到1000结果。

只是丢了几分钟的同样的问题,答案很简单!

数据库打开到循环之外,这样它就被称为一次。 在10,000行的循环内重复调用它可能会导致内存问题。

在每个executeUpdate之后检查db对象上的lastErrorCode,如果不为零,则检查lastErrorMessage。

通过递增计数器并使用模数algorithm来间隔提交,例如

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

考虑使用python批量加载iOS项目之外的数据库。

听起来像你需要提交你的交易。 看起来您已经达到了单个事务中的行数的一些限制。