2012-08-14 65 views
0

我開發一個應用程序,我需要在sqlite數據庫中插入大量的數據。這些數據被正確地插入,但問題是,有時我得到一個異常iPhone Sqlite插件在nsthread上運行


Assertion failure in -[AttendeeDetails addData:anddbpath:], /Users/abhisheknaidu/Desktop/EventApp/AttendeeDetails.m:118 
2012-08-14 11:54:24.937 EventApp[3586:1770b] 

*Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Error while creating add statement. 'SQL logic error or missing database''

這只是發生了一些時間..

可以anyoneone這裏幫助我在這..

即時通訊使用下面的代碼插入

- (void) addData:(NSMutableArray *)attendeeArray anddbpath:(NSString *)dbPath{ 

    NSString *str = @"Not Available"; 
    if(addStmt == nil) { 
      if (sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK) { 

     const char *sql = "insert into AttendeeDetails(AtQRid , EventId , ImageUrl , FirstName , LastName , Company , Email , PhoneNumber , City , State , ATBarcodeID) Values(?,?,?,?,?,?,?,?,?,?,?)"; 
     if(sqlite3_prepare_v2(database, sql, -1, &addStmt, NULL) != SQLITE_OK) 
      NSAssert1(0, @"Error while creating add statement. '%s'", sqlite3_errmsg(database)); 
     } 
     sqlite3_bind_text(addStmt, 1, [[attendeeArray valueForKey:@"Attendee_QR_ID"] UTF8String], -1, SQLITE_TRANSIENT); 
     sqlite3_bind_text(addStmt, 2, [[[[AppDelegate SharedInstance].DetailsOfEventArray valueForKey:@"Event_ID"] objectAtIndex:0] UTF8String], -1, SQLITE_TRANSIENT); 
     if ([attendeeArray valueForKey:@"Image_URL"] == [NSNull null]) { 
      sqlite3_bind_text(addStmt, 3, [str UTF8String], -1, SQLITE_TRANSIENT); 
     } 
     else { 
      sqlite3_bind_text(addStmt, 3, [[attendeeArray valueForKey:@"Image_URL"] UTF8String], -1, SQLITE_TRANSIENT); 
     } 
     sqlite3_bind_text(addStmt, 4, [[attendeeArray valueForKey:@"FirstName"] UTF8String], -1, SQLITE_TRANSIENT); 
     sqlite3_bind_text(addStmt, 5, [[attendeeArray valueForKey:@"LastName"] UTF8String], -1, SQLITE_TRANSIENT); 
     if ([attendeeArray valueForKey:@"Company"] == [NSNull null]) { 
      sqlite3_bind_text(addStmt, 6, [str UTF8String], -1, SQLITE_TRANSIENT); 
     } 
     else { 
      sqlite3_bind_text(addStmt, 6, [[attendeeArray valueForKey:@"Company"] UTF8String], -1, SQLITE_TRANSIENT); 
     } 

     if ([attendeeArray valueForKey:@"Email"] == [NSNull null]) { 
      sqlite3_bind_text(addStmt, 7, [str UTF8String], -1, SQLITE_TRANSIENT); 
     } 
     else { 
      sqlite3_bind_text(addStmt, 7, [[attendeeArray valueForKey:@"Email"] UTF8String], -1, SQLITE_TRANSIENT); 
     } 

     if ([attendeeArray valueForKey:@"PhoneNo"] == [NSNull null]) { 
      sqlite3_bind_text(addStmt, 8, [str UTF8String], -1, SQLITE_TRANSIENT); 
     } 
     else { 
      sqlite3_bind_text(addStmt, 8, [[attendeeArray valueForKey:@"PhoneNo"] UTF8String], -1, SQLITE_TRANSIENT); 
     } 


     if ([attendeeArray valueForKey:@"City"] == [NSNull null]) { 
      sqlite3_bind_text(addStmt, 9, [str UTF8String], -1, SQLITE_TRANSIENT); 
     } 
     else { 
      sqlite3_bind_text(addStmt, 9, [[attendeeArray valueForKey:@"City"] UTF8String], -1, SQLITE_TRANSIENT); 
     } 

     if ([attendeeArray valueForKey:@"State"] == [NSNull null]) { 
      sqlite3_bind_text(addStmt, 10, [str UTF8String], -1, SQLITE_TRANSIENT); 
     } 
     else { 
      sqlite3_bind_text(addStmt, 10, [[attendeeArray valueForKey:@"State"] UTF8String], -1, SQLITE_TRANSIENT); 
     } 

     if ([attendeeArray valueForKey:@"State"] == [NSNull null]) { 
      sqlite3_bind_text(addStmt, 10, [str UTF8String], -1, SQLITE_TRANSIENT); 
     } 
     else { 
      sqlite3_bind_text(addStmt, 10, [[attendeeArray valueForKey:@"State"] UTF8String], -1, SQLITE_TRANSIENT); 
     } 


     if ([attendeeArray valueForKey:@"State"] == [NSNull null]) { 
      sqlite3_bind_text(addStmt, 11, [str UTF8String], -1, SQLITE_TRANSIENT); 
     } 
     else { 
      sqlite3_bind_text(addStmt, 11, [[attendeeArray valueForKey:@"State"] UTF8String], -1, SQLITE_TRANSIENT); 
     } 

     if(SQLITE_DONE != sqlite3_step(addStmt)) 
      NSAssert1(0, @"Error while inserting data. '%s'", sqlite3_errmsg(database)); 
     else 
      //SQLite provides a method to get the last primary key inserted by using sqlite3_last_insert_rowid 
      coffeeID = sqlite3_last_insert_rowid(database); 

     //Reset the add statement. 
     sqlite3_reset(addStmt); 
    } 
    addStmt = nil; 

} 

在此先感謝

回答

0

我認爲你可以使用調度隊列

dispatch_queue_t concurrentQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); 

    dispatch_async(concurrentQueue, ^{ 
     //this will call when you inserting in bg 


     dispatch_async(dispatch_get_main_queue(), ^{ 
      //this will call when inserting is finished 
     }); 
    }); 
+0

@ankur我仍然得到同樣的異常如 ***在斷言失敗 - [AttendeeDetails addData:anddbpath:] ,/Users/abhisheknaidu/Desktop/EventApp/AttendeeDetails.m:118 2012-08-14 12:46:25.771 EventApp [1020:1a03] ***終止應用程序,由於未捕獲的異常'NSInternalInconsistencyException',原因:'錯誤while創建添加語句。 'SQL logic error or missing database'' 即時通訊使用此功能 – user1597244 2012-08-14 07:18:25