[SVACE Issue Fixes]
[platform/core/pim/contacts-service.git] / server / db / ctsvc_db_plugin_profile_helper.c
index 425d22e..7971db7 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Contacts Service
  *
- * Copyright (c) 2010 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ * Copyright (c) 2010 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -16,7 +16,6 @@
  * limitations under the License.
  *
  */
-
 #include "contacts.h"
 #include "ctsvc_internal.h"
 #include "ctsvc_db_schema.h"
@@ -34,7 +33,7 @@ int ctsvc_db_profile_get_value_from_stmt(cts_stmt stmt, contacts_record_h *recor
        char *temp;
        ctsvc_profile_s *profile;
 
-       ret = contacts_record_create(_contacts_profile._uri, (contacts_record_h *)&profile);
+       ret = contacts_record_create(_contacts_profile._uri, (contacts_record_h*)&profile);
        RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "contacts_record_create Fail(%d)", ret);
 
        profile->id = ctsvc_stmt_get_int(stmt, start_count++);
@@ -91,30 +90,32 @@ int ctsvc_db_profile_insert(contacts_record_h record, int contact_id, bool is_my
        int ret;
        cts_stmt stmt = NULL;
        char query[CTS_SQL_MAX_LEN] = {0};
-       ctsvc_profile_s *profile = (ctsvc_profile_s *)record;
+       ctsvc_profile_s *profile = (ctsvc_profile_s*)record;
 
        RETV_IF(NULL == profile->text, CONTACTS_ERROR_NONE);
        RETVM_IF(contact_id <= 0, CONTACTS_ERROR_INVALID_PARAMETER,
-                               "Invalid parameter : contact_id(%d) is mandatory field to insert profile record ", profile->contact_id);
+                       "contact_id(%d) is mandatory field to insert profile record ", profile->contact_id);
        RETVM_IF(0 < profile->id, CONTACTS_ERROR_INVALID_PARAMETER,
-                               "Invalid parameter : id(%d), This record is already inserted", profile->id);
+                       "id(%d), This record is already inserted", profile->id);
 
        snprintf(query, sizeof(query),
-               "INSERT INTO "CTS_TABLE_DATA"(contact_id, is_my_profile, datatype, data3, data4, data5, "
-                               "data6, data7, data8, data9, data10, data11) "
-                               "VALUES(%d, %d, %d, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
-                               contact_id, is_my_profile, CTSVC_DATA_PROFILE);
+                       "INSERT INTO "CTS_TABLE_DATA"(contact_id, is_my_profile, datatype, data3, data4, data5, "
+                       "data6, data7, data8, data9, data10, data11) "
+                       "VALUES(%d, %d, %d, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
+                       contact_id, is_my_profile, CONTACTS_DATA_TYPE_PROFILE);
 
        ret = ctsvc_query_prepare(query, &stmt);
-       RETVM_IF(NULL == stmt, ret, "DB error : ctsvc_query_prepare() Fail(%d)", ret);
+       RETVM_IF(NULL == stmt, ret, "ctsvc_query_prepare() Fail(%d)", ret);
 
        __ctsvc_profile_bind_stmt(stmt, profile, 1);
 
        ret = ctsvc_stmt_step(stmt);
        if (CONTACTS_ERROR_NONE != ret) {
-               CTS_ERR("DB error : ctsvc_stmt_step() Fail(%d)", ret);
+               /* LCOV_EXCL_START */
+               ERR("ctsvc_stmt_step() Fail(%d)", ret);
                ctsvc_stmt_finalize(stmt);
                return ret;
+               /* LCOV_EXCL_STOP */
        }
 
        /* profile->id = ctsvc_db_get_last_insert_id(); */
@@ -133,7 +134,7 @@ int ctsvc_db_profile_update(contacts_record_h record, bool is_my_profile)
 {
        int id;
        int ret = CONTACTS_ERROR_NONE;
-       charset = NULL;
+       char *set = NULL;
        GSList *bind_text = NULL;
        GSList *cursor = NULL;
        ctsvc_profile_s *profile = (ctsvc_profile_s*)record;
@@ -155,11 +156,14 @@ int ctsvc_db_profile_update(contacts_record_h record, bool is_my_profile)
                        ctsvc_set_profile_noti();
        } while (0);
 
-       CTSVC_RECORD_RESET_PROPERTY_FLAGS((ctsvc_record_s *)record);
-       CONTACTS_FREE(set);
+       CTSVC_RECORD_RESET_PROPERTY_FLAGS((ctsvc_record_s*)record);
+       free(set);
+
        if (bind_text) {
-               for (cursor=bind_text;cursor;cursor=cursor->next)
-                       CONTACTS_FREE(cursor->data);
+               for (cursor = bind_text; cursor; cursor = cursor->next) {
+                       free(cursor->data);
+                       cursor->data = NULL;
+               }
                g_slist_free(bind_text);
        }
 
@@ -173,7 +177,7 @@ int ctsvc_db_profile_delete(int id, bool is_my_profile)
        char query[CTS_SQL_MIN_LEN] = {0};
 
        snprintf(query, sizeof(query), "DELETE FROM "CTS_TABLE_DATA" WHERE id = %d AND datatype = %d",
-                       id, CTSVC_DATA_PROFILE);
+                       id, CONTACTS_DATA_TYPE_PROFILE);
 
        ret = ctsvc_query_exec(query);
        RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_query_exec() Fail(%d)", ret);