[DB Review] DB commitee review comments.
authorsaerome.kim <saerome.kim@samsung.com>
Thu, 5 Sep 2019 08:21:48 +0000 (17:21 +0900)
committersaerome.kim <saerome.kim@samsung.com>
Mon, 16 Sep 2019 12:00:00 +0000 (21:00 +0900)
Change-Id: Id8431c88a9cc4e6a673d9b947501768aa171d3db
Signed-off-by: saerome.kim <saerome.kim@samsung.com>
ua-daemon/include/ua-manager-database.h
ua-daemon/src/pm/ua-ble-plugin-handler.c [changed mode: 0755->0644]
ua-daemon/src/pm/ua-plugin-manager.c [changed mode: 0755->0644]
ua-daemon/src/pm/ua-wifi-plugin-handler.c [changed mode: 0755->0644]
ua-daemon/src/ua-manager-db.c
ua-daemon/src/ua-manager-device-db.c
ua-daemon/src/ua-manager-device-service-db.c
ua-daemon/src/ua-manager-service-db.c
ua-daemon/src/ua-manager-user-db.c

index 347d091..0761850 100644 (file)
@@ -28,6 +28,12 @@ extern "C" {
 
 #define SQLITE_BUSY_TIMEOUT 500000
 
+
+/*
+ * 15) If possible,
+ *      change these four phrases to sqlite_exec3 and make it an atomic operation.
+ */
+
 /* Helper macros */
 #define EXEC(error_code, command, handle_error) do { \
        if (error_code != command) { \
old mode 100755 (executable)
new mode 100644 (file)
old mode 100755 (executable)
new mode 100644 (file)
old mode 100755 (executable)
new mode 100644 (file)
index 36dd7d2..9d8ed98 100644 (file)
 #define UAM_DB_DEVICE_SERVICES_TABLE "device_services" /**< Device services DB table name */
 #define UAM_DB_IBEACON_ADV_TABLE "ibeacon_adv" /**< iBeacon adv DB table name */
 
+/*
+ * 13) Need to version table for changing DB schema.
+ *     For instance, In case of frequent OS upgrade, VD should make a dicision
+ *     Whether it is needed to DB migration.
+ */
+
 #define CREATE_USERDATA_TABLE "CREATE TABLE IF NOT EXISTS userdata ( " \
        "name TEXT, " \
        "user_id INTEGER, " \
@@ -85,6 +91,11 @@ static int __ua_db_busy(void *user, int attempts)
        UAM_ERR("DB locked by another process, attempts number %d",
                        attempts);
 
+       /*
+        * 8) It can be usleep infinitely, so we can stop this callback (return 0)
+        *    For instance, usually, after 10 time sleeping.
+        *   The attemts variable tells you how many attempts.
+        */
        usleep(SQLITE_BUSY_TIMEOUT); /* wait for a half second*/
        FUNC_EXIT;
        return 1;
@@ -96,12 +107,20 @@ static int __uam_db_check_integrity_cb(
        FUNC_ENTRY;
        int i;
 
+       /*
+        * 7) count is column count so we just check which count is 'ok'
+        *    we can check integrity 2 ways:
+        *    - 1st is check column like us
+        *    - 2ne is check recodes are okey using sqlite3_step (ref: avocd_db_check_integrity())
+        *      //TIZEN/[MAIN]/[ONEPROD_Prj]/[FET]/[COSMOS]/SYSTEM/Avoc/avoc-service/avocd/src/db/avocd_db.cpp
+        *    which one is okey.
+        */
        for (i = 0; i < count; i++) {
                UAM_DBG("%s = %s\n", columns[i], data[i] ? data[i] : "NULL");
                if (!g_strcmp0(columns[i], "integrity_check") && !g_strcmp0(data[i], "ok"))
-                       return 0;
+                       return 0; /* 8) In order to enhance readabiity we can explicitly 0 means SUCCESS */
        }
-       return 1;
+       return 1; /* 9) In order to enhance readabiity we can explicitly 0 means DATA_ABORT */
 }
 
 static int __uam_db_check_table_cb(
@@ -124,6 +143,7 @@ static int __check_integrity(void)
        int res = 0;
        char *sql = NULL;
 
+       /* 11) Please don't open DB file multiple times */
        res = sqlite3_open(DATABASE_FULL_PATH, &database);
        if (res != SQLITE_OK) {
                UAM_ERR("Error in opening database %s: %s",
@@ -133,6 +153,7 @@ static int __check_integrity(void)
        }
        UAM_DBG("Successfully opened database");
 
+       /* 12) It is need to check file size is 0 at first time */
        size_t db_size = _uam_getFilesize(DATABASE_FULL_PATH);
        if (db_size == 0) {
                UAM_ERR("Database size is 0");
@@ -141,6 +162,9 @@ static int __check_integrity(void)
        }
        UAM_DBG("Database size: %zd", db_size);
 
+       /*
+        * 10) In oder to enhance SAM score, please replace below repeat block as a function
+        */
        res = sqlite3_exec(database, "PRAGMA integrity_check", __uam_db_check_integrity_cb, 0, 0);
        if (res != SQLITE_OK) {
                UAM_ERR("Can't verify database integrity %s",
@@ -152,8 +176,9 @@ static int __check_integrity(void)
        }
        UAM_DBG("Successfully verified database integrity");
 
+       /* REDUNDANT Start */
        sql = sqlite3_mprintf(
-               "SELECT count(*) as count FROM sqlite_master WHERE type='table' AND name='%s'",
+               "SELECT count(*) as count FROM sqlite_master WHERE type='table' AND name='%s'", /* 14) If possible please this SQL text as MACRO */
                UAM_DB_USERDATA_TABLE);
 
        res = sqlite3_exec(database, sql, __uam_db_check_table_cb, 0, 0);
@@ -168,7 +193,9 @@ static int __check_integrity(void)
                return UAM_ERROR_DB_FAILED;
        }
        UAM_DBG("Successfully verified %s table creation", UAM_DB_USERDATA_TABLE);
+       /* REDUNDANT End */
 
+       /* REDUNDANT Start */
        sql = sqlite3_mprintf(
                "SELECT count(*) as count FROM sqlite_master WHERE type='table' AND name='%s'",
                UAM_DB_DEVICES_TABLE);
@@ -185,7 +212,9 @@ static int __check_integrity(void)
                return UAM_ERROR_DB_FAILED;
        }
        UAM_DBG("Successfully verified %s table creation", UAM_DB_DEVICES_TABLE);
+       /* REDUNDANT End */
 
+       /* REDUNDANT Start */
        sql = sqlite3_mprintf(
                "SELECT count(*) as count FROM sqlite_master WHERE type='table' AND name='%s'",
                UAM_DB_SERVICES_TABLE);
@@ -203,6 +232,7 @@ static int __check_integrity(void)
        }
        UAM_DBG("Successfully verified %s table creation", UAM_DB_SERVICES_TABLE);
 
+       /* REDUNDANT Start */
        sql = sqlite3_mprintf(
                "SELECT count(*) as count FROM sqlite_master WHERE type='table' AND name='%s'",
                UAM_DB_IBEACON_ADV_TABLE);
@@ -219,7 +249,9 @@ static int __check_integrity(void)
                return UAM_ERROR_DB_FAILED;
        }
        UAM_DBG("Successfully verified %s table creation", UAM_DB_IBEACON_ADV_TABLE);
+       /* REDUNDANT End */
 
+       /* REDUNDANT Start */
        sql = sqlite3_mprintf(
                "SELECT count(*) as count FROM sqlite_master WHERE type='table' AND name='%s'",
                UAM_DB_DEVICE_SERVICES_TABLE);
@@ -236,7 +268,11 @@ static int __check_integrity(void)
                return UAM_ERROR_DB_FAILED;
        }
        UAM_DBG("Successfully verified %s table creation", UAM_DB_DEVICE_SERVICES_TABLE);
+       /* REDUNDANT End */
 
+       /*
+        * 11) why this is required? If it is not needed, please remove it
+        */
        res = sqlite3_exec(database, "PRAGMA locking_mode = NORMAL", 0, 0, 0);
        if (res != SQLITE_OK) {
                UAM_ERR("Can't set locking mode %s, skip set busy handler.",
@@ -324,6 +360,9 @@ static int __ua_create_table(const char *table_name)
 
 static void __ua_prepare_table(void)
 {
+       /*
+        * 4) Each __is_table_existing() open DB file again and again.. it is redundant
+        */
        if (!__is_table_existing(UAM_DB_USERDATA_TABLE))
                __ua_create_table(CREATE_USERDATA_TABLE);
 
@@ -346,6 +385,10 @@ int _ua_db_initialize_once(void)
        int sql_ret = SQLITE_OK;
        char *error = NULL;
 
+       /*
+        * 1) Once open DB file then we don't need to re-open DB
+        *    but in our code, we open the same DB repeately.
+        */
        sql_ret = sqlite3_open_v2(DATABASE_FULL_PATH, &(database),
                                SQLITE_OPEN_FULLMUTEX | SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
        if (SQLITE_OK != sql_ret) {
@@ -353,6 +396,10 @@ int _ua_db_initialize_once(void)
                return UAM_ERROR_DB_FAILED;
        }
 
+       /*
+        * 2) __check_integrity() should be executed before DB open
+        *   Move __check_integrity() ahead of _ua_db_initialize_once()
+        */
        if (UAM_ERROR_NONE != __check_integrity()) {
                UAM_ERR("Failed to check integrity");
                unlink(DATABASE_FULL_PATH);
@@ -368,6 +415,10 @@ int _ua_db_initialize_once(void)
 
        __ua_prepare_table();
 
+       /*
+        * 3) Default journal mode is PERIST so it seems use-less.
+        */
+
        /* Enable persist journal mode */
        sql_ret = sqlite3_exec(database, "PRAGMA journal_mode = PERSIST", NULL, NULL, &error);
        if (SQLITE_OK != sql_ret) {
@@ -378,6 +429,9 @@ int _ua_db_initialize_once(void)
                return UAM_ERROR_DB_FAILED;
        }
 
+       /*
+        * 12) it seems that we don't need busy handler because we are single thread.
+        */
        /* Set how many times we'll repeat our attempts for sqlite_step */
        if (SQLITE_OK != sqlite3_busy_handler(database, __ua_db_busy, NULL))
                UAM_ERR("Couldn't set busy handler!");
index a85b0b7..1202e5f 100644 (file)
@@ -251,6 +251,10 @@ static void __ua_device_table_devicesinfo_finalize(void)
        FUNC_EXIT;
 }
 
+/*
+ * 5) it just check only dtabase is null but all error-case
+ *    we just call the function for recovery.
+ */
 static sqlite3 *__ua_device_db_get_database(void)
 {
        if (database == NULL)
@@ -279,7 +283,7 @@ int _uam_db_get_max_device_number(void)
                case SQLITE_ERROR:
                default:
                        UAM_ERR("Failed to enumerate device info: %s",
-                                       sqlite3_errmsg(__ua_device_db_get_database()));
+                                       sqlite3_errmsg(__ua_device_db_get_database())); /* 5) it does not recover the DB because database is not null */
                }
        } while (rc == SQLITE_ROW);
 
@@ -338,9 +342,13 @@ int _ua_device_db_update_device_ip_address(char *device_id, int tech_type,
        DB_ACTION(sqlite3_bind_text(stmt, 4, address, -1, SQLITE_TRANSIENT),
                error_code, handle_error);
 
+       /* 6) SQLITE_DONE or SQITE_ROW can be returned but is not error
+        *    SQLITE_ROW can be returned multiple times, so we consider SQLITE_ROW case as well
+        *    Lastly, we just regard SQLITE_ERROR is actual error.
+        */
        if (sqlite3_step(stmt) != SQLITE_DONE) {
                UAM_ERR("Failed to update ip address: %s",
-                        sqlite3_errmsg(__ua_device_db_get_database()));
+                        sqlite3_errmsg(__ua_device_db_get_database())); /* 5) it does not recover the DB because database is not null */
 
                error_code = UAM_ERROR_DB_FAILED;
                goto handle_error;
@@ -371,9 +379,13 @@ int _ua_device_db_update_device_presence(char *device_id, int tech_type,
        DB_ACTION(sqlite3_bind_text(stmt, 4, address, -1, SQLITE_TRANSIENT),
                error_code, handle_error);
 
+       /* 6) SQLITE_DONE or SQITE_ROW can be returned but is not error
+        *    SQLITE_ROW can be returned multiple times, so we consider SQLITE_ROW case as well
+        *    Lastly, we just regard SQLITE_ERROR is actual error.
+        */
        if (sqlite3_step(stmt) != SQLITE_DONE) {
                UAM_ERR("Failed to update presence: %s",
-                        sqlite3_errmsg(__ua_device_db_get_database()));
+                        sqlite3_errmsg(__ua_device_db_get_database())); /* 5) it does not recover the DB because database is not null */
 
                error_code = UAM_ERROR_DB_FAILED;
                goto handle_error;
@@ -404,9 +416,13 @@ int _ua_device_db_update_device_timestamp(char *device_id, int tech_type,
        DB_ACTION(sqlite3_bind_text(stmt, 4, address, -1, SQLITE_TRANSIENT),
                error_code, handle_error);
 
+       /* 6) SQLITE_DONE or SQITE_ROW can be returned but is not error
+        *    SQLITE_ROW can be returned multiple times, so we consider SQLITE_ROW case as well
+        *    Lastly, we just regard SQLITE_ERROR is actual error.
+        */
        if (sqlite3_step(stmt) != SQLITE_DONE) {
                UAM_ERR("Failed to update device timestamp: %s",
-                        sqlite3_errmsg(__ua_device_db_get_database()));
+                        sqlite3_errmsg(__ua_device_db_get_database())); /* 5) it does not recover the DB because database is not null */
 
                error_code = UAM_ERROR_DB_FAILED;
                goto handle_error;
@@ -449,9 +465,13 @@ int _ua_device_db_update_device_device(char *device_id, int tech_type,
        DB_ACTION(sqlite3_bind_text(stmt, 10, address, -1, SQLITE_TRANSIENT),
                error_code, handle_error);
 
+       /* 6) SQLITE_DONE or SQITE_ROW can be returned but is not error
+        *    SQLITE_ROW can be returned multiple times, so we consider SQLITE_ROW case as well
+        *    Lastly, we just regard SQLITE_ERROR is actual error.
+        */
        if (sqlite3_step(stmt) != SQLITE_DONE) {
                UAM_ERR("Failed to update device discriminant: %s",
-                        sqlite3_errmsg(__ua_device_db_get_database()));
+                        sqlite3_errmsg(__ua_device_db_get_database())); /* 5) it does not recover the DB because database is not null */
 
                error_code = UAM_ERROR_DB_FAILED;
                goto handle_error;
@@ -507,9 +527,13 @@ int _ua_device_db_insert_device_info(int user_id,
        DB_ACTION(sqlite3_bind_int(stmt, 14, max_device_number + 1),
                error_code, handle_error);
 
+       /* 6) SQLITE_DONE or SQITE_ROW can be returned but is not error
+        *    SQLITE_ROW can be returned multiple times, so we consider SQLITE_ROW case as well
+        *    Lastly, we just regard SQLITE_ERROR is actual error.
+        */
        if (sqlite3_step(stmt) != SQLITE_DONE) {
                UAM_ERR("Failed to insert device info: %s",
-                               sqlite3_errmsg(__ua_device_db_get_database()));
+                               sqlite3_errmsg(__ua_device_db_get_database())); /* 5) it does not recover the DB because database is not null */
                error_code = UAM_ERROR_DB_FAILED;
                goto handle_error;
        }
@@ -540,9 +564,13 @@ int _ua_device_db_delete_device_info(const char *device_id, int tech_type,
        DB_ACTION(sqlite3_bind_text(stmt, 3, address, -1, SQLITE_STATIC),
                error_code, handle_error);
 
+       /* 6) SQLITE_DONE or SQITE_ROW can be returned but is not error
+        *    SQLITE_ROW can be returned multiple times, so we consider SQLITE_ROW case as well
+        *    Lastly, we just regard SQLITE_ERROR is actual error.
+        */
        if (sqlite3_step(stmt) != SQLITE_DONE) {
                UAM_ERR("Failed to delete device info %s",
-                               sqlite3_errmsg(__ua_device_db_get_database()));
+                               sqlite3_errmsg(__ua_device_db_get_database())); /* 5) it does not recover the DB because database is not null */
                error_code = UAM_ERROR_DB_FAILED;
        } else
                UAM_DBG("User info deleted");
@@ -571,9 +599,13 @@ int _ua_device_db_get_device(char *device_id, int tech_type, char *address,
        DB_ACTION(sqlite3_bind_text(stmt, 3, address, -1, SQLITE_STATIC),
                error_code, handle_error);
 
+       /* 6) SQLITE_DONE or SQITE_ROW can be returned but is not error
+        *    SQLITE_ROW can be returned multiple times, so we consider SQLITE_ROW case as well
+        *    Lastly, we just regard SQLITE_ERROR is actual error.
+        */
        if (sqlite3_step(stmt) != SQLITE_DONE) {
                UAM_ERR("Failed to select device info %s",
-                               sqlite3_errmsg(__ua_device_db_get_database()));
+                               sqlite3_errmsg(__ua_device_db_get_database())); /* 5) it does not recover the DB because database is not null */
                error_code = UAM_ERROR_DB_FAILED;
        } else {
                UAM_DBG("Device info found");
@@ -651,7 +683,7 @@ int _uam_db_get_device_number(const char *device_id, int tech_type,
                case SQLITE_ERROR:
                default:
                        UAM_ERR("Failed to enumerate device info: %s",
-                                       sqlite3_errmsg(__ua_device_db_get_database()));
+                                       sqlite3_errmsg(__ua_device_db_get_database())); /* 5) it does not recover the DB because database is not null */
                }
        } while (rc == SQLITE_ROW);
 
@@ -714,7 +746,7 @@ GSList *_ua_device_db_get_all_devices(void)
                case SQLITE_ERROR:
                default:
                        UAM_ERR("Failed to enumerate device info: %s",
-                                       sqlite3_errmsg(__ua_device_db_get_database()));
+                                       sqlite3_errmsg(__ua_device_db_get_database())); /* 5) it does not recover the DB because database is not null */
                }
        } while (rc == SQLITE_ROW);
 
@@ -728,6 +760,10 @@ int _ua_device_db_clear(void)
        int error_code = UAM_ERROR_NONE;
        sqlite3_stmt *stmt = delete_all_devices;
 
+       /* 6) SQLITE_DONE or SQITE_ROW can be returned but is not error
+        *    SQLITE_ROW can be returned multiple times, so we consider SQLITE_ROW case as well
+        *    Lastly, we just regard SQLITE_ERROR is actual error.
+        */
        if (sqlite3_step(stmt) != SQLITE_DONE) {
                UAM_ERR("Failed to delete device data %s",
                                sqlite3_errmsg(__ua_device_db_get_database()));
index cb37d04..0780ebe 100644 (file)
@@ -249,6 +249,10 @@ int _uam_db_insert_service(int device_number, int service_number)
        DB_ACTION(sqlite3_bind_int(stmt, 1, device_number), error_code, handle_error);
        DB_ACTION(sqlite3_bind_int(stmt, 2, service_number), error_code, handle_error);
 
+       /* 6) SQLITE_DONE or SQITE_ROW can be returned but is not error
+        *    SQLITE_ROW can be returned multiple times, so we consider SQLITE_ROW case as well
+        *    Lastly, we just regard SQLITE_ERROR is actual error.
+        */
        if (sqlite3_step(stmt) != SQLITE_DONE) {
                UAM_ERR("Failed to insert device-service info: %s",
                                sqlite3_errmsg(__ua_device_service_db_get_database()));
@@ -306,6 +310,10 @@ int _ua_device_service_db_clear(void)
        int error_code = UAM_ERROR_NONE;
        sqlite3_stmt *stmt = delete_all_device_services;
 
+       /* 6) SQLITE_DONE or SQITE_ROW can be returned but is not error
+        *    SQLITE_ROW can be returned multiple times, so we consider SQLITE_ROW case as well
+        *    Lastly, we just regard SQLITE_ERROR is actual error.
+        */
        if (sqlite3_step(stmt) != SQLITE_DONE) {
                UAM_ERR("Failed to delete device data %s",
                                sqlite3_errmsg(__ua_device_service_db_get_database()));
@@ -331,6 +339,10 @@ int _uam_db_delete_service_number(int service_number)
 
        DB_ACTION(sqlite3_bind_int(stmt, 1, service_number), error_code, handle_error);
 
+       /* 6) SQLITE_DONE or SQITE_ROW can be returned but is not error
+        *    SQLITE_ROW can be returned multiple times, so we consider SQLITE_ROW case as well
+        *    Lastly, we just regard SQLITE_ERROR is actual error.
+        */
        if (sqlite3_step(stmt) != SQLITE_DONE) {
                UAM_ERR("Failed to delete device-service info %s",
                                sqlite3_errmsg(__ua_device_service_db_get_database()));
@@ -355,6 +367,10 @@ int _uam_db_delete_device_service_number(int device_number, int service_number)
        DB_ACTION(sqlite3_bind_int(stmt, 1, device_number), error_code, handle_error);
        DB_ACTION(sqlite3_bind_int(stmt, 2, service_number), error_code, handle_error);
 
+       /* 6) SQLITE_DONE or SQITE_ROW can be returned but is not error
+        *    SQLITE_ROW can be returned multiple times, so we consider SQLITE_ROW case as well
+        *    Lastly, we just regard SQLITE_ERROR is actual error.
+        */
        if (sqlite3_step(stmt) != SQLITE_DONE) {
                UAM_ERR("Failed to delete device-service info %s",
                                sqlite3_errmsg(__ua_device_service_db_get_database()));
index ce32a4a..a3b66d2 100644 (file)
@@ -296,6 +296,10 @@ int _uam_db_insert_service_info(
        DB_ACTION(sqlite3_bind_int(stmt, 3, cycle),
                error_code, handle_error);
 
+       /* 6) SQLITE_DONE or SQITE_ROW can be returned but is not error
+        *    SQLITE_ROW can be returned multiple times, so we consider SQLITE_ROW case as well
+        *    Lastly, we just regard SQLITE_ERROR is actual error.
+        */
        if (sqlite3_step(stmt) != SQLITE_DONE) {
                UAM_ERR("Failed to insert service info: %s",
                                sqlite3_errmsg(__ua_service_db_get_database()));
@@ -330,6 +334,10 @@ int _uam_db_delete_service_info(const char *service_name)
        DB_ACTION(sqlite3_bind_text(stmt, 1, service_name, -1, SQLITE_STATIC),
                error_code, handle_error);
 
+       /* 6) SQLITE_DONE or SQITE_ROW can be returned but is not error
+        *    SQLITE_ROW can be returned multiple times, so we consider SQLITE_ROW case as well
+        *    Lastly, we just regard SQLITE_ERROR is actual error.
+        */
        if (sqlite3_step(stmt) != SQLITE_DONE) {
                UAM_ERR("Failed to delete service info %s",
                                sqlite3_errmsg(__ua_service_db_get_database()));
@@ -348,6 +356,10 @@ int _ua_service_db_clear(void)
        int error_code = UAM_ERROR_NONE;
        sqlite3_stmt *stmt = delete_all_services;
 
+       /* 6) SQLITE_DONE or SQITE_ROW can be returned but is not error
+        *    SQLITE_ROW can be returned multiple times, so we consider SQLITE_ROW case as well
+        *    Lastly, we just regard SQLITE_ERROR is actual error.
+        */
        if (sqlite3_step(stmt) != SQLITE_DONE) {
                UAM_ERR("Failed to delete service data %s",
                                sqlite3_errmsg(__ua_service_db_get_database()));
@@ -375,6 +387,10 @@ int _uam_db_update_service_cycle(const char *service_name, int cycle)
        DB_ACTION(sqlite3_bind_text(stmt, 2, service_name, -1, SQLITE_TRANSIENT),
                error_code, handle_error);
 
+       /* 6) SQLITE_DONE or SQITE_ROW can be returned but is not error
+        *    SQLITE_ROW can be returned multiple times, so we consider SQLITE_ROW case as well
+        *    Lastly, we just regard SQLITE_ERROR is actual error.
+        */
        if (sqlite3_step(stmt) != SQLITE_DONE) {
                UAM_ERR("Failed to update service timestamp: %s",
                         sqlite3_errmsg(__ua_service_db_get_database()));
index 5c71590..7771c9c 100644 (file)
@@ -302,6 +302,10 @@ int _ua_db_insert_user_info(int *user_id, const char *name, const char *account)
        DB_ACTION(sqlite3_bind_text(stmt, 3, account, -1, SQLITE_TRANSIENT),
                error_code, handle_error);
 
+       /* 6) SQLITE_DONE or SQITE_ROW can be returned but is not error
+        *    SQLITE_ROW can be returned multiple times, so we consider SQLITE_ROW case as well
+        *    Lastly, we just regard SQLITE_ERROR is actual error.
+        */
        if (sqlite3_step(stmt) != SQLITE_DONE) {
                UAM_ERR("Failed to insert user info: %s",
                                sqlite3_errmsg(__ua_db_get_database()));
@@ -331,6 +335,10 @@ int _ua_db_delete_by_user_id(int user_id)
 
        DB_ACTION(sqlite3_bind_int(stmt, 1, user_id), error_code, handle_error);
 
+       /* 6) SQLITE_DONE or SQITE_ROW can be returned but is not error
+        *    SQLITE_ROW can be returned multiple times, so we consider SQLITE_ROW case as well
+        *    Lastly, we just regard SQLITE_ERROR is actual error.
+        */
        if (sqlite3_step(stmt) != SQLITE_DONE) {
                UAM_ERR("Failed to delete user info %s",
                                sqlite3_errmsg(__ua_db_get_database()));
@@ -357,6 +365,10 @@ int _ua_db_get_user(int user_id, db_user_info_t *info)
 
        DB_ACTION(sqlite3_bind_int(stmt, 1, user_id), error_code, handle_error);
 
+       /* 6) SQLITE_DONE or SQITE_ROW can be returned but is not error
+        *    SQLITE_ROW can be returned multiple times, so we consider SQLITE_ROW case as well
+        *    Lastly, we just regard SQLITE_ERROR is actual error.
+        */
        if (sqlite3_step(stmt) != SQLITE_DONE) {
                UAM_ERR("Failed to select user info %s",
                                sqlite3_errmsg(__ua_db_get_database()));
@@ -424,6 +436,10 @@ int _ua_db_clear(void)
        int error_code = UAM_ERROR_NONE;
        sqlite3_stmt *stmt = delete_all_users_data;
 
+       /* 6) SQLITE_DONE or SQITE_ROW can be returned but is not error
+        *    SQLITE_ROW can be returned multiple times, so we consider SQLITE_ROW case as well
+        *    Lastly, we just regard SQLITE_ERROR is actual error.
+        */
        if (sqlite3_step(stmt) != SQLITE_DONE) {
                UAM_ERR("Failed to delete user data %s",
                                sqlite3_errmsg(__ua_db_get_database()));