sqlite3_finalize がよくわかりません。私の初期コード。
while (j < Autors.count)
{
if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK)
{
sqlite3_bind_int(compiledStatement, 1, ((AuthorSettings *)[Autors objectAtIndex:j]).authorId);
if(sqlite3_step(compiledStatement) != SQLITE_DONE)
{
NSLog(@"sqlite3_step error %s", sqlite3_errmsg(database));
sqlite3_busy_timeout(database, 5);
}
else
{
if(sqlite3_prepare_v2(database, sqlStatement_1, -1, &compiledStatement, NULL) == SQLITE_OK)
{
sqlite3_bind_int(compiledStatement, 1, bookId);
if(sqlite3_step(compiledStatement) != SQLITE_DONE)
{
NSLog(@"sqlite3_step error %s", sqlite3_errmsg(database));
sqlite3_busy_timeout(database, 5);
}
else j++;
}
else NSLog(@"sqlite3_prepare_v2 error %s", sqlite3_errmsg(database));
}
}
}
sqlite3_finalize(compiledStatement);
sqlite3_finalize 関数を追加しました。私をチェックしてください。
while (j < Autors.count)
{
sqlite3_finalize(compiledStatement); //**added
if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK)
{
sqlite3_bind_int(compiledStatement, 1, ((AuthorSettings *)[Autors objectAtIndex:j]).authorId);
if(sqlite3_step(compiledStatement) != SQLITE_DONE)
{
NSLog(@"sqlite3_step error %s", sqlite3_errmsg(database));
sqlite3_busy_timeout(database, 5);
}
else
{
sqlite3_finalize(compiledStatement); //**added
if(sqlite3_prepare_v2(database, sqlStatement_1, -1, &compiledStatement, NULL) == SQLITE_OK)
{
sqlite3_bind_int(compiledStatement, 1, bookId);
if(sqlite3_step(compiledStatement) != SQLITE_DONE)
{
NSLog(@"sqlite3_step error %s", sqlite3_errmsg(database));
sqlite3_busy_timeout(database, 5);
}
else j++;
}
else NSLog(@"sqlite3_prepare_v2 error %s", sqlite3_errmsg(database));
}
}
}
sqlite3_finalize(compiledStatement);