gpt4 book ai didi

ios - 乱序调用的 SQLite3 库例程

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:22:24 24 4
gpt4 key购买 nike

下面的代码给了我一个乱序调用的库例程错误,但我无法解释问题出在哪里。有任何想法吗 ?

- (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;
}

日志打印错误准备=库例程调用顺序不对

最佳答案

我有一种方法。在此之前,请确保您已完成所有 sql 查询,如连接打开、关闭、完成等。

Before run your query actual into your code, execute that query into any database browser, You will see what is missing in your query.

在我的例子中,我错误地将列名放入查询中并运行代码,我多次遇到错误。我仔细检查了所有代码并在数据库浏览器中执行查询,我发现了我的错误。

关于ios - 乱序调用的 SQLite3 库例程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15904522/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com