Sqlite敲定和Db锁定问题 [英] Sqlite finalise and Db locking issue

查看:110
本文介绍了Sqlite敲定和Db锁定问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序中使用以下功能,我最近开始使用sq-lite,我想得到你的意见,我正确或不正确。

I am using the below function in my app,and i have started using the sq-lite recently and i would like to get your opinion that i am going with that correctly or not.

由于我在搜索时遇到数据库锁定问题,我发现我需要使用sqlite3 finalize语句。

Since i am facing db locked issue in my app when searched i found that i need to use sqlite3 finalise statement.

我不确定是什么我是否需要为每个sqlite3准备语句放置一个finalize语句

what i am not sure is do i need to place one finalise statement for each sqlite3 prepare statement

请告诉我

- ( BOOL ) addNewCate:(NSString*)dbPath:(NSString*)title:(NSString*)tierOneID:(NSString*)tierTwoID{

    BOOL returnVal = NO;

    if (sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK) 
    {
        const char *sql = "insert into storyboard_phrases(phrase) Values(?)";

        sqlite3_stmt *addStmt;

        if(sqlite3_prepare_v2(database, sql, -1, &addStmt, NULL) == SQLITE_OK){

            sqlite3_bind_text(addStmt, 1, [title UTF8String], -1, SQLITE_TRANSIENT);
        }

        if(sqlite3_step(addStmt) != SQLITE_DONE ) {

            NSLog( @"Error: %s", sqlite3_errmsg(database) );

        } else {

            NSLog( @"Insert into row id = %d", sqlite3_last_insert_rowid(database));

            int ph_id = sqlite3_last_insert_rowid(database);

            int sub_category_id = [tierTwoID intValue];

            int main_category_id = [tierOneID intValue];

            addStmt = nil;

            sql = "insert into phrase_reference(phrase_id, sub_category_id,main_category_id) Values(?,?,?)";

            if(sqlite3_prepare_v2(database, sql, -1, &addStmt, NULL) == SQLITE_OK){

                sqlite3_bind_int(addStmt, 1, ph_id);

                sqlite3_bind_int(addStmt, 2, sub_category_id);

                sqlite3_bind_int(addStmt, 3, main_category_id);

            }

            if(sqlite3_step(addStmt) != SQLITE_DONE ) {

                NSLog( @"Error: %s", sqlite3_errmsg(database) );

            } else {

                NSLog( @"Insert into row id = %d", sqlite3_last_insert_rowid(database));
                returnVal = YES;


            }

        }
        sqlite3_finalize(addStmt);

    }
    sqlite3_close(database);

    return returnVal;
}


推荐答案

你得到锁定的问题在log right中,这意味着您的数据库打开,并且您在该数据库中进行了一些更改,以便关闭数据库并再次尝试运行应用程序并插入表...

hii you get the locked issues in log right, that means your database is open and you doing some changes in that database so close database and try again to run application and insert in table...

希望这对你有帮助..

hope this will help you..

这篇关于Sqlite敲定和Db锁定问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