Fix some svace issues for unchecking return value
[platform/core/connectivity/stc-manager.git] / src / database / tables / table-restrictions.c
index a5cb108..71167ee 100755 (executable)
 
 /* DELETE statements */
 #define DELETE_RESTRICTIONS "DELETE FROM restrictions " \
-       " WHERE binpath = ? AND iftype = ? AND imsi = ?"
+       " WHERE binpath = ? AND iftype = ? AND ifname = ? " \
+       " AND subscriber_id = ? AND roaming = ?"
 
 /* SELECT statements */
 #define SELECT_RESTRICTIONS "SELECT binpath, data_limit, " \
-       " iftype, rst_state, roaming, ifname, imsi, " \
-       " data_warn_limit, restriction_id FROM restrictions"
+       " iftype, rstn_type, roaming, ifname, subscriber_id, " \
+       " data_warn_limit, monthly_limit, weekly_limit, daily_limit, month_start_date, " \
+       " restriction_id FROM restrictions"
 
 #define SELECT_RESTRICTIONS_PER_APP "SELECT binpath, data_limit, " \
-       " iftype, rst_state, roaming, ifname, imsi, " \
-       " data_warn_limit, restriction_id " \
+       " iftype, rstn_type, roaming, ifname, subscriber_id, " \
+       " data_warn_limit, monthly_limit, weekly_limit, daily_limit, month_start_date, " \
+       " restriction_id " \
        " FROM restrictions INDEXED BY restrictions_index " \
        " WHERE binpath = ?"
 
-#define SELECT_RESTRICTION_STATE "SELECT rst_state " \
+#define SELECT_RESTRICTION_TYPE "SELECT rstn_type " \
        " FROM restrictions INDEXED BY restrictions_index " \
        " WHERE binpath = ? AND iftype = ?"
 
-#define SELECT_RESTRICTION_STATE_IMSI "SELECT rst_state " \
+#define SELECT_RESTRICTION_TYPE_SUBSCRIBER_ID "SELECT rstn_type " \
        " FROM restrictions INDEXED BY restrictions_index " \
-       " WHERE binpath = ? AND iftype = ? AND imsi = ?"
+       " WHERE binpath = ? AND iftype = ? AND subscriber_id = ?"
 
 #define SELECT_RESTRICTION_ID "SELECT restriction_id FROM restrictions " \
-       " WHERE binpath = ? AND iftype = ? AND imsi = ? AND " \
-       " data_limit = ? AND data_warn_limit = ? AND " \
-       " rst_state = ? AND roaming = ? AND ifname = ?"
+       " WHERE binpath = ? AND iftype = ? AND subscriber_id = ? AND " \
+       " roaming = ? AND ifname = ?"
 
 /* UPDATE statement */
 #define UPDATE_NET_RESTRICTIONS "UPDATE restrictions " \
-       " SET binpath = ?, data_limit = ?, iftype = ?, rst_state = ?, " \
-       " roaming = ?, ifname = ?, imsi = ?, data_warn_limit = ? " \
+       " SET binpath = ?, data_limit = ?, iftype = ?, rstn_type = ?, " \
+       " roaming = ?, ifname = ?, subscriber_id = ?, data_warn_limit = ?, " \
+       " monthly_limit = ?, weekly_limit = ?, daily_limit = ? " \
        " WHERE restriction_id = ?"
 
 /* INSERT statement */
 #define INSERT_NET_RESTRICTIONS "INSERT INTO restrictions " \
-       " (binpath, data_limit, iftype, rst_state, " \
-       " roaming, ifname, imsi, data_warn_limit) " \
-       " VALUES (?, ?, ?, ?, ?, ?, ?, ?)"
+       " (binpath, data_limit, iftype, rstn_type, " \
+       " roaming, ifname, subscriber_id, data_warn_limit, " \
+       " monthly_limit, weekly_limit, daily_limit, month_start_date) " \
+       " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
 
 static void __finalize_delete(void);
 
