exc_bad_access代码= 2地址= 0x1000003c为sqlite汇编语句
问题描述:
我越来越exc_bad_access代码= 2。有些时候它的作品没有错误,但有时它会给出错误。我不知道为什么会发生这种情况。如果有人发现有任何问题请让我知道 这里是我的代码..提前exc_bad_access代码= 2地址= 0x1000003c为sqlite汇编语句
if (sqlite3_open(dbpath, &adhDB) == SQLITE_OK)
{
sqlite3_stmt *compiledStatement;
const char *sqlStatement = "INSERT INTO tblNotifications (NotificationID,Description,BeforeHrs,AfterHrs,PreparationID,PreparationName,ProcedureID,ProcedureName,ClientID,IsActive,UpdatedDateTime) VALUES (?,?,?,?,?,?,?,?,?,?,?)"; // Total 11 ?
NSLog(@"sqlStatement = %s",sqlStatement);
if(sqlite3_prepare_v2(adhDB, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK)
{
int i = 0;
for (statusNotification in nsNotification)
{
NSString *NotificationID1 =[statusNotification objectForKey:@"NotificationID"];
NotificationID1 = [NotificationID1 stringByTrimmingCharactersInSet:
[NSCharacterSet whitespaceCharacterSet]];
NSString *Description1 = [statusNotification objectForKey:@"Description"];
Description1 = [Description1 stringByTrimmingCharactersInSet:
[NSCharacterSet whitespaceCharacterSet]];
NSString *BeforeHrs1 = [statusNotification objectForKey:@"BeforeHrs"];
BeforeHrs1 = [BeforeHrs1 stringByTrimmingCharactersInSet:
[NSCharacterSet whitespaceCharacterSet]];
NSString *AfterHrs1 = [statusNotification objectForKey:@"AfterHrs"];
AfterHrs1 = [AfterHrs1 stringByTrimmingCharactersInSet:
[NSCharacterSet whitespaceCharacterSet]];
NSString *PreparationID1 =[statusNotification objectForKey:@"PreparationID"];
PreparationID1 = [PreparationID1 stringByTrimmingCharactersInSet:
[NSCharacterSet whitespaceCharacterSet]];
NSString *PreparationName1 =[statusNotification objectForKey:@"PreparationName"];
PreparationName1 = [PreparationName1 stringByTrimmingCharactersInSet:
[NSCharacterSet whitespaceCharacterSet]];
NSString *ProcedureID1 =[statusNotification objectForKey:@"ProcedureID"];
ProcedureID1 = [ProcedureID1 stringByTrimmingCharactersInSet:
[NSCharacterSet whitespaceCharacterSet]];
NSString *ProcedureName1 =[statusNotification objectForKey:@"ProcedureName"];
ProcedureName1 = [ProcedureName1 stringByTrimmingCharactersInSet:
[NSCharacterSet whitespaceCharacterSet]];
NSString *ClientID1 =[statusNotification objectForKey:@"ClientID"];
ClientID1 = [ClientID1 stringByTrimmingCharactersInSet:
[NSCharacterSet whitespaceCharacterSet]];
NSString *IsActive1 =[statusNotification objectForKey:@"IsActive"];
IsActive1 = [IsActive1 stringByTrimmingCharactersInSet:
[NSCharacterSet whitespaceCharacterSet]];
NSString *UpdatedDateTime1 = [HomeScreen returnDateTime];
sqlite3_bind_text(compiledStatement, 1, [NotificationID1 UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(compiledStatement, 2, [Description1 UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(compiledStatement, 3, [BeforeHrs1 UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(compiledStatement, 4, [AfterHrs1 UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(compiledStatement, 5, [PreparationID1 UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(compiledStatement, 6, [PreparationName1 UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(compiledStatement, 7, [ProcedureID1 UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(compiledStatement, 8, [ProcedureName1 UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(compiledStatement, 9, [ClientID1 UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(compiledStatement, 10, [IsActive1 UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(compiledStatement, 11, [UpdatedDateTime1 UTF8String], -1, SQLITE_TRANSIENT);
// NSLog(@"UpdatedDateTime= %@",UpdatedDateTime1);
if (sqlite3_step(compiledStatement) == SQLITE_DONE) {
if (i == cntProcedures)
sqlite3_finalize(compiledStatement);
else
sqlite3_reset(compiledStatement);
}
else {
}
i++;
}
}
}
感谢。
答
试试这个:我认为多了一个sql语句在循环中被触发,现在我们使用函数进行触发,并且每次创建新的编译语句...所以它不会崩溃。
for (statusNotification in nsNotification)
{
NSString *NotificationID1 =[statusNotification objectForKey:@"NotificationID"];
NotificationID1 = [NotificationID1 stringByTrimmingCharactersInSet:
[NSCharacterSet whitespaceCharacterSet]];
NSString *Description1 = [statusNotification objectForKey:@"Description"];
Description1 = [Description1 stringByTrimmingCharactersInSet:
[NSCharacterSet whitespaceCharacterSet]];
NSString *BeforeHrs1 = [statusNotification objectForKey:@"BeforeHrs"];
BeforeHrs1 = [BeforeHrs1 stringByTrimmingCharactersInSet:
[NSCharacterSet whitespaceCharacterSet]];
NSString *AfterHrs1 = [statusNotification objectForKey:@"AfterHrs"];
AfterHrs1 = [AfterHrs1 stringByTrimmingCharactersInSet:
[NSCharacterSet whitespaceCharacterSet]];
NSString *PreparationID1 =[statusNotification objectForKey:@"PreparationID"];
PreparationID1 = [PreparationID1 stringByTrimmingCharactersInSet:
[NSCharacterSet whitespaceCharacterSet]];
NSString *PreparationName1 =[statusNotification objectForKey:@"PreparationName"];
PreparationName1 = [PreparationName1 stringByTrimmingCharactersInSet:
[NSCharacterSet whitespaceCharacterSet]];
NSString *ProcedureID1 =[statusNotification objectForKey:@"ProcedureID"];
ProcedureID1 = [ProcedureID1 stringByTrimmingCharactersInSet:
[NSCharacterSet whitespaceCharacterSet]];
NSString *ProcedureName1 =[statusNotification objectForKey:@"ProcedureName"];
ProcedureName1 = [ProcedureName1 stringByTrimmingCharactersInSet:
[NSCharacterSet whitespaceCharacterSet]];
NSString *ClientID1 =[statusNotification objectForKey:@"ClientID"];
ClientID1 = [ClientID1 stringByTrimmingCharactersInSet:
[NSCharacterSet whitespaceCharacterSet]];
NSString *IsActive1 =[statusNotification objectForKey:@"IsActive"];
IsActive1 = [IsActive1 stringByTrimmingCharactersInSet:
[NSCharacterSet whitespaceCharacterSet]];
NSString *UpdatedDateTime1 = [HomeScreen returnDateTime];
[self insertTblNotification:NotificationID1 :Description1 :BeforeHrs1 :AfterHrs1 :PreparationID1 :PreparationName1 :ProcedureID1 :ProcedureName1 :ClientID1 :IsActive1 :UpdatedDateTime1]
}
-(void)insertTblNotification :(NSString *) NotificationID:(NSString *) Description:(NSString *) BeforeHrs:(NSString *) AfterHrs:(NSString *) PreparationID:(NSString *) PreparationName:(NSString *) ProcedureID:(NSString *) ProcedureName:(NSString *) ClientID:(NSString *) IsActive:(NSString *) UpdatedDateTime
{
const char *insertSql;
insertSql = nil;
sqlite3_stmt *compiledStatement;
compiledStatement = nil;
if(compiledStatement == nil)
{
insertSql ="INSERT INTO tblNotifications (NotificationID,Description,BeforeHrs,AfterHrs,PreparationID,PreparationName,ProcedureID,ProcedureName,ClientID,IsActive,UpdatedDateTime) VALUES (?,?,?,?,?,?,?,?,?,?,?)"; // Total 11 ?
if(sqlite3_prepare_v2(adhDB, insertSql, -1, &compiledStatement, NULL) != SQLITE_OK){
NSAssert1(0, @"Error: failed to prepare insert statement with message '%s'.", sqlite3_errmsg(appDelegate.objDBAdapter.database));
}
sqlite3_bind_text(compiledStatement, 1, [NotificationID1 UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(compiledStatement, 2, [Description1 UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(compiledStatement, 3, [BeforeHrs1 UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(compiledStatement, 4, [AfterHrs1 UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(compiledStatement, 5, [PreparationID1 UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(compiledStatement, 6, [PreparationName1 UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(compiledStatement, 7, [ProcedureID1 UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(compiledStatement, 8, [ProcedureName1 UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(compiledStatement, 9, [ClientID1 UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(compiledStatement, 10, [IsActive1 UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(compiledStatement, 11, [UpdatedDateTime1 UTF8String], -1, SQLITE_TRANSIENT);
// NSLog(@"UpdatedDateTime= %@",UpdatedDateTime1);
if(sqlite3_step(compiledStatement) != SQLITE_DONE)
{
NSAssert1(0, @"Error: failed to insert into the database with message '%s'.", sqlite3_errmsg(adhDB));
return;
}
sqlite3_reset(compiledStatement);
}
}
在哪一行崩溃?把断点和逐步调试.. – 2013-04-23 07:36:22
有时它崩溃在第二编译语句,有时它在第六编译语句崩溃。我试图插入10条记录..有些时间8个记录插入数据库,然后崩溃。 – Rahul 2013-04-23 08:41:05
显示上述条件的代码 – 2013-04-23 09:38:08