下面的代码给了我一个称为乱序错误的库例程,但我无法解释问题出在哪里。有任何想法吗 ?
- (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;
}
日志打印错误准备 = 库例程调用乱序