Objective c 另一个EXC\u坏访问
我修复了上一个问题的错误,但我的代码引发了另一个EXC\u BAD\u访问 在 完整的代码是Objective c 另一个EXC\u坏访问,objective-c,xcode,ipad,ios,Objective C,Xcode,Ipad,Ios,我修复了上一个问题的错误,但我的代码引发了另一个EXC\u BAD\u访问 在 完整的代码是 sqlite3 *database; // Setup some globals NSString *databaseName = @"test.sql"; // Get the path to the documents directory and append the databaseName NSArray *documentPaths = NSSearchPathForDirectoriesI
sqlite3 *database;
// Setup some globals
NSString *databaseName = @"test.sql";
// Get the path to the documents directory and append the databaseName
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [documentPaths objectAtIndex:0];
NSString * databasePath = [documentsDir stringByAppendingPathComponent:databaseName];
[databasePath retain];
sqlite3_stmt *compiledStatement;
NSString * TheNewText = self.animalDesciption.text;
[TheNewText retain];
NSString * the_user = AnimalName ;
[ the_user retain];
NSString *NewData = [NSString stringWithFormat:@"%@%@%@%@", @"Update animals set description = ",TheNewText , " Where name = ",the_user];
[NewData retain] ;
if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {
const char *sqlStatement = [NewData UTF8String];
if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL)== SQLITE_OK) {
sqlite3_reset(sqlStatement);
}
我敢打赌字符串是通过自动释放运行收集的。在文档中查找UTF8String,他们建议复制该字符串以确保其持续时间超过该点 经过深思熟虑后,我真正的建议是去掉对垫脚石变量的赋值 我想说,像这样使用它:
if(sqlite3_prepare_v2(database, [NewData UTF8String], -1, &compiledStatement, NULL)== SQLITE_OK) {
sqlite3_reset(compiledStatement);
注意重置语句中的更改。这可能是您真正的问题,您的代码试图执行一个字符串而不是一个准备好的sqlite语句。您是否尝试过alloc和init NSString
NSString *NewData = [[NSString alloc] initWithFormat:@"%@%@%@%@", @"Update animals set description = ",TheNewText , " Where name = ",the_user];
不要留着吗?请给我更多的插图好吗
NSString *NewData = [[NSString alloc] initWithFormat:@"%@%@%@%@", @"Update animals set description = ",TheNewText , " Where name = ",the_user];