@@ -129,8 +133,8 @@ static sqlite3_stmt *delete_restrictions;
 /* SELECT statements */
 static sqlite3_stmt *select_restriction;
 static sqlite3_stmt *select_restriction_per_app;
-static sqlite3_stmt *select_restriction_state;
-static sqlite3_stmt *select_restriction_state_imsi;
+static sqlite3_stmt *select_restriction_type;
+static sqlite3_stmt *select_restriction_type_subscriber_id;
 static sqlite3_stmt *select_restriction_id;
 
 /* REPLACE statements */
@@ -146,8 +150,8 @@ static int __prepare_delete(sqlite3 *db)
        static int initialized;
 
        if (initialized) {
-               __STC_LOG_FUNC_EXIT__;
-               return SQLITE_OK;
+               __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+               return SQLITE_OK; //LCOV_EXCL_LINE
        }
 
        PREPARE_DELETE(delete_restrictions, DELETE_RESTRICTIONS);
@@ -173,14 +177,14 @@ static int __prepare_select(sqlite3 *db)
        static int initialized;
 
        if (initialized) {
-               __STC_LOG_FUNC_EXIT__;
-               return SQLITE_OK;
+               __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+               return SQLITE_OK; //LCOV_EXCL_LINE
        }
 
        PREPARE_SELECT(select_restriction, SELECT_RESTRICTIONS);
        PREPARE_SELECT(select_restriction_per_app, SELECT_RESTRICTIONS_PER_APP);
-       PREPARE_SELECT(select_restriction_state, SELECT_RESTRICTION_STATE);
-       PREPARE_SELECT(select_restriction_state_imsi, SELECT_RESTRICTION_STATE_IMSI);
+       PREPARE_SELECT(select_restriction_type, SELECT_RESTRICTION_TYPE);
+       PREPARE_SELECT(select_restriction_type_subscriber_id, SELECT_RESTRICTION_TYPE_SUBSCRIBER_ID);
        PREPARE_SELECT(select_restriction_id, SELECT_RESTRICTION_ID);
 
        initialized = 1;
@@ -194,8 +198,8 @@ static void __finalize_select(void)
 
        FINALIZE(select_restriction);
        FINALIZE(select_restriction_per_app);
-       FINALIZE(select_restriction_state);
-       FINALIZE(select_restriction_state_imsi);
+       FINALIZE(select_restriction_type);
+       FINALIZE(select_restriction_type_subscriber_id);
        FINALIZE(select_restriction_id);
 
        __STC_LOG_FUNC_EXIT__;
@@ -208,8 +212,8 @@ static int __prepare_replace(sqlite3 *db)
        static int initialized;
 
        if (initialized) {
-               __STC_LOG_FUNC_EXIT__;
-               return SQLITE_OK;
+               __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+               return SQLITE_OK; //LCOV_EXCL_LINE
        }
 
        PREPARE_UPDATE(update_net_restrictions, UPDATE_NET_RESTRICTIONS);
@@ -235,8 +239,8 @@ static int __prepare_insert(sqlite3 *db)
        static int initialized;
 
        if (initialized) {
-               __STC_LOG_FUNC_EXIT__;
-               return SQLITE_OK;
+               __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+               return SQLITE_OK; //LCOV_EXCL_LINE
        }
 
        PREPARE_UPDATE(insert_net_restrictions, INSERT_NET_RESTRICTIONS);
