gpt4 book ai didi

ios - 为什么在IOS中向sqlite插入数据时数据库被锁定?

转载 作者:行者123 更新时间:2023-11-29 03:16:49 26 4
gpt4 key购买 nike

为什么在 sqlite 中插入数据时数据库被锁定?我已经打开和关闭了我所有的数据库代码?我有这段代码:

-(void)insertDataIn_tbl_selectItem_data: (NSString *)empID ProdId: (NSString *)prodId ProdName: (NSString *)prodName  GenName: (NSString *)genName ComputeType: (NSString *)computeType UOM: (NSString *)uom ListPrice: (NSString *)listPrice UOMQty: (NSString *)uomqty{

const char *query = "insert into tbl_selectItem_data (femployeeid,fproductid,fname,fgeneric_name,fcompute_type,fuom,flist_price,fuomqty) values (?,?, ?, ?, ?, ?, ?, ?)";
sqlite3_stmt *stmt;

if (sqlite3_open([sqLiteDb UTF8String], &(_database)) == SQLITE_OK) {
if (sqlite3_prepare_v2(_database, query, -1, &stmt, nil) == SQLITE_OK) {

sqlite3_bind_text(stmt, 1, [empID UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(stmt, 2, [prodId UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(stmt, 3, [prodName UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(stmt, 4, [genName UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(stmt, 5, [computeType UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(stmt, 6, [uom UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(stmt, 7, [listPrice UTF8String], -1, SQLITE_TRANSIENT);
sqlite3_bind_text(stmt, 8, [uomqty UTF8String], -1, SQLITE_TRANSIENT);

if(sqlite3_step(stmt) == SQLITE_DONE){
NSLog(@"Insert Successful");
sqlite3_finalize(stmt);
}else{
NSLog(@"insertDataIn_tbl_selectItem_data error: %s", sqlite3_errmsg(_database));
}
}
}

sqlite3_close(_database);
}

最佳答案

首先...尝试“完成”您的陈述,即使存在错误...所以您的方法:

if(sqlite3_step(stmt) == SQLITE_DONE){
NSLog(@"Insert Successful");
sqlite3_finalize(stmt);
}else{
NSLog(@"insertDataIn_tbl_selectItem_data error: %s", sqlite3_errmsg(_database));
}
}
}
sqlite3_close(_database);

最好是:

if(sqlite3_step(stmt) == SQLITE_DONE){
NSLog(@"Insert Successful");
}else{
NSLog(@"insertDataIn_tbl_selectItem_data error: %s", sqlite3_errmsg(_database));
}
}
sqlite3_finalize(stmt);
}

sqlite3_close(_database);

第二个...

您可以尝试使用 sqlite3_open_v2 而不是 sqlite3_open 更多相关信息:http://www.sqlite.org/c3ref/open.html

所以...改为:

if (sqlite3_open([sqLiteDb UTF8String], &(_database)) == SQLITE_OK) {...}

将是:if (sqlite3_open_v2([sqLiteDb UTF8String], &(_database), SQLITE_OPEN_READWRITE, NULL) == SQLITE_OK) {....}

关于ios - 为什么在IOS中向sqlite插入数据时数据库被锁定?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21597925/

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