Fix : set query limit 54/9854/2
authorDonghee Ye <donghee.ye@samsung.com>
Sat, 7 Sep 2013 13:12:20 +0000 (22:12 +0900)
committerGerrit Code Review <gerrit@review.vlan103.tizen.org>
Tue, 17 Sep 2013 06:27:26 +0000 (23:27 -0700)
If you want to set only offset, you should set negative limit

Change-Id: Id7f47c5fb473fce503c97064a3ebcf16cf3d5880

26 files changed:
native/ctsvc_db_plugin_activity.c
native/ctsvc_db_plugin_address.c
native/ctsvc_db_plugin_addressbook.c
native/ctsvc_db_plugin_company.c
native/ctsvc_db_plugin_contact.c
native/ctsvc_db_plugin_email.c
native/ctsvc_db_plugin_event.c
native/ctsvc_db_plugin_extension.c
native/ctsvc_db_plugin_group.c
native/ctsvc_db_plugin_grouprelation.c
native/ctsvc_db_plugin_image.c
native/ctsvc_db_plugin_messenger.c
native/ctsvc_db_plugin_my_profile.c
native/ctsvc_db_plugin_name.c
native/ctsvc_db_plugin_nickname.c
native/ctsvc_db_plugin_note.c
native/ctsvc_db_plugin_number.c
native/ctsvc_db_plugin_person.c
native/ctsvc_db_plugin_phonelog.c
native/ctsvc_db_plugin_profile.c
native/ctsvc_db_plugin_relationship.c
native/ctsvc_db_plugin_sdn.c
native/ctsvc_db_plugin_simple_contact.c
native/ctsvc_db_plugin_speeddial.c
native/ctsvc_db_plugin_url.c
native/ctsvc_db_query.c