@@ -266,8 +270,8 @@ stc_error_e table_restrictions_per_app(const gchar* app_id,
        sqlite3_stmt *stmt = select_restriction_per_app;
 
        if (!app_id) {
-               __STC_LOG_FUNC_EXIT__;
-               return STC_ERROR_DB_FAILED;
+               __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+               return STC_ERROR_DB_FAILED; //LCOV_EXCL_LINE
        }
 
        DB_ACTION(sqlite3_bind_text(stmt, 1, app_id, -1,
@@ -286,34 +290,40 @@ stc_error_e table_restrictions_per_app(const gchar* app_id,
                        data.app_id = (char *)sqlite3_column_text(stmt, 0);
                        data.data_limit = sqlite3_column_int64(stmt, 1);
                        data.iftype = (stc_iface_type_e)sqlite3_column_int(stmt, 2);
-                       data.rst_state =
-                               (stc_restriction_state_e)sqlite3_column_int(stmt, 3);
+                       data.rstn_type =
+                               (stc_rstn_type_e)sqlite3_column_int(stmt, 3);
                        data.roaming = sqlite3_column_int(stmt, 4);
                        data.ifname = (char *)sqlite3_column_text(stmt, 5);
-                       data.imsi = (char *)sqlite3_column_text(stmt, 6);
+                       data.subscriber_id = (char *)sqlite3_column_text(stmt, 6);
                        data.data_warn_limit = sqlite3_column_int64(stmt, 7);
-                       data.restriction_id = sqlite3_column_int64(stmt, 8);
+                       data.monthly_limit = sqlite3_column_int64(stmt, 8);
+                       data.weekly_limit = sqlite3_column_int64(stmt, 9);
+                       data.daily_limit = sqlite3_column_int64(stmt, 10);
+                       data.restriction_id = sqlite3_column_int64(stmt, 11);
 
                        if (restriction_cb(&data, user_data) == STC_CANCEL)
-                               rc = SQLITE_DONE;
+                               rc = SQLITE_DONE; //LCOV_EXCL_LINE
                        break;
                case SQLITE_ERROR:
                default:
-                       STC_LOGE("Failed to enumerate restrictions: %s\n",
+                       STC_LOGE("Failed to enumerate restrictions: %s\n", //LCOV_EXCL_LINE
                                 sqlite3_errmsg(stc_db_get_database()));
 
-                       __STC_LOG_FUNC_EXIT__;
-                       error_code = STC_ERROR_DB_FAILED;
+                       __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+                       error_code = STC_ERROR_DB_FAILED; //LCOV_EXCL_LINE
                }
        } while (rc == SQLITE_ROW);
 
 handle_error:
-       sqlite3_reset(stmt);
+       rc = sqlite3_reset(stmt);
+       if (rc != SQLITE_OK)
+               error_code = STC_ERROR_DB_FAILED;
+
        __STC_LOG_FUNC_EXIT__;
        return error_code;
 }
 
-stc_error_e table_restrictions_foreach(const table_restrictions_info_cb restriction_cb,
+API stc_error_e table_restrictions_foreach(const table_restrictions_info_cb restriction_cb,
                                       void *user_data)
 {
        __STC_LOG_FUNC_ENTER__;
@@ -334,133 +344,161 @@ stc_error_e table_restrictions_foreach(const table_restrictions_info_cb restrict
                        data.app_id = (char *)sqlite3_column_text(stmt, 0);
                        data.data_limit = sqlite3_column_int64(stmt, 1);
                        data.iftype = (stc_iface_type_e)sqlite3_column_int(stmt, 2);
-                       data.rst_state =
-                               (stc_restriction_state_e)sqlite3_column_int(stmt, 3);
+                       data.rstn_type =
+                               (stc_rstn_type_e)sqlite3_column_int(stmt, 3);
                        data.roaming = sqlite3_column_int(stmt, 4);
                        data.ifname = (char *)sqlite3_column_text(stmt, 5);
-                       data.imsi = (char *)sqlite3_column_text(stmt, 6);
+                       data.subscriber_id = (char *)sqlite3_column_text(stmt, 6);
                        data.data_warn_limit = sqlite3_column_int64(stmt, 7);
-                       data.restriction_id = sqlite3_column_int64(stmt, 8);
+                       data.monthly_limit = sqlite3_column_int64(stmt, 8);
+                       data.weekly_limit = sqlite3_column_int64(stmt, 9);
+                       data.daily_limit = sqlite3_column_int64(stmt, 10);
+                       data.month_start_date = sqlite3_column_int(stmt, 11);
+                       data.restriction_id = sqlite3_column_int64(stmt, 12);
 
                        if (restriction_cb(&data, user_data) == STC_CANCEL)
-                               rc = SQLITE_DONE;
+                               rc = SQLITE_DONE; //LCOV_EXCL_LINE
                        break;
                case SQLITE_ERROR:
                default:
-                       STC_LOGE("Failed to enumerate restrictions: %s\n",
+                       STC_LOGE("Failed to enumerate restrictions: %s\n", //LCOV_EXCL_LINE
                                 sqlite3_errmsg(stc_db_get_database()));
 
-                       __STC_LOG_FUNC_EXIT__;
-                       error_code = STC_ERROR_DB_FAILED;
+                       __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+                       error_code = STC_ERROR_DB_FAILED; //LCOV_EXCL_LINE
                }
        } while (rc == SQLITE_ROW);
 
-       sqlite3_reset(stmt);
+       rc = sqlite3_reset(stmt);
+       if (rc != SQLITE_OK)
+               error_code = STC_ERROR_DB_FAILED;
+
        __STC_LOG_FUNC_EXIT__;
        return error_code;
 }
 
-stc_error_e table_restrictions_get_restriction_state_imsi(const char *app_id,
+stc_error_e table_restrictions_get_restriction_type_subscriber_id(const char *app_id,
                                                          stc_iface_type_e iftype,
-                                                         const char *imsi_hash,
-                                                         stc_restriction_state_e *state)
+                                                         const char *subscriber_id,
+                                                         stc_rstn_type_e *type)
 {
        __STC_LOG_FUNC_ENTER__;
        int error_code = STC_ERROR_NONE;
        int ret;
-       bool state_imsi = 0;
+       bool state_subscriber_id = 0;
+
+       if (type == NULL) {
+               STC_LOGE("Please provide valid argument!"); //LCOV_EXCL_LINE
+               __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+               return STC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+       }
 
-       if (state == NULL) {
-               STC_LOGE("Please provide valid argument!");
-               __STC_LOG_FUNC_EXIT__;
-               return STC_ERROR_INVALID_PARAMETER;
+       *type = STC_RSTN_TYPE_UNKNOWN;
+       ret = sqlite3_reset(select_restriction_type_subscriber_id);
+       if (ret != SQLITE_OK) {
+               __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+               return STC_ERROR_DB_FAILED; //LCOV_EXCL_LINE
        }
 
-       *state = STC_RESTRICTION_UNKNOWN;
-       sqlite3_reset(select_restriction_state_imsi);
-       sqlite3_reset(select_restriction_state);
+       ret = sqlite3_reset(select_restriction_type);
+       if (ret != SQLITE_OK) {
+               __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+               return STC_ERROR_DB_FAILED; //LCOV_EXCL_LINE
+       }
 
-       if (imsi_hash == NULL) {
-               state_imsi = 0;
-               DB_ACTION(sqlite3_bind_text(select_restriction_state, 1,
+       if (subscriber_id == NULL) {
+               state_subscriber_id = 0;
+               DB_ACTION(sqlite3_bind_text(select_restriction_type, 1,
                                            app_id ? app_id : "", -1,
                                            SQLITE_STATIC));
-               DB_ACTION(sqlite3_bind_int(select_restriction_state, 2,
+               DB_ACTION(sqlite3_bind_int(select_restriction_type, 2,
                                           iftype));
-               ret = sqlite3_step(select_restriction_state);
+               ret = sqlite3_step(select_restriction_type);
        } else {
-               state_imsi = 1;
-               DB_ACTION(sqlite3_bind_text(select_restriction_state_imsi, 1,
+               state_subscriber_id = 1;
+               DB_ACTION(sqlite3_bind_text(select_restriction_type_subscriber_id, 1,
                                            app_id ? app_id : "", -1,
                                            SQLITE_STATIC));
-               DB_ACTION(sqlite3_bind_int(select_restriction_state_imsi, 2,
+               DB_ACTION(sqlite3_bind_int(select_restriction_type_subscriber_id, 2,
                                           iftype));
-               DB_ACTION(sqlite3_bind_text(select_restriction_state_imsi, 3,
-                                           imsi_hash, -1, SQLITE_STATIC));
-               ret = sqlite3_step(select_restriction_state_imsi);
+               DB_ACTION(sqlite3_bind_text(select_restriction_type_subscriber_id, 3,
+                                           subscriber_id, -1, SQLITE_STATIC));
+               ret = sqlite3_step(select_restriction_type_subscriber_id);
        }
 
        switch (ret) {
        case SQLITE_DONE:
                break;
        case SQLITE_ROW:
-               if (state_imsi)
-                       *state = (stc_restriction_state_e)sqlite3_column_int(select_restriction_state_imsi, 0);
+               if (state_subscriber_id)
+                       *type = (stc_rstn_type_e)sqlite3_column_int(select_restriction_type_subscriber_id, 0);
                else
-                       *state = (stc_restriction_state_e)sqlite3_column_int(select_restriction_state, 0);
+                       *type = (stc_rstn_type_e)sqlite3_column_int(select_restriction_type, 0);
                break;
        case SQLITE_ERROR:
        default:
-               STC_LOGE("Can't perform sql query: %s \n%s",
-                        SELECT_RESTRICTION_STATE,
+               STC_LOGE("Can't perform sql query: %s\n", //LCOV_EXCL_LINE
                         sqlite3_errmsg(stc_db_get_database()));
-               error_code = STC_ERROR_DB_FAILED;
+               error_code = STC_ERROR_DB_FAILED; //LCOV_EXCL_LINE
        }
 
 handle_error:
-       sqlite3_reset(select_restriction_state);
-       sqlite3_reset(select_restriction_state_imsi);
+       ret = sqlite3_reset(select_restriction_type);
+       if (ret != SQLITE_OK)
+               error_code = STC_ERROR_DB_FAILED;
+
+       ret = sqlite3_reset(select_restriction_type_subscriber_id);
+       if (ret != SQLITE_OK)
+               error_code = STC_ERROR_DB_FAILED;
+
        return error_code;
 }
 
-stc_error_e table_restrictions_get_restriction_state(const char *app_id,
+stc_error_e table_restrictions_get_restriction_type(const char *app_id,
                                                     stc_iface_type_e iftype,
-                                                    stc_restriction_state_e *state)
+                                                    stc_rstn_type_e *type)
 {
        __STC_LOG_FUNC_ENTER__;
        __STC_LOG_FUNC_EXIT__;
-       return table_restrictions_get_restriction_state_imsi(app_id, iftype,
-                                                            NULL, state);
+       return table_restrictions_get_restriction_type_subscriber_id(app_id, iftype,
+                                                            NULL, type);
 }
 
 stc_error_e table_restrictions_delete(const char *app_id,
                                      const stc_iface_type_e iftype,
-                                     const char *imsi)
+                                     const char *ifname,
+                                     const char *subscriber_id,
+                                     const stc_roaming_type_e roaming)
 {
        stc_error_e error_code = STC_ERROR_NONE;
        sqlite3_stmt *stmt = delete_restrictions;
 
-       STC_LOGD("app_id [%s], iftype [%d], imsi [%s]",
-                app_id, iftype, imsi);
+       STC_LOGD("app_id[%s] iftype[%d] ifname[%s] subscriber_id[%s] roaming[%d]",
+                app_id, iftype, ifname, subscriber_id, roaming);
 
        DB_ACTION(sqlite3_bind_text(stmt, 1, app_id ? app_id : "",
                                    -1, SQLITE_TRANSIENT));
        DB_ACTION(sqlite3_bind_int(stmt, 2, iftype));
-       DB_ACTION(sqlite3_bind_text(stmt, 3, imsi ? imsi : "", -1,
-                                   SQLITE_TRANSIENT));
+       DB_ACTION(sqlite3_bind_text(stmt, 3, ifname ? ifname : "",
+                                   -1, SQLITE_TRANSIENT));
+       DB_ACTION(sqlite3_bind_text(stmt, 4, subscriber_id ? subscriber_id : "",
+                                       -1, SQLITE_TRANSIENT));
+       DB_ACTION(sqlite3_bind_int(stmt, 5, roaming));
 
        if (sqlite3_step(stmt) != SQLITE_DONE) {
-               STC_LOGE("Failed to remove restrictions by network interface %s\n",
+               STC_LOGE("Failed to remove restrictions by network interface %s\n", //LCOV_EXCL_LINE
                         sqlite3_errmsg(stc_db_get_database()));
-               error_code = STC_ERROR_DB_FAILED;
-               goto handle_error;
+               error_code = STC_ERROR_DB_FAILED; //LCOV_EXCL_LINE
+               goto handle_error; //LCOV_EXCL_LINE
        }
 
        STC_LOGD("Restriction deleted for app_id [%s]", app_id);
 
 handle_error:
 
-       sqlite3_reset(stmt);
+       if (sqlite3_reset(stmt) != SQLITE_OK)
+               error_code = STC_ERROR_DB_FAILED;
+
        return error_code;
 }
 
@@ -474,13 +512,10 @@ stc_error_e __get_restriction_id(table_restrictions_info *info)
        DB_ACTION(sqlite3_bind_text(stmt, 1, info->app_id ? info->app_id : "",
                                    -1, SQLITE_TRANSIENT));
        DB_ACTION(sqlite3_bind_int(stmt, 2, info->iftype));
-       DB_ACTION(sqlite3_bind_text(stmt, 3, info->imsi ? info->imsi : "",
+       DB_ACTION(sqlite3_bind_text(stmt, 3, info->subscriber_id ? info->subscriber_id : "",
                                    -1, SQLITE_TRANSIENT));
-       DB_ACTION(sqlite3_bind_int64(stmt, 4, info->data_limit));
-       DB_ACTION(sqlite3_bind_int64(stmt, 5, info->data_warn_limit));
-       DB_ACTION(sqlite3_bind_int(stmt, 6, info->rst_state));
-       DB_ACTION(sqlite3_bind_int(stmt, 7, info->roaming));
-       DB_ACTION(sqlite3_bind_text(stmt, 8, info->ifname ? info->ifname : "",
+       DB_ACTION(sqlite3_bind_int(stmt, 4, info->roaming));
+       DB_ACTION(sqlite3_bind_text(stmt, 5, info->ifname ? info->ifname : "",
                                    -1, SQLITE_TRANSIENT));
 
        rc = sqlite3_step(stmt);
@@ -494,12 +529,16 @@ stc_error_e __get_restriction_id(table_restrictions_info *info)
                break;
        case SQLITE_ERROR:
        default:
-               STC_LOGE("Failed to get restriction id: %s\n",
+               STC_LOGE("Failed to get restriction id: %s\n", //LCOV_EXCL_LINE
                         sqlite3_errmsg(stc_db_get_database()));
+               error_code = STC_ERROR_DB_FAILED; //LCOV_EXCL_LINE
        }
 
 handle_error:
-       sqlite3_reset(stmt);
+       rc = sqlite3_reset(stmt);
+       if (rc != SQLITE_OK)
+               error_code = STC_ERROR_DB_FAILED;
+
        __STC_LOG_FUNC_EXIT__;
        return error_code;
 }
@@ -510,8 +549,13 @@ stc_error_e table_restrictions_update(table_restrictions_info *info)
        sqlite3_stmt *stmt = insert_net_restrictions;
 
        if (!info) {
-               error_code = STC_ERROR_INVALID_PARAMETER;
-               goto handle_error;
+               error_code = STC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+               goto handle_error; //LCOV_EXCL_LINE
+       }
+
+       if (__get_restriction_id(info) != STC_ERROR_NONE) {
+               error_code = STC_ERROR_DB_FAILED; //LCOV_EXCL_LINE
+               goto handle_error; //LCOV_EXCL_LINE
        }
 
        if (info->restriction_id)
@@ -521,33 +565,41 @@ stc_error_e table_restrictions_update(table_restrictions_info *info)
                                    -1, SQLITE_TRANSIENT));
        DB_ACTION(sqlite3_bind_int64(stmt, 2, info->data_limit));
        DB_ACTION(sqlite3_bind_int(stmt, 3, info->iftype));
-       DB_ACTION(sqlite3_bind_int(stmt, 4, info->rst_state));
+       DB_ACTION(sqlite3_bind_int(stmt, 4, info->rstn_type));
        DB_ACTION(sqlite3_bind_int(stmt, 5, info->roaming));
        DB_ACTION(sqlite3_bind_text(stmt, 6, info->ifname ? info->ifname : "",
                                    -1, SQLITE_TRANSIENT));
-       DB_ACTION(sqlite3_bind_text(stmt, 7, info->imsi ? info->imsi : "",
+       DB_ACTION(sqlite3_bind_text(stmt, 7, info->subscriber_id ? info->subscriber_id : "",
                                    -1, SQLITE_TRANSIENT));
        DB_ACTION(sqlite3_bind_int64(stmt, 8, info->data_warn_limit));
+       DB_ACTION(sqlite3_bind_int64(stmt, 9, info->monthly_limit));
+       DB_ACTION(sqlite3_bind_int64(stmt, 10, info->weekly_limit));
+       DB_ACTION(sqlite3_bind_int64(stmt, 11, info->daily_limit));
 
        if (info->restriction_id)
-               DB_ACTION(sqlite3_bind_int64(stmt, 11, info->restriction_id));
+               DB_ACTION(sqlite3_bind_int64(stmt, 12, info->restriction_id));
+       else
+               DB_ACTION(sqlite3_bind_int64(stmt, 12, info->month_start_date));
 
        if (sqlite3_step(stmt) != SQLITE_DONE) {
-               STC_LOGE("Failed to set network restriction: %s\n",
+               STC_LOGE("Failed to set network restriction: %s\n", //LCOV_EXCL_LINE
                         sqlite3_errmsg(stc_db_get_database()));
-               error_code = STC_ERROR_DB_FAILED;
-               goto handle_error;
+               error_code = STC_ERROR_DB_FAILED; //LCOV_EXCL_LINE
+               goto handle_error; //LCOV_EXCL_LINE
        }
 
        if (info->restriction_id) {
                STC_LOGD("Restriction updated app_id [%s]", info->app_id);
        } else {
                STC_LOGD("Restriction inserted app_id [%s]", info->app_id);
-               __get_restriction_id(info);
+               if (__get_restriction_id(info) != STC_ERROR_NONE)
+                       error_code = STC_ERROR_DB_FAILED; //LCOV_EXCL_LINE
        }
 
 handle_error:
-       sqlite3_reset(stmt);
+       if (sqlite3_reset(stmt) != SQLITE_OK)
+               error_code = STC_ERROR_DB_FAILED;
+
        return error_code;
 }
 
@@ -558,8 +610,8 @@ stc_error_e table_restrictions_prepare(sqlite3 *db)
        stc_error_e error_code = STC_ERROR_NONE;
 
        if (db == NULL) {
-               __STC_LOG_FUNC_EXIT__;
-               return STC_ERROR_FAIL;
+               __STC_LOG_FUNC_EXIT__; //LCOV_EXCL_LINE
+               return STC_ERROR_FAIL; //LCOV_EXCL_LINE
        }
 
        DB_ACTION(__prepare_delete(db));