本文介绍了iPhone 中的 sqlite 中的“数据库已锁定"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
朋友你好,我已经搜索了很多关于这个错误的信息.我发现了一些建议,比如你必须使用 sqlite_finalize() 语句,我使用它.看看我的代码.
Hello friends I have searched a lot about this error. I found some advice like you must use sqlite_finalize() statement and I use it. Have a look on my code.
-(void) updatePostingsForLike:(NSString *)postingKey isLiked:(NSString *)isLiked{
[self initWithDB];
sqlite3_stmt *stmt;
if(sqlite3_open([[self dbPath] UTF8String],&(db)) == SQLITE_OK) {
NSString *str=[@"" stringByAppendingFormat:@"update posting set isLiked='%@' where postKey='%@'",isLiked,postingKey];
const char *sql=[str cStringUsingEncoding:NSUTF8StringEncoding];
int status;
status= sqlite3_prepare_v2(db,sql, -1, &stmt, NULL);
if(SQLITE_DONE != sqlite3_step(stmt))
{
NSLog(@"%s",sqlite3_errmsg(db));
}
sqlite3_finalize(stmt);
[self closeConnection];
}}
我遵守了所有规则.我只能更新我的记录一次.仅限第一次.它第二次抛出错误.解决方案应该是什么?自从过去 2 天以来,我一直在遇到这样的问题!
I followed all the rules. I can update my record only once. First time only. It throws error on second time. What should be the solution ? I stuck in such problem since last 2 days !
推荐答案
试试这个,
-(void) updatePostingsForLike:(NSString *)postingKey isLiked:(NSString *)isLiked
{
[self initWithDB];
sqlite3_stmt *statement;
if(sqlite3_open([[self dbPath] UTF8String],&db) == SQLITE_OK)
{
NSString* query=[NSString stringWithFormat: @"update posting set isLiked='%@' where postKey='%@'",isLiked,postingKey];
const char *query_stmt = [query UTF8String];
if (sqlite3_prepare_v2(db, query_stmt, -1, &statement, NULL) == SQLITE_OK)
{
while (sqlite3_step(statement) == SQLITE_ROW)
{
sqlite3_column_text(statement, 0);
}
sqlite3_finalize(statement);
}
sqlite3_close(db);
}
}
这篇关于iPhone 中的 sqlite 中的“数据库已锁定"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!