iphone sqlite问题:sqlite3_prepare_v2上的“内存不足”

时间:2022-06-01 16:41:52

I'm wondering if someone can help me understand what is wrong with this block of code. I never get past the sqlite3_prepare_v2 statement and the debugger says :

我想知道是否有人可以帮我理解这段代码有什么问题。我从未通过sqlite3_prepare_v2语句,调试器说:

'NSInternalInconsistencyException', reason: 'Error while creating add statement. 'out of memory''

'NSInternalInconsistencyException',原因:'创建add语句时出错。 '内存不足''

    static sqlite3 *database = nil;
sqlite3_stmt *addStmt = nil;

if(addStmt == nil) {
    NSLog(@"About to add start time...\n");
    const char *sql = "INSERT INTO games_played(start) VALUES(?)";     
    if(sqlite3_prepare_v2(database, sql, -1, &addStmt, NULL) != SQLITE_OK)
        NSAssert1(0, @"Error while creating add statement. '%s'", sqlite3_errmsg(database));
    NSLog(@"add statement created successfully!\n");
}
NSLog(@"About to bind start time...\n");
sqlite3_bind_text(addStmt, 1, @"start time", -1, SQLITE_TRANSIENT);

3 个解决方案

#1


26  

I never opened the database...I think thats the problem.

我从未打开数据库...我认为这就是问题所在。

#2


11  

It is not a bug, the problem is you never open the database. For example:

它不是一个bug,问题是你永远不会打开数据库。例如:

if (sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK)

#3


0  

I was also facing this problem, and solved it by reset the database for the sqlite statement.

我也遇到了这个问题,并通过重置sqlite语句的数据库来解决它。

#1


26  

I never opened the database...I think thats the problem.

我从未打开数据库...我认为这就是问题所在。

#2


11  

It is not a bug, the problem is you never open the database. For example:

它不是一个bug,问题是你永远不会打开数据库。例如:

if (sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK)

#3


0  

I was also facing this problem, and solved it by reset the database for the sqlite statement.

我也遇到了这个问题,并通过重置sqlite语句的数据库来解决它。