gpt4 book ai didi

ios - sqlite DB 在获取 sqlite3_last_insert_rowid() objective-c 后显示 SQLITE_BUSY

转载 作者:行者123 更新时间:2023-11-29 12:17:06 30 4
gpt4 key购买 nike

我正在尝试在 sqlite 数据库成员表中插入一个成员。如果我使用 sqlite3_last_insert_rowid() 插入值后,我无法插入另一个成员。该语句显示 SQLITE_BUSY。这是我的代码。请任何人帮助。

-(NSInteger) saveMember:(TMMember *)member {
const char *dbPath = [databasePath UTF8String];
if (sqlite3_open(dbPath, &database) == SQLITE_OK)
{
NSString *insertSQL = [NSString stringWithFormat:@"insert into members (memberName, memberAmount,shareFlag) values(\"%@\", \"%f\",%d)",member.memberName,member.amount,[[NSNumber numberWithBool:member.shareFlag]intValue]];
const char *insert_stmt = [insertSQL UTF8String];
sqlite3_prepare_v2(database, insert_stmt,-1, &statement, NULL);
if(sqlite3_step(statement) == SQLITE_DONE)
{
NSInteger lastRowId = sqlite3_last_insert_rowid(database);
member.memberId = lastRowId;
NSLog(@"inserted member id = %ld",lastRowId);
NSLog(@"member is added");
}
sqlite3_finalize(statement);
statement = nil;
}
sqlite3_reset(statement);
sqlite3_close(database);
return 0;

最佳答案

当 sqlite 已经在处理另一条语句,而您正试图执行另一条语句时,就会出现此错误。因此,在您完成语句之前,数据库一直处于锁定状态。

了解更多信息。阅读:SQLite Exception: SQLite Busy

关于ios - sqlite DB 在获取 sqlite3_last_insert_rowid() objective-c 后显示 SQLITE_BUSY,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31743754/

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