I’m getting error to store array value in database. My last array value is stored in database. I thought the counter was proper. Where in this code did I do wrong? I’m creating a counter in the database to store array values.
i got this error message Save Error: library routine called out of sequence
on this line ############
-(BOOL)Add
{
NSString *filePath = [BaseModal getDBPath];
NSLog(@"this check:%@",filePath);
sqlite3 *database;
if(sqlite3_open([filePath UTF8String], &database) == SQLITE_OK) {
const char *sqlStatement = "insert into Name(name,Date,CDate,Attach form,data) VALUES (?,?,?,?,?)";
sqlite3_stmt *compiledStatement;
if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK)
{
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"dd/MM/yyyy"];
NSString* date = [dateFormat stringFromDate:Date];
NSString* cdate = [dateFormat stringFromDate:Cdate];
sqlite3_bind_text( compiledStatement, 1, [name UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(compiledStatement, 2, [date UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(compiledStatement, 3, [cdate UTF8String], -1, SQLITE_TRANSIENT);
//sqlite3_bind_text( compiledStatement, 4, [UDate UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_int(compiledStatement, 4, Attach form);
sqlite3_bind_text( compiledStatement, 5, [data UTF8String], -1, SQLITE_TRANSIENT);
//sqlite3_bind_int(compiledStatement, 6, i);
}
if(sqlite3_step(compiledStatement) != SQLITE_DONE ) {
NSLog( @"Save Error: %s", sqlite3_errmsg(database));
sqlite3_finalize(compiledStatement);
sqlite3_close(database);
return FALSE;
}
else {
TaskId=sqlite3_last_insert_rowid(database);
sqlite3_reset(compiledStatement);
//sqlite3_finalize(compiledStatement);
//now insert into name table
const char *sqlStatement3 = "insert into TeaInfo(TitleId,TeaId) VALUES (?,?)";
sqlite3_stmt *compiledStatement3;
if(sqlite3_prepare_v2(database, sqlStatement3, -1, &compiledStatement3, NULL) == SQLITE_OK) {
sqlite3_bind_int(compiledStatement3, 1, TitleId);
for(int counter=0;counter<[self.Tea count];counter++)//***************************
{
Teaclass *teaInfo=(Teaclass*)[self.Teas objectAtIndex:counter];
sqlite3_bind_int( compiledStatement3, 2, teaInfo. TeaId);
}
if(sqlite3_step(compiledStatement3) != SQLITE_DONE )//#############
{
NSLog( @"Save Error: %s", sqlite3_errmsg(database) );
//return FALSE;
}
//}
}
return TRUE;
}
}
return TRUE;
}
Solved problem in
if(sqlite3_prepare_v2(database, sqlStatement3, -1, &compiledStatement3, NULL) == SQLITE_OK)this line I have to write in for loop then row is inserted properly.