EXC_BAD_ACCESS错误

时间:2011-02-21 08:32:32

标签: xcode ipad

我有uitextview(self.animalDesciption)的应用程序和按钮

我使用按钮使用uitextview中的文本更新数据库 但它总是在行

处给出EXC_BAD_ACCESS

NSString * NewData = [NSString stringWithFormat:@“%@%@%@%@”,@“Update animals set description =”,TheNewText,“Where name =”,the_user];

完整的代码是

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

请提出任何建议

祝你好运

2 个答案:

答案 0 :(得分:1)

您在字符串“Where name =”之前缺少“@” 尝试:

NSString *NewData = [NSString stringWithFormat:@"%@%@%@%@", @"Update animals set description = ",TheNewText , @" Where name =  ",the_user];

答案 1 :(得分:0)

尝试:

NSString *NewData = [NSString stringWithFormat:@"%@%@%@%@", @"Update animals set description = ",TheNewText , @" Where name = ",the_user];

请注意@“Where name =”