vendredi 2 janvier 2015

Database could not open after insert some contact from PhoneBook in Objective-c

Database Could not able to open after insert few record from iPhone Contact and application UI irresponsive and crash



-(BOOL)InsertUserBirtdayInfo:(UserBirthDayInfo*) objBirthDayInfo
{
isOperationCompleted=NO;
@try
{
if ( sqlite3_open_v2([databasePath UTF8String], &calledDB, SQLITE_OPEN_READWRITE, NULL) == SQLITE_OK)
{
statementInsert = nil;

NSString *insert=[NSString stringWithFormat:@"INSERT INTO %@ (%@, %@ ,%@, %@ ,%@ ,%@ , %@ , %@ ,%@ ,%@ ,%@, %@,%@) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?)",_Table,_Name,_Phone,_UserImage,_Birthday_Day,_Birthday_Month,_Birthday_Year,_isDisplayOnCalender,_isMessageDefault,_Default_Message,_Custom_Message,_isAutoPost,_isTextMessage,_isFacebook];
const char *qryInsert = [insert UTF8String];
if (sqlite3_prepare_v2(calledDB, qryInsert, -1, &statementInsert, NULL) != SQLITE_OK)
{
NSAssert1(0, @"Error: failed to prepare statement with message '%s'.", sqlite3_errmsg(calledDB));
}else{

sqlite3_bind_text(statementInsert, 1, [objBirthDayInfo.Name UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(statementInsert, 2, [objBirthDayInfo.Phone UTF8String], -1, SQLITE_TRANSIENT);

NSData *dataForImage = objBirthDayInfo.User_Image;
sqlite3_bind_blob(statementInsert,3, [dataForImage bytes],(int) [dataForImage length], SQLITE_TRANSIENT);

sqlite3_bind_int(statementInsert,4, objBirthDayInfo.BirthDay_Day.intValue);
sqlite3_bind_int(statementInsert,5, objBirthDayInfo.BirthDay_Month.intValue);
sqlite3_bind_int(statementInsert,6, objBirthDayInfo.BirthDay_Year.intValue);

sqlite3_bind_int(statementInsert,7,(int) objBirthDayInfo.isDisplayCalender);
sqlite3_bind_int(statementInsert,8,(int)objBirthDayInfo.isMessageDefault);

sqlite3_bind_text(statementInsert,9, [objBirthDayInfo.defaultMessage UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(statementInsert,10, [objBirthDayInfo.customMessage UTF8String], -1, SQLITE_TRANSIENT);
// sqlite3_bind_int(statementInsert,11,(int) objBirthDayInfo.isNotification);
sqlite3_bind_int(statementInsert, 12,(int) objBirthDayInfo.isAutoPost);
sqlite3_bind_int(statementInsert, 13,(int) objBirthDayInfo.isTextMessage);
sqlite3_bind_int(statementInsert, 14,(int) objBirthDayInfo.isFacebook);

if(sqlite3_step(statementInsert)==SQLITE_DONE)
{
isOperationCompleted=YES;
NSLog(@"User birthdate information inserted successfully on database!");

}

else
{

NSLog(@"Failed to Insert User birthdate information!");
}

}

}

else
{
NSLog(@"Insert Record");

NSLog(@"Failed to open database with error %s", sqlite3_errmsg(calledDB));
}

}


@catch (NSException *exception)
{
isOperationCompleted=NO;
NSLog(@"%@",exception);
}
@finally
{
sqlite3_reset(statementInsert);
sqlite3_close(calledDB);
}
return isOperationCompleted;
}

Aucun commentaire:

Enregistrer un commentaire