繁体   English   中英

SQLite的。 无法添加超过1000行

[英]SQLite. Can't add more than 1000 rows

我正在尝试添加到我的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");
    } 
}

有什么建议?

对于有相同问题的任何人...确保您的sqlite查看器不会将查询的输出限制为1000个结果。

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

数据库放在循环外部,以便只调用一次。 在10,000行的循环内重复调用它可能会导致内存问题。

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

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

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

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

您可以尝试以下代码,看看是否有任何变化:

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

听起来你需要提交你的交易。 您似乎已达到单个事务中的行数限制。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM