add db file versioning codes 74/67074/6
authorJunghyun Yeon <jungh.yeon@samsung.com>
Mon, 25 Apr 2016 05:22:03 +0000 (14:22 +0900)
committerJunghyun Yeon <jungh.yeon@samsung.com>
Fri, 3 Jun 2016 07:47:56 +0000 (00:47 -0700)
db version will be added with integer format.
minor version and patch version can be 2 digits each.

Change-Id: Ia35a3874ba1178c2d882d76e439a336e06260a69
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
packaging/pkgmgr-info.spec
parser/CMakeLists.txt
parser/pkgmgr_parser_db.c

index 84672f4..482c60d 100644 (file)
@@ -50,7 +50,11 @@ cp %{SOURCE1001} .
 
 %build
 MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
-%cmake . -DFULLVER=%{version} -DMAJORVER=${MAJORVER}
+%cmake . -DFULLVER=%{version} -DMAJORVER=${MAJORVER} \
+               -DTIZEN_MAJOR_VER=%{tizen_version_major} \
+               -DTIZEN_MINOR_VER=%{tizen_version_minor} \
+               -DTIZEN_PATCH_VER=%{tizen_version_patch}
+
 %__make %{?jobs:-j%jobs}
 
 %install
index dcdc744..c1d369c 100644 (file)
@@ -23,6 +23,28 @@ else()
 endif()
 message(STATUS "version/major : ${VERSION} / ${VERSION_MAJOR}")
 
+### Define tizen version for db version
+if(DEFINED TIZEN_MAJOR_VER)
+       ADD_DEFINITIONS("-DTIZEN_MAJOR_VER=\"${TIZEN_MAJOR_VER}\"")
+else()
+       message("TIZEN_MAJOR_VER is not defined. set it to 0")
+       ADD_DEFINITIONS("-DTIZEN_MAJOR_VER=\"0\"")
+endif()
+
+if(DEFINED TIZEN_MINOR_VER)
+       ADD_DEFINITIONS("-DTIZEN_MINOR_VER=\"${TIZEN_MINOR_VER}\"")
+else()
+       message("TIZEN_MINOR_VER is not defined. set it to 0")
+       ADD_DEFINITIONS("-DTIZEN_MINOR_VER=\"0\"")
+endif()
+
+if(DEFINED TIZEN_PATCH_VER)
+       ADD_DEFINITIONS("-DTIZEN_PATCH_VER=\"${TIZEN_PATCH_VER}\"")
+else()
+       message("TIZEN_PATCH_VER is not defined. set it to 0")
+       ADD_DEFINITIONS("-DTIZEN_PATCH_VER=\"${TIZEN_PATCH_VER}\"")
+endif()
+
 ### Get required CFLAGS, LDFLAGS from pkg-config
 
 include(FindPkgConfig)
index c818a6f..974a18b 100644 (file)
@@ -414,6 +414,8 @@ static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path)
 {
        int ret = -1;
        sqlite3 *handle;
+       char *query = NULL;
+       char *error_message = NULL;
 
        ret = db_util_open(db_path, &handle,  DB_UTIL_REGISTER_HOOK_METHOD);
        if (ret != SQLITE_OK) {
@@ -422,6 +424,16 @@ static int __pkgmgr_parser_create_db(sqlite3 **db_handle, const char *db_path)
        }
        *db_handle = handle;
 
+       /* add user_version for db upgrade*/
+       query = sqlite3_mprintf("PRAGMA user_version=%d", (atoi(TIZEN_MAJOR_VER) * 10000 + atoi(TIZEN_MINOR_VER) * 100 + atoi(TIZEN_PATCH_VER)));
+       if (SQLITE_OK !=
+           sqlite3_exec(handle, query, NULL, NULL, &error_message)) {
+               _LOGE("Don't execute query = %s error message = %s\n", query,
+                      error_message);
+       }
+       sqlite3_free(error_message);
+       sqlite3_free(query);
+
        return 0;
 }