mercredi 31 décembre 2014

inserting into SQLLite database

I am very much new to Sqlite operation, Till now I was operating only to UI + some Web service


What I am facing issue is that,


I am creating a table from Terminal and inserting values in it from Xcode by matching the table name. The table consist for 4 fields, out of which 2 belongs to table and 2 are foreign keys.


When even I insert the Query my app FREEZES at that point.


It doesn't move further, not allowing any operations.


Here is my query



FMDatabase* db=[SqlLiteDAOFactory createConnection];

for(int i=0;i<[matchQesA count];i++)
{
MTQuestionDTO *mTQuestionDTO =[matchQesA objectAtIndex:i];

NSLog(@"value of testsample id is :- %@",questionDTO.testsampledid);
NSLog(@"value of sampletest id is :- %@",questionDTO.sampletestid);
NSLog(@"value of MTQ Question id :- %@",mTQuestionDTO.mtq_question_id);
NSLog(@"value of MTQ Question Text :- %@",mTQuestionDTO.mtq_question_text);

[db executeUpdate:@"insert into matchquestion (testsampledID,sampletestid,mtq_question_id,mtq_question_text) values(?,?,?,?)",questionDTO.testsampledid,questionDTO.sampletestid,mTQuestionDTO.mtq_question_id,mTQuestionDTO.mtq_question_text];

if ([db hadError])
{
NSLog(@"database error before");
NSLog(@"Err in inserting %d: %@", [db lastErrorCode], [db lastErrorMessage]);
[db close];
}
}

[db close];
return TRUE;


When I NSlog the values, it gives me proper values. Also when I fire the same query from Terminal value get inserted into database.


I am firing this Query to my Array count. I am having total Array, and want to insert the elements into table till array count.


Why my app is FREEZING, if its error then It must go in Error block, its not going there, So I am facing difficulties to track it.


What a mistake I made.


Thanks in advance.


Aucun commentaire:

Enregistrer un commentaire