0

exc_bad_access code=2 を取得しています。エラーなしで動作する場合もありますが、エラーが発生する場合もあります。なぜこれが起こっているのかわかりません。誰かが何か問題を見つけたら教えてください ここに私のコードがあります..

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


                }
            }

前もって感謝します。

4

1 に答える 1

0

これを試してください:ループで複数の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-23T10:38:04.447 に答える