gpt4 book ai didi

iphone - 不规则地获取sqlite3_prepare_v2中的Exc_Bad_Access

转载 作者:行者123 更新时间:2023-12-03 05:22:06 24 4
gpt4 key购买 nike

在插入 livecategories 之前,我会检查此 id 是否存在,如果不存在,则插入该值。但有时它会崩溃并获得 exc_bad_access。为什么我会得到这个?请参阅附图。

enter image description here

当我将鼠标悬停在 &statement 上时,它显示 0x000000:

enter image description here

最佳答案

检查下面的示例代码:

// Setup the database object
sqlite3 *database;

// Init the animals Array
animals = [[NSMutableArray alloc] init];

// Open the database from the users filessytem
if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {
// Setup the SQL Statement and compile it for faster access
const char *sqlStatement = "select * from animals";
sqlite3_stmt *compiledStatement;
if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {
// Loop through the results and add them to the feeds array
while(sqlite3_step(compiledStatement) == SQLITE_ROW) {
// Read the data from the result row
NSString *aName = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)];
NSString *aDescription = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 2)];
NSString *aImageUrl = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 3)];

// Create a new animal object with the data from the database
Animal *animal = [[Animal alloc] initWithName:aName description:aDescription url:aImageUrl];

// Add the animal object to the animals Array
[animals addObject:animal];

[animal release];
}
}
// Release the compiled statement from memory
sqlite3_finalize(compiledStatement);

}
sqlite3_close(database);

另一个Link寻求帮助。

希望它对你有用..

关于iphone - 不规则地获取sqlite3_prepare_v2中的Exc_Bad_Access,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13135794/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com