index 7beb66b..2ef9bac 100644 (file)
@@ -89,7 +89,7 @@ static int __ctsvc_db_activity_insert_record( contacts_record_h record, int *id
 {
        int ret;
        int activity_id;
-       int contact_id;
+       int addressbook_id;
        cts_stmt stmt = NULL;
        unsigned int count = 0;
        char query[CTS_SQL_MAX_LEN] = {0};
@@ -106,13 +106,19 @@ static int __ctsvc_db_activity_insert_record( contacts_record_h record, int *id
        RETVM_IF(ret, ret, "contacts_svc_begin_trans() Failed(%d)", ret);
 
        snprintf(query, sizeof(query),
-                       "SELECT contact_id from %s WHERE contact_id = %d",
+                       "SELECT addressbook_id from %s WHERE contact_id = %d",
                                CTSVC_DB_VIEW_CONTACT, activity->contact_id);
-       ret = ctsvc_query_get_first_int_result(query, &contact_id);
+       ret = ctsvc_query_get_first_int_result(query, &addressbook_id);
        if (CONTACTS_ERROR_NONE != ret ) {
-               CTS_ERR("No data : contact id (%d)", activity->contact_id);
                ctsvc_end_trans(false);
-               return CONTACTS_ERROR_INVALID_PARAMETER;
+               if (CONTACTS_ERROR_NO_DATA) {
+                       CTS_ERR("No data : contact id (%d)", activity->contact_id);
+                       return CONTACTS_ERROR_INVALID_PARAMETER;
+               }
+               else {
+                       CTS_ERR("ctsvc_query_get_first_int_result Fail(%d)", ret);
+                       return ret;
+               }
        }
 
        snprintf(query, sizeof(query), "INSERT INTO "CTS_TABLE_ACTIVITIES"("
@@ -346,7 +352,7 @@ static int __ctsvc_db_activity_get_all_records( int offset, int limit,
        len = snprintf(query, sizeof(query),
                        "SELECT id FROM "CTSVC_DB_VIEW_ACTIVITY);
 
-       if (0 < limit) {
+       if (0 != limit) {
                len += snprintf(query+len, sizeof(query)-len, " LIMIT %d", limit);
                if (0 < offset)
                        len += snprintf(query+len, sizeof(query)-len, " OFFSET %d", offset);
index e82de9c..efa024c 100644 (file)
@@ -30,7 +30,6 @@
 #include "ctsvc_list.h"
 #include "ctsvc_notification.h"
 
-
 static int __ctsvc_db_address_insert_record( contacts_record_h record, int *id );
 static int __ctsvc_db_address_get_record( int id, contacts_record_h* out_record );
 static int __ctsvc_db_address_update_record( contacts_record_h record );
@@ -61,7 +60,7 @@ ctsvc_db_plugin_info_s ctsvc_db_plugin_address = {
 static int __ctsvc_db_address_insert_record( contacts_record_h record, int *id )
 {
        int ret;
-       int contact_id;
+       int addressbook_id;
        char query[CTS_SQL_MAX_LEN] = {0};
        ctsvc_address_s *address = (ctsvc_address_s*)record;
 
@@ -77,12 +76,18 @@ static int __ctsvc_db_address_insert_record( contacts_record_h record, int *id )
        }
 
        snprintf(query, sizeof(query),
-                       "SELECT contact_id FROM "CTSVC_DB_VIEW_CONTACT" WHERE contact_id = %d", address->contact_id);
-       ret = ctsvc_query_get_first_int_result(query, &contact_id);
+                       "SELECT addressbook_id FROM "CTSVC_DB_VIEW_CONTACT" WHERE contact_id = %d", address->contact_id);
+       ret = ctsvc_query_get_first_int_result(query, &addressbook_id);
        if (CONTACTS_ERROR_NONE != ret) {
-               CTS_ERR("No data : contact_id (%d) is not exist", contact_id);
                ctsvc_end_trans(false);
-               return CONTACTS_ERROR_INVALID_PARAMETER;
+               if (CONTACTS_ERROR_NO_DATA) {
+                       CTS_ERR("No data : contact_id (%d) is not exist", address->contact_id);
+                       return CONTACTS_ERROR_INVALID_PARAMETER;
+               }
+               else {
+                       CTS_ERR("ctsvc_query_get_first_int_result Fail(%d)", ret);
+                       return ret;
+               }
        }
 
        ret = ctsvc_db_address_insert(record, address->contact_id, false, id);
@@ -110,7 +115,7 @@ static int __ctsvc_db_address_insert_record( contacts_record_h record, int *id )
 static int __ctsvc_db_address_update_record( contacts_record_h record )
 {
        int ret;
-       int contact_id;
+       int addressbook_id;
        char query[CTS_SQL_MAX_LEN] = {0};
        ctsvc_address_s *address = (ctsvc_address_s*)record;
 
@@ -125,9 +130,8 @@ static int __ctsvc_db_address_update_record( contacts_record_h record )
        }
 
        snprintf(query, sizeof(query),
-                       "SELECT contact_id FROM "CTSVC_DB_VIEW_CONTACT" WHERE contact_id = %d", address->contact_id);
-
-       ret = ctsvc_query_get_first_int_result(query, &contact_id);
+                       "SELECT addressbook_id FROM "CTSVC_DB_VIEW_CONTACT" WHERE contact_id = %d", address->contact_id);
+       ret = ctsvc_query_get_first_int_result(query, &addressbook_id);
        if (CONTACTS_ERROR_NONE != ret) {
                CTS_ERR("No data : contact_id (%d) is not exist", address->contact_id);
                ctsvc_end_trans(false);
@@ -247,7 +251,7 @@ static int __ctsvc_db_address_get_all_records( int offset, int limit, contacts_l
                                                "ON "CTS_TABLE_DATA".contact_id = "CTSVC_DB_VIEW_CONTACT".contact_id "
                                                "WHERE datatype=%d AND is_my_profile=0 ",
                                                CTSVC_DATA_POSTAL);
-       if (0 < limit) {
+       if (0 != limit) {
                len += snprintf(query+len, sizeof(query)-len, " LIMIT %d", limit);
                if (0 < offset)
                        len += snprintf(query+len, sizeof(query)-len, " OFFSET %d", offset);
index ab32cdb..3f72455 100644 (file)
@@ -102,7 +102,10 @@ static int __ctsvc_db_addressbook_get_record( int id, contacts_record_h* out_rec
        if (1 /*CTS_TRUE*/ != ret) {
                CTS_ERR("cts_stmt_step() Failed(%d)", ret);
                cts_stmt_finalize(stmt);
-               return CONTACTS_ERROR_NO_DATA;
+               if (CONTACTS_ERROR_NONE == ret)
+                       return CONTACTS_ERROR_NO_DATA;
+               else
+                       return ret;
        }
 
        ret = __ctsvc_db_addressbook_value_set(stmt, &record);
@@ -440,9 +443,9 @@ static int __ctsvc_db_addressbook_get_all_records( int offset, int limit,
 
        len = snprintf(query, sizeof(query),
                                "SELECT addressbook_id, addressbook_name, account_id, mode, last_sync_ver "
-                                "FROM "CTS_TABLE_ADDRESSBOOKS" ORDER BY account_id, addressbook_id");
+                               "FROM "CTS_TABLE_ADDRESSBOOKS" ORDER BY account_id, addressbook_id");
 
-       if (0 < limit) {
+       if (0 != limit) {
                len += snprintf(query+len, sizeof(query)-len, " LIMIT %d", limit);
                if (0 < offset)
                        len += snprintf(query+len, sizeof(query)-len, " OFFSET %d", offset);
index 9f118a6..adab635 100644 (file)
@@ -96,7 +96,7 @@ static int __ctsvc_db_company_get_record( int id, contacts_record_h* out_record
 static int __ctsvc_db_company_insert_record( contacts_record_h record, int *id )
 {
        int ret;
-       int contact_id;
+       int addressbook_id;
        char query[CTS_SQL_MAX_LEN] = {0};
        ctsvc_company_s *company = (ctsvc_company_s *)record;
 
@@ -112,12 +112,18 @@ static int __ctsvc_db_company_insert_record( contacts_record_h record, int *id )
        }
 
        snprintf(query, sizeof(query),
-                       "SELECT contact_id FROM "CTSVC_DB_VIEW_CONTACT" WHERE contact_id = %d", company->contact_id);
-       ret = ctsvc_query_get_first_int_result(query, &contact_id);
+                       "SELECT addressbook_id FROM "CTSVC_DB_VIEW_CONTACT" WHERE contact_id = %d", company->contact_id);
+       ret = ctsvc_query_get_first_int_result(query, &addressbook_id);
        if (CONTACTS_ERROR_NONE != ret) {
-               CTS_ERR("No data : contact_id (%d) is not exist", contact_id);
                ctsvc_end_trans(false);
-               return CONTACTS_ERROR_INVALID_PARAMETER;
+               if (CONTACTS_ERROR_NO_DATA) {
+                       CTS_ERR("No data : contact_id (%d) is not exist", company->contact_id);
+                       return CONTACTS_ERROR_INVALID_PARAMETER;
+               }
+               else {
+                       CTS_ERR("ctsvc_query_get_first_int_result Fail(%d)", ret);
+                       return ret;
+               }
        }
 
        ret = ctsvc_db_company_insert(record, company->contact_id, false, id);
@@ -150,7 +156,7 @@ static int __ctsvc_db_company_insert_record( contacts_record_h record, int *id )
 static int __ctsvc_db_company_update_record( contacts_record_h record )
 {
        int ret;
-       int contact_id;
+       int addressbook_id;
        char query[CTS_SQL_MAX_LEN] = {0};
        ctsvc_company_s *company = (ctsvc_company_s *)record;
 
@@ -166,8 +172,8 @@ static int __ctsvc_db_company_update_record( contacts_record_h record )
        }
 
        snprintf(query, sizeof(query),
-                       "SELECT contact_id FROM "CTSVC_DB_VIEW_CONTACT" WHERE contact_id = %d", company->contact_id);
-       ret = ctsvc_query_get_first_int_result(query, &contact_id);
+                       "SELECT addressbook_id FROM "CTSVC_DB_VIEW_CONTACT" WHERE contact_id = %d", company->contact_id);
+       ret = ctsvc_query_get_first_int_result(query, &addressbook_id);
        if (CONTACTS_ERROR_NONE != ret) {
                CTS_ERR("No data : contact_id (%d) is not exist", company->contact_id);
                ctsvc_end_trans(false);
@@ -267,7 +273,7 @@ static int __ctsvc_db_company_get_all_records( int offset, int limit, contacts_l
                                "ON "CTS_TABLE_DATA".contact_id = "CTSVC_DB_VIEW_CONTACT".contact_id "
                                "WHERE datatype=%d AND is_my_profile=0 ",
                                CTSVC_DATA_COMPANY);
-       if (0 < limit) {
+       if (0 != limit) {
                len += snprintf(query+len, sizeof(query)-len, " LIMIT %d", limit);
                if (0 < offset)
                        len += snprintf(query+len, sizeof(query)-len, " OFFSET %d", offset);
index 5441977..467d564 100644 (file)
@@ -1344,7 +1344,7 @@ static int __ctsvc_db_contact_get_all_records( int offset, int limit, contacts_l
        len = snprintf(query, sizeof(query),
                        "SELECT contact_id FROM "CTS_TABLE_CONTACTS" WHERE deleted = 0");
 
-       if (0 < limit) {
+       if (0 != limit) {
                len += snprintf(query+len, sizeof(query)-len, " LIMIT %d", limit);
                if (0 < offset)
                        len += snprintf(query+len, sizeof(query)-len, " OFFSET %d", offset);
index a0616b1..07f84e0 100644 (file)
@@ -175,7 +175,7 @@ static int __ctsvc_db_email_set_primary_default(int email_id, bool is_primary_de
 static int __ctsvc_db_email_insert_record( contacts_record_h record, int *id )
 {
        int ret;
-       int contact_id = 0;
+       int addressbook_id = 0;
        int person_id = 0;
        int old_default_email_id = 0;
        char query[CTS_SQL_MAX_LEN] = {0};
@@ -191,7 +191,7 @@ static int __ctsvc_db_email_insert_record( contacts_record_h record, int *id )
        }
 
        snprintf(query, sizeof(query),
-                       "SELECT contact_id, person_id FROM "CTSVC_DB_VIEW_CONTACT" WHERE contact_id = %d", email->contact_id);
+                       "SELECT addressbook_id, person_id FROM "CTSVC_DB_VIEW_CONTACT" WHERE contact_id = %d", email->contact_id);
        stmt = cts_query_prepare(query);
        if (NULL == stmt) {
                CTS_ERR("DB error : cts_query_prepare() Failed");
@@ -204,9 +204,12 @@ static int __ctsvc_db_email_insert_record( contacts_record_h record, int *id )
                CTS_ERR("DB error : cts_stmt_step() Failed(%d)", ret);
                cts_stmt_finalize(stmt);
                ctsvc_end_trans(false);
-               return CONTACTS_ERROR_INVALID_PARAMETER;
+               if (CONTACTS_ERROR_NO_DATA)
+                       return CONTACTS_ERROR_INVALID_PARAMETER;
+               else
+                       return ret;
        }
-       contact_id = ctsvc_stmt_get_int(stmt, 0);
+       addressbook_id = ctsvc_stmt_get_int(stmt, 0);
        person_id = ctsvc_stmt_get_int(stmt, 1);
        cts_stmt_finalize(stmt);
 
@@ -239,12 +242,12 @@ static int __ctsvc_db_email_insert_record( contacts_record_h record, int *id )
                __ctsvc_db_email_update_person_has_email(person_id, true);
 
                primary_default_contact_id = __ctsvc_db_email_get_primary_default_contact_id(person_id);
-               __ctsvc_db_email_reset_default(*id, contact_id);
+               __ctsvc_db_email_reset_default(*id, email->contact_id);
 
-               if (0 == primary_default_contact_id || contact_id == primary_default_contact_id)
+               if (0 == primary_default_contact_id || email->contact_id == primary_default_contact_id)
                        __ctsvc_db_email_set_primary_default(*id, true);
 
-               ctsvc_contact_update_display_name(contact_id, CONTACTS_DISPLAY_NAME_SOURCE_TYPE_EMAIL);
+               ctsvc_contact_update_display_name(email->contact_id, CONTACTS_DISPLAY_NAME_SOURCE_TYPE_EMAIL);
        }
 
        ctsvc_set_contact_noti();
@@ -297,7 +300,7 @@ static int __ctsvc_db_email_get_record( int id, contacts_record_h* out_record )
 static int __ctsvc_db_email_update_record( contacts_record_h record )
 {
        int ret;
-       int contact_id;
+       int addressbook_id;
        char query[CTS_SQL_MAX_LEN] = {0};
        ctsvc_email_s *email = (ctsvc_email_s *)record;
        RETVM_IF(NULL == email->email_addr, CONTACTS_ERROR_INVALID_PARAMETER, "email is empty");
@@ -309,8 +312,8 @@ static int __ctsvc_db_email_update_record( contacts_record_h record )
        }
 
        snprintf(query, sizeof(query),
-                       "SELECT contact_id FROM "CTSVC_DB_VIEW_CONTACT" WHERE contact_id = %d", email->contact_id);
-       ret = ctsvc_query_get_first_int_result(query, &contact_id);
+                       "SELECT addressbook_id FROM "CTSVC_DB_VIEW_CONTACT" WHERE contact_id = %d", email->contact_id);
+       ret = ctsvc_query_get_first_int_result(query, &addressbook_id);
        if (CONTACTS_ERROR_NONE != ret) {
                CTS_ERR("No data : contact_id (%d) is not exist", email->contact_id);
                ctsvc_end_trans(false);
@@ -327,13 +330,13 @@ static int __ctsvc_db_email_update_record( contacts_record_h record )
        if (email->is_default) {
                int old_primary_default_email_id = 0;
 
-               old_primary_default_email_id = __ctsvc_db_email_get_primary_default_email_id(contact_id);
-               __ctsvc_db_email_reset_default(email->id, contact_id);
+               old_primary_default_email_id = __ctsvc_db_email_get_primary_default_email_id(email->contact_id);
+               __ctsvc_db_email_reset_default(email->id, email->contact_id);
 
                if (old_primary_default_email_id)
                        __ctsvc_db_email_set_primary_default(email->id, true);
        }
-       ctsvc_contact_update_display_name(contact_id, CONTACTS_DISPLAY_NAME_SOURCE_TYPE_EMAIL);
+       ctsvc_contact_update_display_name(email->contact_id, CONTACTS_DISPLAY_NAME_SOURCE_TYPE_EMAIL);
 
        ret = ctsvc_db_contact_update_changed_time(email->contact_id);
        if (CONTACTS_ERROR_NONE != ret) {
@@ -387,7 +390,10 @@ static int __ctsvc_db_email_delete_record( int id )
                CTS_ERR("DB error : cts_stmt_step() Failed(%d)", ret);
                cts_stmt_finalize(stmt);
                ctsvc_end_trans(false);
-               return CONTACTS_ERROR_NO_DATA;
+               if (CONTACTS_ERROR_NONE == ret)
+                       return CONTACTS_ERROR_NO_DATA;
+               else
+                       return ret;
        }
        contact_id = ctsvc_stmt_get_int(stmt, 0);
        person_id = ctsvc_stmt_get_int(stmt, 1);
@@ -475,7 +481,7 @@ static int __ctsvc_db_email_get_all_records( int offset, int limit, contacts_lis
                                "ON "CTS_TABLE_DATA".contact_id = "CTSVC_DB_VIEW_CONTACT".contact_id "
                                "WHERE datatype = %d AND is_my_profile=0 ",
                                CTSVC_DATA_EMAIL);
-       if (0 < limit) {
+       if (0 != limit) {
                len += snprintf(query+len, sizeof(query)-len, " LIMIT %d", limit);
                if (0 < offset)
                        len += snprintf(query+len, sizeof(query)-len, " OFFSET %d", offset);
index 71ec513..53f3f5c 100644 (file)
@@ -60,7 +60,7 @@ ctsvc_db_plugin_info_s ctsvc_db_plugin_event = {
 static int __ctsvc_db_event_insert_record( contacts_record_h record, int *id )
 {
        int ret;
-       int contact_id;
+       int addressbook_id;
        char query[CTS_SQL_MAX_LEN] = {0};
        ctsvc_event_s *event = (ctsvc_event_s *)record;
 
@@ -74,12 +74,18 @@ static int __ctsvc_db_event_insert_record( contacts_record_h record, int *id )
        }
 
        snprintf(query, sizeof(query),
-                       "SELECT contact_id FROM "CTSVC_DB_VIEW_CONTACT" WHERE contact_id = %d", event->contact_id);
-       ret = ctsvc_query_get_first_int_result(query, &contact_id);
+                       "SELECT addressbook_id FROM "CTSVC_DB_VIEW_CONTACT" WHERE contact_id = %d", event->contact_id);
+       ret = ctsvc_query_get_first_int_result(query, &addressbook_id);
        if (CONTACTS_ERROR_NONE != ret) {
-               CTS_ERR("No data : contact_id (%d) is not exist", contact_id);
                ctsvc_end_trans(false);
-               return CONTACTS_ERROR_INVALID_PARAMETER;
+               if (CONTACTS_ERROR_NO_DATA) {
+                       CTS_ERR("No data : contact_id (%d) is not exist", event->contact_id);
+                       return CONTACTS_ERROR_INVALID_PARAMETER;
+               }
+               else {
+                       CTS_ERR("ctsvc_query_get_first_int_result Fail(%d)", ret);
+                       return ret;
+               }
        }
 
        ret = ctsvc_db_event_insert(record, event->contact_id, false, id);
@@ -144,7 +150,7 @@ static int __ctsvc_db_event_get_record( int id, contacts_record_h* out_record )
 static int __ctsvc_db_event_update_record( contacts_record_h record )
 {
        int ret;
-       int contact_id;
+       int addressbook_id;
        char query[CTS_SQL_MAX_LEN] = {0};
        ctsvc_event_s *event = (ctsvc_event_s *)record;
 
@@ -155,8 +161,8 @@ static int __ctsvc_db_event_update_record( contacts_record_h record )
        }
 
        snprintf(query, sizeof(query),
-                       "SELECT contact_id FROM "CTSVC_DB_VIEW_CONTACT" WHERE contact_id = %d", event->contact_id);
-       ret = ctsvc_query_get_first_int_result(query, &contact_id);
+                       "SELECT addressbook_id FROM "CTSVC_DB_VIEW_CONTACT" WHERE contact_id = %d", event->contact_id);
+       ret = ctsvc_query_get_first_int_result(query, &addressbook_id);
        if (CONTACTS_ERROR_NONE != ret) {
                CTS_ERR("No data : contact_id (%d) is not exist", event->contact_id);
                ctsvc_end_trans(false);
@@ -251,7 +257,7 @@ static int __ctsvc_db_event_get_all_records( int offset, int limit, contacts_lis
                                "ON "CTS_TABLE_DATA".contact_id = "CTSVC_DB_VIEW_CONTACT".contact_id "
                                "WHERE datatype = %d AND is_my_profile=0 ",
                                CTSVC_DATA_EVENT);
-       if (0 < limit) {
+       if (0 != limit) {
                len += snprintf(query+len, sizeof(query)-len, " LIMIT %d", limit);
                if (0 < offset)
                        len += snprintf(query+len, sizeof(query)-len, " OFFSET %d", offset);
index fb9d9fa..0d2c38f 100644 (file)
@@ -60,7 +60,7 @@ ctsvc_db_plugin_info_s ctsvc_db_plugin_extension = {
 static int __ctsvc_db_extension_insert_record( contacts_record_h record, int *id )
 {
        int ret;
-       int contact_id;
+       int addressbook_id;
        char query[CTS_SQL_MAX_LEN] = {0};
        ctsvc_extension_s *extension = (ctsvc_extension_s *)record;
 
@@ -77,12 +77,18 @@ static int __ctsvc_db_extension_insert_record( contacts_record_h record, int *id
        }
 
        snprintf(query, sizeof(query),
-                       "SELECT contact_id FROM "CTSVC_DB_VIEW_CONTACT" WHERE contact_id = %d", extension->contact_id);
-       ret = ctsvc_query_get_first_int_result(query, &contact_id);
+                       "SELECT addressbook_id FROM "CTSVC_DB_VIEW_CONTACT" WHERE contact_id = %d", extension->contact_id);
+       ret = ctsvc_query_get_first_int_result(query, &addressbook_id);
        if (CONTACTS_ERROR_NONE != ret) {
-               CTS_ERR("No data : contact_id (%d) is not exist", contact_id);
                ctsvc_end_trans(false);
-               return CONTACTS_ERROR_INVALID_PARAMETER;
+               if (CONTACTS_ERROR_NO_DATA) {
+                       CTS_ERR("No data : contact_id (%d) is not exist", extension->contact_id);
+                       return CONTACTS_ERROR_INVALID_PARAMETER;
+               }
+               else {
+                       CTS_ERR("ctsvc_query_get_first_int_result Fail(%d)", ret);
+                       return ret;
+               }
        }
 
        ret = ctsvc_db_extension_insert(record, extension->contact_id, false, id);
@@ -148,7 +154,7 @@ static int __ctsvc_db_extension_get_record( int id, contacts_record_h* out_recor
 static int __ctsvc_db_extension_update_record( contacts_record_h record )
 {
        int ret;
-       int contact_id;
+       int addressbook_id;
        char query[CTS_SQL_MAX_LEN] = {0};
        ctsvc_extension_s *extension = (ctsvc_extension_s *)record;
 
@@ -164,8 +170,8 @@ static int __ctsvc_db_extension_update_record( contacts_record_h record )
        }
 
        snprintf(query, sizeof(query),
-                       "SELECT contact_id FROM "CTSVC_DB_VIEW_CONTACT" WHERE contact_id = %d", extension->contact_id);
-       ret = ctsvc_query_get_first_int_result(query, &contact_id);
+                       "SELECT addressbook_id FROM "CTSVC_DB_VIEW_CONTACT" WHERE contact_id = %d", extension->contact_id);
+       ret = ctsvc_query_get_first_int_result(query, &addressbook_id);
        if (CONTACTS_ERROR_NONE != ret) {
                CTS_ERR("No data : contact_id (%d) is not exist", extension->contact_id);
                ctsvc_end_trans(false);
@@ -260,7 +266,7 @@ static int __ctsvc_db_extension_get_all_records( int offset, int limit, contacts
                                "ON "CTS_TABLE_DATA".contact_id = "CTSVC_DB_VIEW_CONTACT".contact_id "
                                "WHERE datatype = %d AND is_my_profile=0 ",
                                CTSVC_DATA_EXTENSION);
-       if (0 < limit) {
+       if (0 != limit) {
                len += snprintf(query+len, sizeof(query)-len, " LIMIT %d", limit);
                if (0 < offset)
                        len += snprintf(query+len, sizeof(query)-len, " OFFSET %d", offset);
index 2687c80..23adb68 100644 (file)
@@ -499,7 +499,7 @@ static int __ctsvc_db_group_get_all_records( int offset, int limit, contacts_lis
                                "ringtone_path, vibration, image_thumbnail_path "
                                "FROM "CTS_TABLE_GROUPS" ORDER BY addressbook_id, group_prio");
 
-       if (0 < limit) {
+       if (0 != limit) {
                len += snprintf(query+len, sizeof(query)-len, " LIMIT %d", limit);
                if (0 < offset)
                        len += snprintf(query+len, sizeof(query)-len, " OFFSET %d", offset);
index 851f152..7e639f8 100644 (file)
@@ -62,7 +62,7 @@ static int __ctsvc_db_grouprelation_insert_record( contacts_record_h record, int
 
 static int __ctsvc_db_grouprelation_get_record( int id, contacts_record_h* out_record )
 {
-       CTS_ERR("Not support update group-relation");
+       CTS_ERR("Not support get group-relation");
        return CONTACTS_ERROR_INVALID_PARAMETER;
 }
 
@@ -90,7 +90,7 @@ static int __ctsvc_db_grouprelation_get_all_records( int offset, int limit, cont
 
        len = snprintf(query, sizeof(query),
                        "SELECT group_id, contact_id, group_name FROM "CTSVC_DB_VIEW_GROUP_RELATION);
-       if (0 < limit) {
+       if (0 != limit) {
                len += snprintf(query+len, sizeof(query)-len, " LIMIT %d", limit);
                if (0 < offset)
                        len += snprintf(query+len, sizeof(query)-len, " OFFSET %d", offset);
index 2d5b5a5..32c69bf 100644 (file)
@@ -184,7 +184,7 @@ static int __ctsvc_db_image_insert_record( contacts_record_h record, int *id )
        int len = 0;
        int ret;
        int version;
-       int contact_id;
+       int addressbook_id;
        int person_id;
        int old_default_image_id;
        char query[CTS_SQL_MAX_LEN] = {0};
@@ -201,7 +201,7 @@ static int __ctsvc_db_image_insert_record( contacts_record_h record, int *id )
        }
 
        snprintf(query, sizeof(query),
-                       "SELECT contact_id, person_id FROM "CTSVC_DB_VIEW_CONTACT" WHERE contact_id = %d", image->contact_id);
+                       "SELECT addressbook_id, person_id FROM "CTSVC_DB_VIEW_CONTACT" WHERE contact_id = %d", image->contact_id);
        stmt = cts_query_prepare(query);
        if (NULL == stmt) {
                CTS_ERR("DB error : cts_query_prepare() Failed");
@@ -214,9 +214,13 @@ static int __ctsvc_db_image_insert_record( contacts_record_h record, int *id )
                CTS_ERR("DB error : cts_stmt_step() Failed(%d)", ret);
                cts_stmt_finalize(stmt);
                ctsvc_end_trans(false);
-               return CONTACTS_ERROR_NO_DATA;
+               if (ret == CONTACTS_ERROR_NONE)
+                       return CONTACTS_ERROR_INVALID_PARAMETER;
+               else
+                       return ret;
        }
-       contact_id = ctsvc_stmt_get_int(stmt, 0);
+
+       addressbook_id = ctsvc_stmt_get_int(stmt, 0);
        person_id = ctsvc_stmt_get_int(stmt, 1);
        cts_stmt_finalize(stmt);
 
@@ -258,9 +262,9 @@ static int __ctsvc_db_image_insert_record( contacts_record_h record, int *id )
                int primary_default_contact_id;
 
                primary_default_contact_id = __ctsvc_db_image_get_primary_default_contact_id(person_id);
-               ctsvc_db_image_reset_default(*id, contact_id);
+               ctsvc_db_image_reset_default(*id, image->contact_id);
 
-               if (primary_default_contact_id == 0 || primary_default_contact_id == contact_id) {
+               if (primary_default_contact_id == 0 || primary_default_contact_id == image->contact_id) {
                        __ctsvc_db_image_set_primary_default(*id, true);
                        __ctsvc_db_image_update_person_image(person_id, image->path);
                }
@@ -318,8 +322,8 @@ static int __ctsvc_db_image_update_record( contacts_record_h record )
        int len = 0;
        int ret;
        int version;
-       int contact_id;
        int person_id;
+       int addressbook_id;
        char query[CTS_SQL_MAX_LEN] = {0};
        ctsvc_image_s *image = (ctsvc_image_s *)record;
        cts_stmt stmt = NULL;
@@ -332,8 +336,7 @@ static int __ctsvc_db_image_update_record( contacts_record_h record )
        }
 
        snprintf(query, sizeof(query),
-                       "SELECT contact_id, person_id FROM "CTSVC_DB_VIEW_CONTACT" WHERE contact_id = %d", image->contact_id);
-
+                       "SELECT addressbook_id, person_id FROM "CTSVC_DB_VIEW_CONTACT" WHERE contact_id = %d", image->contact_id);
        stmt = cts_query_prepare(query);
        if (NULL == stmt) {
                CTS_ERR("DB error : cts_query_prepare() Failed");
@@ -348,7 +351,7 @@ static int __ctsvc_db_image_update_record( contacts_record_h record )
                ctsvc_end_trans(false);
                return CONTACTS_ERROR_NO_DATA;
        }
-       contact_id = ctsvc_stmt_get_int(stmt, 0);
+       addressbook_id = ctsvc_stmt_get_int(stmt, 0);
        person_id = ctsvc_stmt_get_int(stmt, 1);
        cts_stmt_finalize(stmt);
 
@@ -385,10 +388,10 @@ static int __ctsvc_db_image_update_record( contacts_record_h record )
        if (image->is_default) {
                int primary_default_contact_id;
 
-               primary_default_contact_id = __ctsvc_db_image_get_primary_default_contact_id(contact_id);
-               ctsvc_db_image_reset_default(image->id, contact_id);
+               primary_default_contact_id = __ctsvc_db_image_get_primary_default_contact_id(image->contact_id);
+               ctsvc_db_image_reset_default(image->id, image->contact_id);
 
-               if (contact_id == primary_default_contact_id) {
+               if (image->contact_id == primary_default_contact_id) {
                        __ctsvc_db_image_set_primary_default(image->id, true);
                        __ctsvc_db_image_update_person_image(person_id, image->path);
                }
@@ -542,7 +545,7 @@ static int __ctsvc_db_image_get_all_records( int offset, int limit, contacts_lis
                                "ON "CTS_TABLE_DATA".contact_id = "CTSVC_DB_VIEW_CONTACT".contact_id "
                                "WHERE datatype = %d AND is_my_profile=0 ",
                                CTSVC_DATA_IMAGE);
-       if (0 < limit) {
+       if (0 != limit) {
                len += snprintf(query+len, sizeof(query)-len, " LIMIT %d", limit);
                if (0 < offset)
                        len += snprintf(query+len, sizeof(query)-len, " OFFSET %d", offset);
index f88a42e..de10741 100644 (file)
@@ -59,7 +59,7 @@ ctsvc_db_plugin_info_s ctsvc_db_plugin_messenger = {
 static int __ctsvc_db_messenger_insert_record( contacts_record_h record, int *id )
 {
        int ret;
-       int contact_id;
+       int addressbook_id;
        char query[CTS_SQL_MAX_LEN] = {0};
        ctsvc_messenger_s *messenger = (ctsvc_messenger_s *)record;
 
@@ -73,12 +73,18 @@ static int __ctsvc_db_messenger_insert_record( contacts_record_h record, int *id
        }
 
        snprintf(query, sizeof(query),
-                       "SELECT contact_id FROM "CTSVC_DB_VIEW_CONTACT" WHERE contact_id = %d", messenger->contact_id);
-       ret = ctsvc_query_get_first_int_result(query, &contact_id);
+                       "SELECT addressbook_id FROM "CTSVC_DB_VIEW_CONTACT" WHERE contact_id = %d", messenger->contact_id);
+       ret = ctsvc_query_get_first_int_result(query, &addressbook_id);
        if (CONTACTS_ERROR_NONE != ret) {
-               CTS_ERR("No data : contact_id (%d) is not exist", contact_id);
                ctsvc_end_trans(false);
-               return CONTACTS_ERROR_INVALID_PARAMETER;
+               if (CONTACTS_ERROR_NO_DATA) {
+                       CTS_ERR("No data : contact_id (%d) is not exist", messenger->contact_id);
+                       return CONTACTS_ERROR_INVALID_PARAMETER;
+               }
+               else {
+                       CTS_ERR("ctsvc_query_get_first_int_result Fail(%d)", ret);
+                       return ret;
+               }
        }
 
        ret = ctsvc_db_messenger_insert(record, messenger->contact_id, false, id);
@@ -143,7 +149,7 @@ static int __ctsvc_db_messenger_get_record( int id, contacts_record_h* out_recor
 static int __ctsvc_db_messenger_update_record( contacts_record_h record )
 {
        int ret;
-       int contact_id;
+       int addressbook_id;
        char query[CTS_SQL_MAX_LEN] = {0};
        ctsvc_messenger_s *messenger = (ctsvc_messenger_s *)record;
        RETVM_IF(NULL == messenger->im_id, CONTACTS_ERROR_INVALID_PARAMETER, "im_id is empty");
@@ -155,8 +161,8 @@ static int __ctsvc_db_messenger_update_record( contacts_record_h record )
        }
 
        snprintf(query, sizeof(query),
-                       "SELECT contact_id FROM "CTSVC_DB_VIEW_CONTACT" WHERE contact_id = %d", messenger->contact_id);
-       ret = ctsvc_query_get_first_int_result(query, &contact_id);
+                       "SELECT addressbook_id FROM "CTSVC_DB_VIEW_CONTACT" WHERE contact_id = %d", messenger->contact_id);
+       ret = ctsvc_query_get_first_int_result(query, &addressbook_id);
        if (CONTACTS_ERROR_NONE != ret) {
                CTS_ERR("No data : contact_id (%d) is not exist", messenger->contact_id);
                ctsvc_end_trans(false);
@@ -250,7 +256,7 @@ static int __ctsvc_db_messenger_get_all_records( int offset, int limit, contacts
                                "ON "CTS_TABLE_DATA".contact_id = "CTSVC_DB_VIEW_CONTACT".contact_id "
                                "WHERE datatype = %d AND is_my_profile=0 ",
                                CTSVC_DATA_MESSENGER);
-       if (0 < limit) {
+       if (0 != limit) {
                len += snprintf(query+len, sizeof(query)-len, " LIMIT %d", limit);
                if (0 < offset)
                        len += snprintf(query+len, sizeof(query)-len, " OFFSET %d", offset);
index 050d98b..031a375 100644 (file)
@@ -802,7 +802,7 @@ static int __ctsvc_db_my_profile_get_all_records( int offset, int limit, contact
        len = snprintf(query, sizeof(query),
                        "SELECT my_profile_id FROM "CTSVC_DB_VIEW_MY_PROFILE);
 
-       if (0 < limit) {
+       if (0 != limit) {
                len += snprintf(query+len, sizeof(query)-len, " LIMIT %d", limit);
                if (0 < offset)
                        len += snprintf(query+len, sizeof(query)-len, " OFFSET %d", offset);
index dcdb349..0e88316 100644 (file)
@@ -62,7 +62,7 @@ static int __ctsvc_db_name_insert_record( contacts_record_h record, int *id )
 {
        int ret;
        int name_id = 0;
-       int contact_id;
+       int addressbook_id;
        char query[CTS_SQL_MAX_LEN] = {0};
        ctsvc_name_s *name = (ctsvc_name_s *)record;
 
@@ -73,12 +73,18 @@ static int __ctsvc_db_name_insert_record( contacts_record_h record, int *id )
        }
 
        snprintf(query, sizeof(query),
-                       "SELECT contact_id FROM "CTSVC_DB_VIEW_CONTACT" WHERE contact_id = %d", name->contact_id);
-       ret = ctsvc_query_get_first_int_result(query, &contact_id);
+                       "SELECT addressbook_id FROM "CTSVC_DB_VIEW_CONTACT" WHERE contact_id = %d", name->contact_id);
+       ret = ctsvc_query_get_first_int_result(query, &addressbook_id);
        if (CONTACTS_ERROR_NONE != ret) {
-               CTS_ERR("No data : contact_id (%d) is not exist", contact_id);
                ctsvc_end_trans(false);
-               return CONTACTS_ERROR_INVALID_PARAMETER;
+               if (CONTACTS_ERROR_NO_DATA == ret) {
+                       CTS_ERR("No data : contact_id (%d) is not exist", name->contact_id);
+                       return CONTACTS_ERROR_INVALID_PARAMETER;
+               }
+               else {
+                       CTS_ERR("ctsvc_query_get_first_int_result Fail(%d)", ret);
+                       return ret;
+               }
        }
 
        snprintf(query, sizeof(query),
@@ -154,7 +160,7 @@ static int __ctsvc_db_name_get_record( int id, contacts_record_h* out_record )
 static int __ctsvc_db_name_update_record( contacts_record_h record )
 {
        int ret;
-       int contact_id;
+       int addressbook_id;
        char query[CTS_SQL_MAX_LEN] = {0};
        ctsvc_name_s *name = (ctsvc_name_s *)record;
 
@@ -169,8 +175,8 @@ static int __ctsvc_db_name_update_record( contacts_record_h record )
        }
 
        snprintf(query, sizeof(query),
-                       "SELECT contact_id FROM "CTSVC_DB_VIEW_CONTACT" WHERE contact_id = %d", name->contact_id);
-       ret = ctsvc_query_get_first_int_result(query, &contact_id);
+                       "SELECT addressbook_id FROM "CTSVC_DB_VIEW_CONTACT" WHERE contact_id = %d", name->contact_id);
+       ret = ctsvc_query_get_first_int_result(query, &addressbook_id);
        if (CONTACTS_ERROR_NONE != ret) {
                CTS_ERR("No data : contact_id (%d) is not exist", name->contact_id);
                ctsvc_end_trans(false);
@@ -270,7 +276,7 @@ static int __ctsvc_db_name_get_all_records( int offset, int limit, contacts_list
                                "ON "CTS_TABLE_DATA".contact_id = "CTSVC_DB_VIEW_CONTACT".contact_id "
                                "WHERE datatype = %d AND is_my_profile=0 ",
                                CTSVC_DATA_NAME);
-       if (0 < limit) {
+       if (0 != limit) {
                len += snprintf(query+len, sizeof(query)-len, " LIMIT %d", limit);
                if (0 < offset)
                        len += snprintf(query+len, sizeof(query)-len, " OFFSET %d", offset);
index 688d9bc..ff309bf 100644 (file)
@@ -59,7 +59,7 @@ ctsvc_db_plugin_info_s ctsvc_db_plugin_nickname = {
 static int __ctsvc_db_nickname_insert_record( contacts_record_h record, int *id )
 {
        int ret;
-       int contact_id;
+       int addressbook_id;
        char query[CTS_SQL_MAX_LEN] = {0};
        ctsvc_nickname_s *nickname = (ctsvc_nickname_s *)record;
 
@@ -73,12 +73,18 @@ static int __ctsvc_db_nickname_insert_record( contacts_record_h record, int *id
        }
 
        snprintf(query, sizeof(query),
-                       "SELECT contact_id FROM "CTSVC_DB_VIEW_CONTACT" WHERE contact_id = %d", nickname->contact_id);
-       ret = ctsvc_query_get_first_int_result(query, &contact_id);
+                       "SELECT addressbook_id FROM "CTSVC_DB_VIEW_CONTACT" WHERE contact_id = %d", nickname->contact_id);
+       ret = ctsvc_query_get_first_int_result(query, &addressbook_id);
        if (CONTACTS_ERROR_NONE != ret) {
-               CTS_ERR("No data : contact_id (%d) is not exist", contact_id);
                ctsvc_end_trans(false);
-               return CONTACTS_ERROR_INVALID_PARAMETER;
+               if (CONTACTS_ERROR_NO_DATA) {
+                       CTS_ERR("No data : contact_id (%d) is not exist", nickname->contact_id);
+                       return CONTACTS_ERROR_INVALID_PARAMETER;
+               }
+               else {
+                       CTS_ERR("ctsvc_query_get_first_int_result Fail(%d)", ret);
+                       return ret;
+               }
        }
 
        ret = ctsvc_db_nickname_insert(record, nickname->contact_id, false, id);
@@ -145,7 +151,7 @@ static int __ctsvc_db_nickname_get_record( int id, contacts_record_h* out_record
 static int __ctsvc_db_nickname_update_record( contacts_record_h record )
 {
        int ret;
-       int contact_id;
+       int addressbook_id;
        char query[CTS_SQL_MAX_LEN] = {0};
        ctsvc_nickname_s *nickname = (ctsvc_nickname_s *)record;
        RETVM_IF(NULL == nickname->nickname, CONTACTS_ERROR_INVALID_PARAMETER, "nickname is empty");
@@ -157,8 +163,8 @@ static int __ctsvc_db_nickname_update_record( contacts_record_h record )
        }
 
        snprintf(query, sizeof(query),
-                       "SELECT contact_id FROM "CTSVC_DB_VIEW_CONTACT" WHERE contact_id = %d", nickname->contact_id);
-       ret = ctsvc_query_get_first_int_result(query, &contact_id);
+                       "SELECT addressbook_id FROM "CTSVC_DB_VIEW_CONTACT" WHERE contact_id = %d", nickname->contact_id);
+       ret = ctsvc_query_get_first_int_result(query, &addressbook_id);
        if (CONTACTS_ERROR_NONE != ret) {
                CTS_ERR("No data : contact_id (%d) is not exist", nickname->contact_id);
                ctsvc_end_trans(false);
@@ -257,7 +263,7 @@ static int __ctsvc_db_nickname_get_all_records( int offset, int limit, contacts_
                                "ON "CTS_TABLE_DATA".contact_id = "CTSVC_DB_VIEW_CONTACT".contact_id "
                                "WHERE datatype = %d AND is_my_profile=0 ",
                                CTSVC_DATA_NICKNAME);
-       if (0 < limit) {
+       if (0 != limit) {
                len += snprintf(query+len, sizeof(query)-len, " LIMIT %d", limit);
                if (0 < offset)
                        len += snprintf(query+len, sizeof(query)-len, " OFFSET %d", offset);
index 5c34f3c..c5c1f97 100644 (file)
@@ -94,7 +94,7 @@ static int __ctsvc_db_note_get_record( int id, contacts_record_h* out_record )
 static int __ctsvc_db_note_insert_record( contacts_record_h record, int *id )
 {
        int ret;
-       int contact_id;
+       int addressbook_id;
        char query[CTS_SQL_MAX_LEN] = {0};
        ctsvc_note_s *note = (ctsvc_note_s *)record;
 
@@ -108,12 +108,18 @@ static int __ctsvc_db_note_insert_record( contacts_record_h record, int *id )
        }
 
        snprintf(query, sizeof(query),
-                       "SELECT contact_id FROM "CTSVC_DB_VIEW_CONTACT" WHERE contact_id = %d", note->contact_id);
-       ret = ctsvc_query_get_first_int_result(query, &contact_id);
+                       "SELECT addressbook_id FROM "CTSVC_DB_VIEW_CONTACT" WHERE contact_id = %d", note->contact_id);
+       ret = ctsvc_query_get_first_int_result(query, &addressbook_id);
        if (CONTACTS_ERROR_NONE != ret) {
-               CTS_ERR("No data : contact_id (%d) is not exist", contact_id);
                ctsvc_end_trans(false);
-               return CONTACTS_ERROR_INVALID_PARAMETER;
+               if (CONTACTS_ERROR_NO_DATA) {
+                       CTS_ERR("No data : contact_id (%d) is not exist", note->contact_id);
+                       return CONTACTS_ERROR_INVALID_PARAMETER;
+               }
+               else {
+                       CTS_ERR("ctsvc_query_get_first_int_result Fail(%d)", ret);
+                       return ret;
+               }
        }
 
        ret = ctsvc_db_note_insert(record, note->contact_id, false, id);
@@ -144,7 +150,7 @@ static int __ctsvc_db_note_insert_record( contacts_record_h record, int *id )
 static int __ctsvc_db_note_update_record( contacts_record_h record )
 {
        int ret;
-       int contact_id;
+       int addressbook_id;
        char query[CTS_SQL_MAX_LEN] = {0};
        ctsvc_note_s *note = (ctsvc_note_s *)record;
 
@@ -157,8 +163,8 @@ static int __ctsvc_db_note_update_record( contacts_record_h record )
        }
 
        snprintf(query, sizeof(query),
-                       "SELECT contact_id FROM "CTSVC_DB_VIEW_CONTACT" WHERE contact_id = %d", note->contact_id);
-       ret = ctsvc_query_get_first_int_result(query, &contact_id);
+                       "SELECT addressbook_id FROM "CTSVC_DB_VIEW_CONTACT" WHERE contact_id = %d", note->contact_id);
+       ret = ctsvc_query_get_first_int_result(query, &addressbook_id);
        if (CONTACTS_ERROR_NONE != ret) {
                CTS_ERR("No data : contact_id (%d) is not exist", note->contact_id);
                ctsvc_end_trans(false);
@@ -255,7 +261,7 @@ static int __ctsvc_db_note_get_all_records( int offset, int limit, contacts_list
                                "ON "CTS_TABLE_DATA".contact_id = "CTSVC_DB_VIEW_CONTACT".contact_id "
                                "WHERE datatype = %d AND is_my_profile=0 ",
                                CTSVC_DATA_NOTE);
-       if (0 < limit) {
+       if (0 != limit) {
                len += snprintf(query+len, sizeof(query)-len, " LIMIT %d", limit);
                if (0 < offset)
                        len += snprintf(query+len, sizeof(query)-len, " OFFSET %d", offset);
index 96ee872..c8296b6 100644 (file)
@@ -179,9 +179,9 @@ static int __ctsvc_db_number_set_primary_default(int number_id, bool is_primary_
 static int __ctsvc_db_number_insert_record( contacts_record_h record, int *id )
 {
        int ret;
-       int contact_id;
        int person_id;
        int old_default_number_id = 0;
+       int addressbook_id;
        char query[CTS_SQL_MAX_LEN] = {0};
        cts_stmt stmt = NULL;
        ctsvc_number_s *number = (ctsvc_number_s *)record;
@@ -195,7 +195,7 @@ static int __ctsvc_db_number_insert_record( contacts_record_h record, int *id )
        }
 
        snprintf(query, sizeof(query),
-                       "SELECT contact_id, person_id FROM "CTSVC_DB_VIEW_CONTACT" WHERE contact_id = %d", number->contact_id);
+                       "SELECT addressbook_id, person_id FROM "CTSVC_DB_VIEW_CONTACT" WHERE contact_id = %d", number->contact_id);
        stmt = cts_query_prepare(query);
        if (NULL == stmt) {
                CTS_ERR("DB error : cts_query_prepare() Failed");
@@ -208,9 +208,12 @@ static int __ctsvc_db_number_insert_record( contacts_record_h record, int *id )
                CTS_ERR("DB error : cts_stmt_step() Failed(%d)", ret);
                cts_stmt_finalize(stmt);
                ctsvc_end_trans(false);
-               return CONTACTS_ERROR_NO_DATA;
+               if (CONTACTS_ERROR_NO_DATA)
+                       return CONTACTS_ERROR_INVALID_PARAMETER;
+               else
+                       return ret;
        }
-       contact_id = ctsvc_stmt_get_int(stmt, 0);
+       addressbook_id = ctsvc_stmt_get_int(stmt, 0);
        person_id = ctsvc_stmt_get_int(stmt, 1);
        cts_stmt_finalize(stmt);
 
@@ -224,6 +227,7 @@ static int __ctsvc_db_number_insert_record( contacts_record_h record, int *id )
                ctsvc_end_trans(false);
                return ret;
        }
+
        snprintf(query, sizeof(query),
                "UPDATE "CTS_TABLE_CONTACTS" SET has_phonenumber = %d, changed_ver = %d, changed_time = %d "
                        "WHERE contact_id = %d",
@@ -241,12 +245,12 @@ static int __ctsvc_db_number_insert_record( contacts_record_h record, int *id )
                __ctsvc_db_number_update_person_has_phonenumber(person_id, true);
 
                primary_default_contact_id = __ctsvc_db_number_get_primary_default_contact_id(person_id);
-               __ctsvc_db_number_reset_default(*id, contact_id);
+               __ctsvc_db_number_reset_default(*id, number->contact_id);
 
-               if (0 == primary_default_contact_id || contact_id == primary_default_contact_id)
+               if (0 == primary_default_contact_id || number->contact_id == primary_default_contact_id)
                        __ctsvc_db_number_set_primary_default(*id, true);
 
-               ctsvc_contact_update_display_name(contact_id, CONTACTS_DISPLAY_NAME_SOURCE_TYPE_NUMBER);
+               ctsvc_contact_update_display_name(number->contact_id, CONTACTS_DISPLAY_NAME_SOURCE_TYPE_NUMBER);
        }
 
        ctsvc_set_contact_noti();
@@ -291,7 +295,7 @@ static int __ctsvc_db_number_get_record( int id, contacts_record_h* out_record )
 static int __ctsvc_db_number_update_record( contacts_record_h record )
 {
        int ret;
-       int contact_id;
+       int addressbook_id;
        char query[CTS_SQL_MAX_LEN] = {0};
        ctsvc_number_s *number = (ctsvc_number_s *)record;
        RETVM_IF(NULL == number->number, CONTACTS_ERROR_INVALID_PARAMETER, "number is empty");
@@ -303,10 +307,10 @@ static int __ctsvc_db_number_update_record( contacts_record_h record )
        }
 
        snprintf(query, sizeof(query),
-                       "SELECT contact_id, person_id FROM "CTSVC_DB_VIEW_CONTACT" WHERE contact_id = %d", number->contact_id);
-       ret = ctsvc_query_get_first_int_result(query, &contact_id);
+                       "SELECT addressbook_id FROM "CTSVC_DB_VIEW_CONTACT" WHERE contact_id = %d", number->contact_id);
+       ret = ctsvc_query_get_first_int_result(query, &addressbook_id);
        if (CONTACTS_ERROR_NONE != ret) {
-               CTS_ERR("DB error : ctsvc_begin_trans() Failed(%d)", ret);
+               CTS_ERR("No data : contact_id (%d) is not exist", number->contact_id);
                ctsvc_end_trans(false);
                return ret;
        }
@@ -321,14 +325,13 @@ static int __ctsvc_db_number_update_record( contacts_record_h record )
        if (number->is_default) {
                int old_primary_default_number_id = 0;
 
-               old_primary_default_number_id = __ctsvc_db_number_get_primary_default(contact_id);
-               __ctsvc_db_number_reset_default(number->id, contact_id);
+               old_primary_default_number_id = __ctsvc_db_number_get_primary_default(number->contact_id);
+               __ctsvc_db_number_reset_default(number->id, number->contact_id);
 
                if (old_primary_default_number_id)
                        __ctsvc_db_number_set_primary_default(number->id, true);
        }
-       ctsvc_contact_update_display_name(contact_id, CONTACTS_DISPLAY_NAME_SOURCE_TYPE_NUMBER);
-
+       ctsvc_contact_update_display_name(number->contact_id, CONTACTS_DISPLAY_NAME_SOURCE_TYPE_NUMBER);
 
        ret = ctsvc_db_contact_update_changed_time(number->contact_id);
        if (CONTACTS_ERROR_NONE != ret) {
@@ -382,15 +385,18 @@ static int __ctsvc_db_number_delete_record( int id )
                CTS_ERR("DB error : cts_stmt_step() Failed(%d)", ret);
                cts_stmt_finalize(stmt);
                ctsvc_end_trans(false);
-               return CONTACTS_ERROR_NO_DATA;
+               if (CONTACTS_ERROR_NONE == ret)
+                       return CONTACTS_ERROR_NO_DATA;
+               else
+                       return ret;
        }
+
        contact_id = ctsvc_stmt_get_int(stmt, 0);
        person_id = ctsvc_stmt_get_int(stmt, 1);
        cts_stmt_finalize(stmt);
 
        snprintf(query, sizeof(query),
                        "SELECT is_default, is_primary_default FROM "CTS_TABLE_DATA" WHERE id = %d", id);
-
        stmt = cts_query_prepare(query);
        RETVM_IF(NULL == stmt, CONTACTS_ERROR_DB , "DB error : cts_query_prepare() Failed");
 
@@ -466,7 +472,7 @@ static int __ctsvc_db_number_get_all_records( int offset, int limit, contacts_li
 
        len = snprintf(query, sizeof(query),
                        "SELECT id, contact_id, is_default, data1, data2, data3, data4 FROM "CTSVC_DB_VIEW_NUMBER);
-       if (0 < limit) {
+       if (0 != limit) {
                len += snprintf(query+len, sizeof(query)-len, " LIMIT %d", limit);
                if (0 < offset)
                        len += snprintf(query+len, sizeof(query)-len, " OFFSET %d", offset);
index 1682393..4cb2495 100644 (file)
@@ -385,8 +385,7 @@ static int __ctsvc_db_person_delete_record( int id )
                ctsvc_set_group_rel_noti();
 
        ret = ctsvc_end_trans(true);
-       if (ret < CONTACTS_ERROR_NONE)
-       {
+       if (ret < CONTACTS_ERROR_NONE) {
                CTS_ERR("DB error : ctsvc_end_trans() Failed(%d)", ret);
                return ret;
        }
@@ -417,9 +416,9 @@ static int __ctsvc_db_person_get_all_records( int offset, int limit, contacts_li
                                        "has_email, "
                                        "is_favorite "
                        "FROM "CTSVC_DB_VIEW_PERSON" ORDER BY %s",
-                               ctsvc_get_display_column(), ctsvc_get_sort_name_column(),       ctsvc_get_sort_column());
+                               ctsvc_get_display_column(), ctsvc_get_sort_name_column(), ctsvc_get_sort_column());
 
-       if (0 < limit) {
+       if (0 != limit) {
                len += snprintf(query+len, sizeof(query)-len, " LIMIT %d", limit);
                if (0 < offset)
                        len += snprintf(query+len, sizeof(query)-len, " OFFSET %d", offset);
index 3857b0b..b2c0449 100644 (file)
@@ -234,7 +234,7 @@ static int __ctsvc_db_phonelog_get_all_records( int offset, int limit,
        len = snprintf(query, sizeof(query),
                        "SELECT id, number, person_id, log_type, log_time, data1, data2 FROM "CTS_TABLE_PHONELOGS);
 
-       if (0 < limit) {
+       if (0 != limit) {
                len += snprintf(query+len, sizeof(query)-len, " LIMIT %d", limit);
                if (0 < offset)
                        len += snprintf(query+len, sizeof(query)-len, " OFFSET %d", offset);
index b0d9047..9169a19 100644 (file)
@@ -60,7 +60,7 @@ ctsvc_db_plugin_info_s ctsvc_db_plugin_profile = {
 static int __ctsvc_db_profile_insert_record( contacts_record_h record, int *id )
 {
        int ret;
-       int contact_id;
+       int addressbook_id;
        char query[CTS_SQL_MAX_LEN] = {0};
        ctsvc_profile_s *profile = (ctsvc_profile_s *)record;
 
@@ -74,12 +74,18 @@ static int __ctsvc_db_profile_insert_record( contacts_record_h record, int *id )
        }
 
        snprintf(query, sizeof(query),
-                       "SELECT contact_id FROM "CTSVC_DB_VIEW_CONTACT" WHERE contact_id = %d", profile->contact_id);
-       ret = ctsvc_query_get_first_int_result(query, &contact_id);
+                       "SELECT addressbook_id FROM "CTSVC_DB_VIEW_CONTACT" WHERE contact_id = %d", profile->contact_id);
+       ret = ctsvc_query_get_first_int_result(query, &addressbook_id);
        if (CONTACTS_ERROR_NONE != ret) {
-               CTS_ERR("No data : contact_id (%d) is not exist", contact_id);
                ctsvc_end_trans(false);
-               return CONTACTS_ERROR_INVALID_PARAMETER;
+               if (CONTACTS_ERROR_NO_DATA) {
+                       CTS_ERR("No data : contact_id (%d) is not exist", profile->contact_id);
+                       return CONTACTS_ERROR_INVALID_PARAMETER;
+               }
+               else {
+                       CTS_ERR("ctsvc_query_get_first_int_result Fail(%d)", ret);
+                       return ret;
+               }
        }
 
        ret = ctsvc_db_profile_insert(record, profile->contact_id, false, id);
@@ -145,7 +151,7 @@ static int __ctsvc_db_profile_get_record( int id, contacts_record_h* out_record
 static int __ctsvc_db_profile_update_record( contacts_record_h record )
 {
        int ret;
-       int contact_id;
+       int addressbook_id;
        char query[CTS_SQL_MAX_LEN] = {0};
        ctsvc_profile_s *profile = (ctsvc_profile_s *)record;
        RETVM_IF(NULL == profile->text, CONTACTS_ERROR_INVALID_PARAMETER, "profile text is empty");
@@ -157,8 +163,8 @@ static int __ctsvc_db_profile_update_record( contacts_record_h record )
        }
 
        snprintf(query, sizeof(query),
-                       "SELECT contact_id FROM "CTSVC_DB_VIEW_CONTACT" WHERE contact_id = %d", profile->contact_id);
-       ret = ctsvc_query_get_first_int_result(query, &contact_id);
+                       "SELECT addressbook_id FROM "CTSVC_DB_VIEW_CONTACT" WHERE contact_id = %d", profile->contact_id);
+       ret = ctsvc_query_get_first_int_result(query, &addressbook_id);
        if (CONTACTS_ERROR_NONE != ret) {
                CTS_ERR("No data : contact_id (%d) is not exist", profile->contact_id);
                ctsvc_end_trans(false);
@@ -253,7 +259,7 @@ static int __ctsvc_db_profile_get_all_records( int offset, int limit, contacts_l
                                "ON "CTS_TABLE_DATA".contact_id = "CTSVC_DB_VIEW_CONTACT".contact_id "
                                "WHERE datatype = %d AND is_my_profile=0 ",
                                CTSVC_DATA_PROFILE);
-       if (0 < limit) {
+       if (0 != limit) {
                len += snprintf(query+len, sizeof(query)-len, " LIMIT %d", limit);
                if (0 < offset)
                        len += snprintf(query+len, sizeof(query)-len, " OFFSET %d", offset);
index 43aea3a..ec9c4db 100644 (file)
@@ -61,7 +61,7 @@ ctsvc_db_plugin_info_s ctsvc_db_plugin_relationship = {
 static int __ctsvc_db_relationship_insert_record( contacts_record_h record, int *id )
 {
        int ret;
-       int contact_id;
+       int addressbook_id;
        char query[CTS_SQL_MAX_LEN] = {0};
        ctsvc_relationship_s *relationship = (ctsvc_relationship_s *)record;
 
@@ -75,12 +75,18 @@ static int __ctsvc_db_relationship_insert_record( contacts_record_h record, int
        }
 
        snprintf(query, sizeof(query),
-                       "SELECT contact_id FROM "CTSVC_DB_VIEW_CONTACT" WHERE contact_id = %d", relationship->contact_id);
-       ret = ctsvc_query_get_first_int_result(query, &contact_id);
+                       "SELECT addressbook_id FROM "CTSVC_DB_VIEW_CONTACT" WHERE contact_id = %d", relationship->contact_id);
+       ret = ctsvc_query_get_first_int_result(query, &addressbook_id);
        if (CONTACTS_ERROR_NONE != ret) {
-               CTS_ERR("No data : contact_id (%d) is not exist", contact_id);
                ctsvc_end_trans(false);
-               return CONTACTS_ERROR_INVALID_PARAMETER;
+               if (CONTACTS_ERROR_NO_DATA) {
+                       CTS_ERR("No data : contact_id (%d) is not exist", relationship->contact_id);
+                       return CONTACTS_ERROR_INVALID_PARAMETER;
+               }
+               else {
+                       CTS_ERR("ctsvc_query_get_first_int_result Fail(%d)", ret);
+                       return ret;
+               }
        }
 
        ret = ctsvc_db_relationship_insert(record, relationship->contact_id, false, id);
@@ -145,7 +151,7 @@ static int __ctsvc_db_relationship_get_record( int id, contacts_record_h* out_re
 static int __ctsvc_db_relationship_update_record( contacts_record_h record )
 {
        int ret;
-       int contact_id;
+       int addressbook_id;
        char query[CTS_SQL_MAX_LEN] = {0};
        ctsvc_relationship_s *relationship = (ctsvc_relationship_s *)record;
        RETVM_IF(NULL == relationship->name, CONTACTS_ERROR_INVALID_PARAMETER, "name is empty");
@@ -157,8 +163,8 @@ static int __ctsvc_db_relationship_update_record( contacts_record_h record )
        }
 
        snprintf(query, sizeof(query),
-                       "SELECT contact_id FROM "CTSVC_DB_VIEW_CONTACT" WHERE contact_id = %d", relationship->contact_id);
-       ret = ctsvc_query_get_first_int_result(query, &contact_id);
+                       "SELECT addressbook_id FROM "CTSVC_DB_VIEW_CONTACT" WHERE contact_id = %d", relationship->contact_id);
+       ret = ctsvc_query_get_first_int_result(query, &addressbook_id);
        if (CONTACTS_ERROR_NONE != ret) {
                CTS_ERR("No data : contact_id (%d) is not exist", relationship->contact_id);
                ctsvc_end_trans(false);
@@ -252,7 +258,7 @@ static int __ctsvc_db_relationship_get_all_records( int offset, int limit, conta
                                "ON "CTS_TABLE_DATA".contact_id = "CTSVC_DB_VIEW_CONTACT".contact_id "
                                "WHERE datatype = %d AND is_my_profile=0 ",
                                CTSVC_DATA_RELATIONSHIP);
-       if (0 < limit) {
+       if (0 != limit) {
                len += snprintf(query+len, sizeof(query)-len, " LIMIT %d", limit);
                if (0 < offset)
                        len += snprintf(query+len, sizeof(query)-len, " OFFSET %d", offset);
index 13106a8..1629ed1 100644 (file)
@@ -274,7 +274,7 @@ static int __ctsvc_db_sdn_get_all_records( int offset, int limit,
        len = snprintf(query, sizeof(query),
                                "SELECT id, name, number FROM "CTS_TABLE_SDN);
 
-       if (0 < limit) {
+       if (0 != limit) {
                len += snprintf(query+len, sizeof(query)-len, " LIMIT %d", limit);
                if (0 < offset)
                        len += snprintf(query+len, sizeof(query)-len, " OFFSET %d", offset);
index b05d133..dcdc2cd 100644 (file)
@@ -299,7 +299,7 @@ static int __ctsvc_db_simple_contact_get_all_records( int offset, int limit,
                                "ringtone_path, vibration, uid, is_favorite, has_phonenumber, has_email "
                                "FROM "CTS_TABLE_CONTACTS" WHERE deleted = 0", ctsvc_get_display_column());
 
-       if (0 < limit) {
+       if (0 != limit) {
                len += snprintf(query+len, sizeof(query)-len, " LIMIT %d", limit);
                if (0 < offset)
                        len += snprintf(query+len, sizeof(query)-len, " OFFSET %d", offset);
index bb211cf..40f1e36 100644 (file)
@@ -287,7 +287,7 @@ static int __ctsvc_db_speeddial_get_all_records( int offset, int limit, contacts
                                                        "type, label, number, speed_number      "
                                        "FROM "CTSVC_DB_VIEW_SPEEDIDAL " ",     ctsvc_get_display_column());
 
-       if (0 < limit) {
+       if (0 != limit) {
                len += snprintf(query+len, sizeof(query)-len, " LIMIT %d", limit);
                if (0 < offset)
                        len += snprintf(query+len, sizeof(query)-len, " OFFSET %d", offset);
index b474302..a77d195 100644 (file)
@@ -60,7 +60,7 @@ ctsvc_db_plugin_info_s ctsvc_db_plugin_url = {
 static int __ctsvc_db_url_insert_record( contacts_record_h record, int *id )
 {
        int ret;
-       int contact_id;
+       int addressbook_id;
        char query[CTS_SQL_MAX_LEN] = {0};
        ctsvc_url_s *url = (ctsvc_url_s *)record;
 
@@ -73,12 +73,18 @@ static int __ctsvc_db_url_insert_record( contacts_record_h record, int *id )
        }
 
        snprintf(query, sizeof(query),
-                       "SELECT contact_id FROM "CTSVC_DB_VIEW_CONTACT" WHERE contact_id = %d", url->contact_id);
-       ret = ctsvc_query_get_first_int_result(query, &contact_id);
+                       "SELECT addressbook_id FROM "CTSVC_DB_VIEW_CONTACT" WHERE contact_id = %d", url->contact_id);
+       ret = ctsvc_query_get_first_int_result(query, &addressbook_id);
        if (CONTACTS_ERROR_NONE != ret) {
-               CTS_ERR("No data : contact_id (%d) is not exist", contact_id);
                ctsvc_end_trans(false);
-               return CONTACTS_ERROR_INVALID_PARAMETER;
+               if (CONTACTS_ERROR_NO_DATA) {
+                       CTS_ERR("No data : contact_id (%d) is not exist", url->contact_id);
+                       return CONTACTS_ERROR_INVALID_PARAMETER;
+               }
+               else {
+                       CTS_ERR("ctsvc_query_get_first_int_result Fail(%d)", ret);
+                       return ret;
+               }
        }
 
        ret = ctsvc_db_url_insert(record, url->contact_id, false, id);
@@ -143,7 +149,7 @@ static int __ctsvc_db_url_get_record( int id, contacts_record_h* out_record )
 static int __ctsvc_db_url_update_record( contacts_record_h record )
 {
        int ret;
-       int contact_id;
+       int addressbook_id;
        char query[CTS_SQL_MAX_LEN] = {0};
        ctsvc_url_s *url = (ctsvc_url_s *)record;
        RETVM_IF(NULL == url->url, CONTACTS_ERROR_INVALID_PARAMETER, "url is empty");
@@ -155,8 +161,8 @@ static int __ctsvc_db_url_update_record( contacts_record_h record )
        }
 
        snprintf(query, sizeof(query),
-                       "SELECT contact_id FROM "CTSVC_DB_VIEW_CONTACT" WHERE contact_id = %d", url->contact_id);
-       ret = ctsvc_query_get_first_int_result(query, &contact_id);
+                       "SELECT addressbook_id FROM "CTSVC_DB_VIEW_CONTACT" WHERE contact_id = %d", url->contact_id);
+       ret = ctsvc_query_get_first_int_result(query, &addressbook_id);
        if (CONTACTS_ERROR_NONE != ret) {
                CTS_ERR("No data : contact_id (%d) is not exist", url->contact_id);
                ctsvc_end_trans(false);
@@ -250,7 +256,7 @@ static int __ctsvc_db_url_get_all_records( int offset, int limit, contacts_list_
                                "ON "CTS_TABLE_DATA".contact_id = "CTSVC_DB_VIEW_CONTACT".contact_id "
                                "WHERE datatype = %d AND is_my_profile=0 ",
                                CTSVC_DATA_URL);
-       if (0 < limit) {
+       if (0 != limit) {
                len += snprintf(query+len, sizeof(query)-len, " LIMIT %d", limit);
                if (0 < offset)
                        len += snprintf(query+len, sizeof(query)-len, " OFFSET %d", offset);
index da9f11e..fd413e0 100755 (executable)
@@ -677,7 +677,7 @@ int ctsvc_db_make_get_records_query_stmt(ctsvc_query_s *s_query, int offset, int
        else if (0 == strcmp(s_query->view_uri, CTSVC_VIEW_URI_GROUP))
                len += snprintf(query+len, sizeof(query)-len, " ORDER BY group_prio");
 
-       if (0 < limit) {
+       if (0 != limit) {
                len += snprintf(query+len, sizeof(query)-len, " LIMIT %d", limit);
                if (0 < offset)
                        len += snprintf(query+len, sizeof(query)-len, " OFFSET %d", offset);
@@ -797,7 +797,7 @@ static int __ctsvc_db_get_all_records_exec(const char *view_uri, const property_
        } else if (0 == strcmp(view_uri, CTSVC_VIEW_URI_GROUP))
                len += snprintf(query+len, sizeof(query)-len, " ORDER BY group_prio");
 
-       if (0 < limit) {
+       if (0 != limit) {
                len += snprintf(query+len, sizeof(query)-len, " LIMIT %d", limit);
                if (0 < offset)
                        len += snprintf(query+len, sizeof(query)-len, " OFFSET %d", offset);
@@ -1128,7 +1128,7 @@ static int __ctsvc_db_search_records_exec(const char *view_uri, const property_i
        } else if (0 == strcmp(view_uri, CTSVC_VIEW_URI_GROUP))
                len += snprintf(query+len, sizeof(query)-len, " ORDER BY group_prio");
 
-       if (0 < limit) {
+       if (0 != limit) {
                len += snprintf(query+len, sizeof(query)-len, " LIMIT %d", limit);
                if (0 < offset)
                        len += snprintf(query+len, sizeof(query)-len, " OFFSET %d", offset);
@@ -1323,7 +1323,7 @@ static inline int __ctsvc_db_search_records_with_query_exec(ctsvc_query_s *s_que
        else if (0 == strcmp(s_query->view_uri, CTSVC_VIEW_URI_GROUP))
                len += snprintf(query+len, sizeof(query)-len, " ORDER BY group_prio");
 
-       if (0 < limit) {
+       if (0 != limit) {
                len += snprintf(query+len, sizeof(query)-len, " LIMIT %d", limit);
                if (0 < offset)
                        len += snprintf(query+len, sizeof(query)-len, " OFFSET %d", offset);