3
다음 코드는 오류로 호출되는 라이브러리 루틴을 제공하지만 오류는 어디에서 설명 할 수 있습니까? 어떤 아이디어?SQLite3 라이브러리 루틴이 시퀀스 외 호출되었습니다
- (BOOL)insertProduct:(Product *)product inOrder:(Order *)order withAmount:(int)amount
{
BOOL ok = NO;
sqlite3_stmt *statement;
const char *dbpath = [_databasePath UTF8String];
if (sqlite3_open(dbpath, &_database) == SQLITE_OK)
{
NSString * insertSQL;
int amount = [self getAmountForProduct:product inOrder:order];
NSLog(@"%i", amount);
if (amount != -1)
{
insertSQL = [NSString stringWithFormat: @"UPDATE ARTICOLIPERORDINE SET quantita = %i WHERE ordine = %i AND articolo = '%@'", amount, order.idOrdine, product.codice];
}
else
{
insertSQL = [NSString stringWithFormat: @"INSERT INTO ARTICOLIPERORDINE (ordine, articolo, quantita) VALUES(%i, '%@', %i)",order.idOrdine, product.codice, 1];
}
NSLog(@"%@", insertSQL);
const char *insert_stmt = [insertSQL UTF8String];
if (sqlite3_prepare_v2(_database, insert_stmt, -1, &statement, NULL) == SQLITE_OK)
{
if (sqlite3_step(statement) == SQLITE_DONE)
{
ok = YES;
}
else
{
ok = NO;
NSLog(@"sqlite3 ERROR %s: %@",sqlite3_errmsg(_database), insertSQL);
}
sqlite3_finalize(statement);
sqlite3_close(_database);
}
else
{
NSLog(@"Error prepare = %s", sqlite3_errmsg(_database));
}
}
return ok;
}
로그 인쇄 오류가 나는 한 가지 방법을 순서
'sqlite3_prepare_v2'를 (를) 호출하여 얻은 반환 값은 무엇입니까? – gaige
a BOOL ... question updated updated – Fry
실제로'sqlite3_prepare_v2'는 문서에 따라 성공하면'SQLITE_OK'를 반환하므로 위의 코드를 실행하면 실패하게됩니다. 먼저 step on을 실패라고 선언하고 ('SQLITE_OK'가 0), 두 번째로, 준비된 명령문에서'sqlite3_finalize'를 호출합니다. – gaige