Change the timing of adding sqlite busy handler 30/129930/3
authorjongmyeongko <jongmyeong.ko@samsung.com>
Thu, 18 May 2017 10:56:16 +0000 (19:56 +0900)
committerJunghyun Yeon <jungh.yeon@samsung.com>
Thu, 1 Jun 2017 00:05:59 +0000 (00:05 +0000)
Earlier execution of sqlite_exec can be failed becase of
db lock when two different type packages are installed at the same time.

Change-Id: I8c53f68f7b1ee984b70573bdd441e66edcecc9d6
Signed-off-by: jongmyeongko <jongmyeong.ko@samsung.com>
parser/src/pkgmgr_parser_db.c

index 95f2472..74a8f47 100644 (file)
@@ -474,6 +474,14 @@ static int __open_db(uid_t uid, const char *path, sqlite3 **db, int flags)
        if (ret != SQLITE_OK)
                return ret;
 
+       ret = sqlite3_busy_handler(*db, __db_busy_handler, NULL);
+       if (ret != SQLITE_OK) {
+               _LOGE("failed to register busy handler: %s",
+                               sqlite3_errmsg(*db));
+               sqlite3_close_v2(*db);
+               return ret;
+       }
+
        if (flags & SQLITE_OPEN_CREATE) {
                ret = __initialize_db(*db, path, uid);
                if (ret) {
@@ -491,14 +499,6 @@ static int __open_db(uid_t uid, const char *path, sqlite3 **db, int flags)
                return ret;
        }
 
-       ret = sqlite3_busy_handler(*db, __db_busy_handler, NULL);
-       if (ret != SQLITE_OK) {
-               _LOGE("failed to register busy handler: %s",
-                               sqlite3_errmsg(*db));
-               sqlite3_close_v2(*db);
-               return ret;
-       }
-
        return ret;
 }