应用程序崩溃并显示此错误消息(Exc_bad_access(code = 1,address = 0x208))。 应用程序停止并显示错误的行是最后一行(var result)。 这是代码:
// 1. Get the name and the path for DB
self.DBName = @"PhonePager.db";
NSArray * documentsPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString * documentDir = [documentsPaths objectAtIndex:0];
self.DBPath = [documentDir stringByAppendingPathComponent:self.DBName];
const char * dbpath = [self.DBPath UTF8String];
// 2. Open database
if (sqlite3_open(dbpath, &contactDB) == SQLITE_OK)
{
// 3. Create requests ( fill the table messages received )
NSString * statementGetDataFromDB = [NSString stringWithFormat:@"SELECT id_message, date, time, ack_required, auto_ack_sent, message, titre, idfrom FROM messages m WHERE NOT EXISTS(SELECT id_message FROM responses r WHERE r.id_message = m.id_message) ORDER BY date DESC, time DESC"];
const char * sql_stmt_getDataFromDB = [statementGetDataFromDB UTF8String];
// 4. Execute request
sqlite3_stmt * sqlStatement;
int result = sqlite3_prepare_v2(contactDB, sql_stmt_getDataFromDB, -1, &sqlStatement, nil);
你有什么建议吗?提前致谢
答案 0 :(得分:0)
据我所知,你正在尝试向c函数发送一个目标c指针(nil)。在这一行;
int result = sqlite3_prepare_v2(contactDB, sql_stmt_getDataFromDB, -1, &sqlStatement, nil);
试试这个;
int result = sqlite3_prepare_v2(contactDB, sql_stmt_getDataFromDB, -1, &sqlStatement, NULL);