如何解决在FMDB中调用sqlite3_step(21:out of memory)rs的错误

时间:2022-08-14 23:02:26

i am using FMDB wrapper i used this code

我正在使用FMDB包装器我使用此代码

- (BOOL)update:(NSString *) Body fromValue:(NSString *)froms {

    BOOL success = NO;
    FMResultSet *rs;
//I have **searchTable** and in that folder name **OFFICE**  

    rs = [self.database executeQuery:@"select searchId,body from searchTable WHERE folder = 'OFFICE'"];


    NSInteger primaryKey = -1;
    NSString *body = nil;
    NSString *md5OfSearchEmailBody = nil;
    while ([rs next]) {
        primaryKey  = [rs intForColumn:@"searchId"];
        body = [rs stringForColumn:@"body"];
    }           

    [rs close];
    return success;
}

first time

- (BOOL)update:(NSString *) Body fromValue:(NSString *)froms{
}

method working fine. in the loop second time it's not working

方法工作正常。在循环第二次它不工作

Error calling sqlite3_step (21: out of memory) rs

调用sqlite3_step(21:内存不足)rs时出错

how to solve this problem

如何解决这个问题呢

5 个解决方案

#1


5  

Check for the [rs close];

检查[rs close];

May be it is releasing or closing the DB.

可能是发布或关闭数据库。

===================================================

Better use CoreData to implement sqlite in your application.

更好地使用CoreData在您的应用程序中实现sqlite。

Why to use external library, when a better internal library is available in the Application. You don't need to remove your sqlite table. You can easily migrate your existing database to CoreData.

当应用程序中有更好的内部库时,为什么要使用外部库。您不需要删除sqlite表。您可以轻松地将现有数据库迁移到CoreData。

#2


3  

I was getting same error because call [database close] before call [resultSet next].

因为在调用[resultSet next]之前调用[数据库关闭],我得到了相同的错误。

FMDatabase *db;

[db open];

FMResultSet *set = [db executeQuery:@"some select"];

[db close];

while ([set next])
{
    // get Error calling sqlite3_step (21: out of memory) rs
}

[set close];

Should call [database close] after call [resultSet next]

应该在调用[resultSet next]后调用[database close]

FMDatabase *db;

[db open];

FMResultSet *set = [db executeQuery:@"some select"];

while ([set next])
{
    // no error
}

[set close];
[db close];

#3


0  

i was getting out of memory even after [rs close]; so i used :

即使在[rs close]之后我也会失去记忆;所以我用过:

while ([rs next]) {
        @autoreleasepool
        { 
          //stuff like......[rs stringForColumn:@"category_id"];...
        }
                 } 
       [rs close];

i solved my mory growth as well as out of memory error.

我解决了我的mory增长以及内存不足的错误。

Thanks

#4


0  

I was facing the same error. So basically I had two functions, say func1() and func2().

我面临同样的错误。所以基本上我有两个函数,比如func1()和func2()。

In func1() I was doing the following:

在func1()中,我正在执行以下操作:

1.) Generating the result set. 2.) Printing the result( To Test) 3.) Calling func2() with the result set as an argument.

1.)生成结果集。 2.)打印结果(To Test)3。)使用结果集作为参数调用func2()。

In func2(), I was facing the error while I was trying to iterate through the result set received from func1().

在func2()中,当我试图迭代从func1()接收的结果集时,我遇到了错误。

When I removed the code in func1() (Step 2), the error was gone!

当我删除func1()中的代码(步骤2)时,错误消失了!

#5


0  

To resolve the out of memory issue, I had to set my code like below to check at the end of the loop if loop == LocationCount then break the loop. If I left it out it would [rs next] which would then give me the Error calling sqlite3_step (21: out of memory) rs. I would recommend to do something similar so [rs next] doesn't so more than what required for your function.

要解决内存不足的问题,我必须设置我的代码,如下所示,在循环结束时检查loop == LocationCount然后打破循环。如果我把它遗漏了它会[rs next]然后会给我错误调用sqlite3_step(21:out of memory)rs。我建议做类似的事情,所以[rs next]并不比你的功能所需的更多。

int loop = 0;
while ([rs next])
    {
         // additional code here
        loop = loop + 1;
        if (loop == LoopMaxCount) {
                break;
         } else {
                [rs next];
         }
     }

#1


5  

Check for the [rs close];

检查[rs close];

May be it is releasing or closing the DB.

可能是发布或关闭数据库。

===================================================

Better use CoreData to implement sqlite in your application.

更好地使用CoreData在您的应用程序中实现sqlite。

Why to use external library, when a better internal library is available in the Application. You don't need to remove your sqlite table. You can easily migrate your existing database to CoreData.

当应用程序中有更好的内部库时,为什么要使用外部库。您不需要删除sqlite表。您可以轻松地将现有数据库迁移到CoreData。

#2


3  

I was getting same error because call [database close] before call [resultSet next].

因为在调用[resultSet next]之前调用[数据库关闭],我得到了相同的错误。

FMDatabase *db;

[db open];

FMResultSet *set = [db executeQuery:@"some select"];

[db close];

while ([set next])
{
    // get Error calling sqlite3_step (21: out of memory) rs
}

[set close];

Should call [database close] after call [resultSet next]

应该在调用[resultSet next]后调用[database close]

FMDatabase *db;

[db open];

FMResultSet *set = [db executeQuery:@"some select"];

while ([set next])
{
    // no error
}

[set close];
[db close];

#3


0  

i was getting out of memory even after [rs close]; so i used :

即使在[rs close]之后我也会失去记忆;所以我用过:

while ([rs next]) {
        @autoreleasepool
        { 
          //stuff like......[rs stringForColumn:@"category_id"];...
        }
                 } 
       [rs close];

i solved my mory growth as well as out of memory error.

我解决了我的mory增长以及内存不足的错误。

Thanks

#4


0  

I was facing the same error. So basically I had two functions, say func1() and func2().

我面临同样的错误。所以基本上我有两个函数,比如func1()和func2()。

In func1() I was doing the following:

在func1()中,我正在执行以下操作:

1.) Generating the result set. 2.) Printing the result( To Test) 3.) Calling func2() with the result set as an argument.

1.)生成结果集。 2.)打印结果(To Test)3。)使用结果集作为参数调用func2()。

In func2(), I was facing the error while I was trying to iterate through the result set received from func1().

在func2()中,当我试图迭代从func1()接收的结果集时,我遇到了错误。

When I removed the code in func1() (Step 2), the error was gone!

当我删除func1()中的代码(步骤2)时,错误消失了!

#5


0  

To resolve the out of memory issue, I had to set my code like below to check at the end of the loop if loop == LocationCount then break the loop. If I left it out it would [rs next] which would then give me the Error calling sqlite3_step (21: out of memory) rs. I would recommend to do something similar so [rs next] doesn't so more than what required for your function.

要解决内存不足的问题,我必须设置我的代码,如下所示,在循环结束时检查loop == LocationCount然后打破循环。如果我把它遗漏了它会[rs next]然后会给我错误调用sqlite3_step(21:out of memory)rs。我建议做类似的事情,所以[rs next]并不比你的功能所需的更多。

int loop = 0;
while ([rs next])
    {
         // additional code here
        loop = loop + 1;
        if (loop == LoopMaxCount) {
                break;
         } else {
                [rs next];
         }
     }