/*
* 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.
* limitations under the License.
*
*/
-
#include <unistd.h>
#include "contacts.h"
#include "ctsvc_db_query.h"
#include "ctsvc_list.h"
-static int __ctsvc_db_company_insert_record(contacts_record_h record, int *id);
-static int __ctsvc_db_company_get_record(int id, contacts_record_h* out_record);
-static int __ctsvc_db_company_update_record(contacts_record_h record);
-static int __ctsvc_db_company_delete_record(int id);
-static int __ctsvc_db_company_get_all_records(int offset, int limit, contacts_list_h* out_list);
-static int __ctsvc_db_company_get_records_with_query(contacts_query_h query, int offset, int limit, contacts_list_h* out_list);
-//static int __ctsvc_db_company_insert_records(const contacts_list_h in_list, int **ds);
-//static int __ctsvc_db_company_update_records(const contacts_list_h in_list);
-//static int __ctsvc_db_company_delete_records(int ids[], int count);
-
-ctsvc_db_plugin_info_s ctsvc_db_plugin_company = {
- .is_query_only = false,
- .insert_record = __ctsvc_db_company_insert_record,
- .get_record = __ctsvc_db_company_get_record,
- .update_record = __ctsvc_db_company_update_record,
- .delete_record = __ctsvc_db_company_delete_record,
- .get_all_records = __ctsvc_db_company_get_all_records,
- .get_records_with_query = __ctsvc_db_company_get_records_with_query,
- .insert_records = NULL, /* __ctsvc_db_company_insert_records, */
- .update_records = NULL, /* __ctsvc_db_company_update_records, */
- .delete_records = NULL, /* __ctsvc_db_company_delete_records, */
- .get_count = NULL,
- .get_count_with_query = NULL,
- .replace_record = NULL,
- .replace_records = NULL,
-};
-static int __ctsvc_db_company_get_record(int id, contacts_record_h* out_record)
+static int __ctsvc_db_company_get_record(int id, contacts_record_h *out_record)
{
int ret;
cts_stmt stmt = NULL;
snprintf(query, sizeof(query),
"SELECT id, data.contact_id, is_default, data1, data2, "
- "data3, data4, data5, data6, data7, data8, data9, data10, data11, data12 "
- "FROM "CTS_TABLE_DATA", "CTSVC_DB_VIEW_CONTACT" "
- "ON "CTS_TABLE_DATA".contact_id = "CTSVC_DB_VIEW_CONTACT".contact_id "
- "WHERE id = %d AND datatype = %d ",
- id, CTSVC_DATA_COMPANY);
+ "data3, data4, data5, data6, data7, data8, data9, data10, data11, data12 "
+ "FROM "CTS_TABLE_DATA", "CTSVC_DB_VIEW_CONTACT" "
+ "ON "CTS_TABLE_DATA".contact_id = "CTSVC_DB_VIEW_CONTACT".contact_id "
+ "WHERE id = %d AND datatype = %d ",
+ id, CONTACTS_DATA_TYPE_COMPANY);
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);
ret = ctsvc_stmt_step(stmt);
if (1 /*CTS_TRUE*/ != ret) {
- CTS_ERR("ctsvc_stmt_step() Fail(%d)", ret);
+ /* LCOV_EXCL_START */
+ ERR("ctsvc_stmt_step() Fail(%d)", ret);
ctsvc_stmt_finalize(stmt);
if (CONTACTS_ERROR_NONE == ret)
return CONTACTS_ERROR_NO_DATA;
else
return ret;
+ /* LCOV_EXCL_STOP */
}
ctsvc_db_company_get_value_from_stmt(stmt, out_record, 0);
int ret;
int addressbook_id;
char query[CTS_SQL_MAX_LEN] = {0};
- ctsvc_company_s *company = (ctsvc_company_s *)record;
+ ctsvc_company_s *company = (ctsvc_company_s*)record;
RETVM_IF(NULL == company->name && NULL == company->department && NULL == company->job_title
- && NULL == company->role && NULL == company->assistant_name && NULL == company->logo
- && NULL == company->location && NULL == company->description && NULL == company->phonetic_name,
- CONTACTS_ERROR_INVALID_PARAMETER, "Invalid parameter : company is NULL");
+ && NULL == company->role && NULL == company->assistant_name && NULL == company->logo
+ && NULL == company->location && NULL == company->description && NULL == company->phonetic_name,
+ CONTACTS_ERROR_INVALID_PARAMETER, "company is NULL");
ret = ctsvc_begin_trans();
if (CONTACTS_ERROR_NONE != ret) {
- CTS_ERR("DB error : ctsvc_begin_trans() Fail(%d)", ret);
+ /* LCOV_EXCL_START */
+ ERR("ctsvc_begin_trans() Fail(%d)", ret);
return ret;
+ /* LCOV_EXCL_STOP */
}
snprintf(query, sizeof(query),
if (CONTACTS_ERROR_NONE != ret) {
ctsvc_end_trans(false);
if (CONTACTS_ERROR_NO_DATA == ret) {
- CTS_ERR("No data : contact_id (%d) is not exist", company->contact_id);
+ /* LCOV_EXCL_START */
+ 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);
+ /* LCOV_EXCL_STOP */
+ } else {
+ /* LCOV_EXCL_START */
+ ERR("ctsvc_query_get_first_int_result() Fail(%d)", ret);
return ret;
+ /* LCOV_EXCL_STOP */
}
}
- if (false == ctsvc_have_ab_write_permission(addressbook_id)) {
- CTS_ERR("Does not have permission to update this company record : addresbook_id(%d)", addressbook_id);
+ if (false == ctsvc_have_ab_write_permission(addressbook_id, false)) {
+ /* LCOV_EXCL_START */
+ ERR("No permission in this addresbook_id(%d)", addressbook_id);
ctsvc_end_trans(false);
return CONTACTS_ERROR_PERMISSION_DENIED;
+ /* LCOV_EXCL_STOP */
}
ret = ctsvc_db_company_insert(record, company->contact_id, false, id);
if (CONTACTS_ERROR_NONE != ret) {
- CTS_ERR("DB error : ctsvc_begin_trans() Fail(%d)", ret);
+ /* LCOV_EXCL_START */
+ ERR("ctsvc_begin_trans() Fail(%d)", ret);
ctsvc_end_trans(false);
return ret;
+ /* LCOV_EXCL_STOP */
}
ctsvc_contact_update_display_name(company->contact_id, CONTACTS_DISPLAY_NAME_SOURCE_TYPE_COMPANY);
ret = ctsvc_db_contact_update_changed_time(company->contact_id);
if (CONTACTS_ERROR_NONE != ret) {
- CTS_ERR("DB error : ctsvc_db_contact_update_changed_time() Fail(%d)", ret);
+ /* LCOV_EXCL_START */
+ ERR("ctsvc_db_contact_update_changed_time() Fail(%d)", ret);
ctsvc_end_trans(false);
return ret;
+ /* LCOV_EXCL_STOP */
}
ctsvc_set_person_noti();
ret = ctsvc_end_trans(true);
if (ret < CONTACTS_ERROR_NONE) {
- CTS_ERR("DB error : ctsvc_end_trans() Fail(%d)", ret);
+ /* LCOV_EXCL_START */
+ ERR("ctsvc_end_trans() Fail(%d)", ret);
return ret;
- }
- else
+ /* LCOV_EXCL_STOP */
+ } else {
return CONTACTS_ERROR_NONE;
+ }
}
static int __ctsvc_db_company_update_record(contacts_record_h record)
int ret;
int addressbook_id;
char query[CTS_SQL_MAX_LEN] = {0};
- ctsvc_company_s *company = (ctsvc_company_s *)record;
+ ctsvc_company_s *company = (ctsvc_company_s*)record;
RETVM_IF(NULL == company->name && NULL == company->department && NULL == company->job_title &&
NULL == company->role && NULL == company->assistant_name && NULL == company->logo &&
ret = ctsvc_begin_trans();
if (CONTACTS_ERROR_NONE != ret) {
- CTS_ERR("DB error : ctsvc_begin_trans() Fail(%d)", ret);
+ /* LCOV_EXCL_START */
+ ERR("ctsvc_begin_trans() Fail(%d)", ret);
return ret;
+ /* LCOV_EXCL_STOP */
}
snprintf(query, sizeof(query),
"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);
+ /* LCOV_EXCL_START */
+ ERR("No data : contact_id (%d) is not exist", company->contact_id);
ctsvc_end_trans(false);
return ret;
+ /* LCOV_EXCL_STOP */
}
- if (false == ctsvc_have_ab_write_permission(addressbook_id)) {
- CTS_ERR("Does not have permission to update this company record : addresbook_id(%d)", addressbook_id);
+ if (false == ctsvc_have_ab_write_permission(addressbook_id, false)) {
+ /* LCOV_EXCL_START */
+ ERR("No permission in this addresbook_id(%d)", addressbook_id);
ctsvc_end_trans(false);
return CONTACTS_ERROR_PERMISSION_DENIED;
+ /* LCOV_EXCL_STOP */
}
ret = ctsvc_db_company_update(record, company->contact_id, false);
if (CONTACTS_ERROR_NONE != ret) {
- CTS_ERR("Update record Fail(%d)", ret);
+ /* LCOV_EXCL_START */
+ ERR("Update record Fail(%d)", ret);
ctsvc_end_trans(false);
return ret;
+ /* LCOV_EXCL_STOP */
}
ctsvc_contact_update_display_name(company->contact_id, CONTACTS_DISPLAY_NAME_SOURCE_TYPE_COMPANY);
ret = ctsvc_db_contact_update_changed_time(company->contact_id);
if (CONTACTS_ERROR_NONE != ret) {
- CTS_ERR("DB error : ctsvc_db_contact_update_changed_time() Fail(%d)", ret);
+ /* LCOV_EXCL_START */
+ ERR("ctsvc_db_contact_update_changed_time() Fail(%d)", ret);
ctsvc_end_trans(false);
return ret;
+ /* LCOV_EXCL_STOP */
}
ctsvc_set_person_noti();
ret = ctsvc_end_trans(true);
if (ret < CONTACTS_ERROR_NONE) {
- CTS_ERR("DB error : ctsvc_end_trans() Fail(%d)", ret);
+ /* LCOV_EXCL_START */
+ ERR("ctsvc_end_trans() Fail(%d)", ret);
return ret;
- }
- else
+ /* LCOV_EXCL_STOP */
+ } else {
return CONTACTS_ERROR_NONE;
+ }
}
ret = ctsvc_begin_trans();
if (CONTACTS_ERROR_NONE != ret) {
- CTS_ERR("DB error : ctsvc_begin_trans() Fail(%d)", ret);
+ /* LCOV_EXCL_START */
+ ERR("ctsvc_begin_trans() Fail(%d)", ret);
return ret;
+ /* LCOV_EXCL_STOP */
}
snprintf(query, sizeof(query),
"SELECT contact_id, addressbook_id FROM "CTSVC_DB_VIEW_CONTACT" "
- "WHERE contact_id = (SELECT contact_id FROM "CTS_TABLE_DATA" WHERE id = %d)", id);
+ "WHERE contact_id = (SELECT contact_id FROM "CTS_TABLE_DATA" WHERE id = %d)", id);
ret = ctsvc_query_prepare(query, &stmt);
if (NULL == stmt) {
- CTS_ERR("DB error : ctsvc_query_prepare Fail(%d)", ret);
+ /* LCOV_EXCL_START */
+ ERR("ctsvc_query_prepare Fail(%d)", ret);
ctsvc_end_trans(false);
return ret;
+ /* LCOV_EXCL_STOP */
}
ret = ctsvc_stmt_step(stmt);
if (1 != ret) {
- CTS_ERR("The id(%d) is Invalid(%d)", id, ret);
+ /* LCOV_EXCL_START */
+ ERR("The id(%d) is Invalid(%d)", id, ret);
ctsvc_stmt_finalize(stmt);
ctsvc_end_trans(false);
if (CONTACTS_ERROR_NONE == ret)
return CONTACTS_ERROR_NO_DATA;
else
return ret;
+ /* LCOV_EXCL_STOP */
}
contact_id = ctsvc_stmt_get_int(stmt, 0);
addressbook_id = ctsvc_stmt_get_int(stmt, 1);
ctsvc_stmt_finalize(stmt);
- if (false == ctsvc_have_ab_write_permission(addressbook_id)) {
- CTS_ERR("Does not have permission to delete this company record : addresbook_id(%d)", addressbook_id);
+ if (false == ctsvc_have_ab_write_permission(addressbook_id, false)) {
+ /* LCOV_EXCL_START */
+ ERR("No permission in this addresbook_id(%d)", addressbook_id);
ctsvc_end_trans(false);
return CONTACTS_ERROR_PERMISSION_DENIED;
+ /* LCOV_EXCL_STOP */
}
ret = ctsvc_db_company_delete(id, false);
if (CONTACTS_ERROR_NONE != ret) {
- CTS_ERR("DB error : ctsvc_begin_trans() Fail(%d)", ret);
+ /* LCOV_EXCL_START */
+ ERR("ctsvc_begin_trans() Fail(%d)", ret);
ctsvc_end_trans(false);
return ret;
+ /* LCOV_EXCL_STOP */
}
ctsvc_contact_update_display_name(contact_id, CONTACTS_DISPLAY_NAME_SOURCE_TYPE_COMPANY);
ret = ctsvc_db_contact_update_changed_time(contact_id);
if (CONTACTS_ERROR_NONE != ret) {
- CTS_ERR("DB error : ctsvc_db_contact_update_changed_time() Fail(%d)", ret);
+ /* LCOV_EXCL_START */
+ ERR("ctsvc_db_contact_update_changed_time() Fail(%d)", ret);
ctsvc_end_trans(false);
return ret;
+ /* LCOV_EXCL_STOP */
}
ctsvc_set_person_noti();
ret = ctsvc_end_trans(true);
if (ret < CONTACTS_ERROR_NONE) {
- CTS_ERR("DB error : ctsvc_end_trans() Fail(%d)", ret);
+ /* LCOV_EXCL_START */
+ ERR("ctsvc_end_trans() Fail(%d)", ret);
return ret;
- }
- else
+ /* LCOV_EXCL_STOP */
+ } else {
return CONTACTS_ERROR_NONE;
+ }
}
-static int __ctsvc_db_company_get_all_records(int offset, int limit, contacts_list_h* out_list)
+static int __ctsvc_db_company_get_all_records(int offset, int limit, contacts_list_h *out_list)
{
int len;
int ret;
len = snprintf(query, sizeof(query),
"SELECT id, data.contact_id, is_default, data1, data2, "
- "data3, data4, data5, data6, data7, data8, data9, data10, data11, data12 "
- "FROM "CTS_TABLE_DATA", "CTSVC_DB_VIEW_CONTACT" "
- "ON "CTS_TABLE_DATA".contact_id = "CTSVC_DB_VIEW_CONTACT".contact_id "
- "WHERE datatype=%d AND is_my_profile=0 ",
- CTSVC_DATA_COMPANY);
+ "data3, data4, data5, data6, data7, data8, data9, data10, data11, data12 "
+ "FROM "CTS_TABLE_DATA", "CTSVC_DB_VIEW_CONTACT" "
+ "ON "CTS_TABLE_DATA".contact_id = "CTSVC_DB_VIEW_CONTACT".contact_id "
+ "WHERE datatype=%d AND is_my_profile=0 ",
+ CONTACTS_DATA_TYPE_COMPANY);
if (0 != limit) {
len += snprintf(query+len, sizeof(query)-len, " LIMIT %d", limit);
}
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);
contacts_list_create(&list);
while ((ret = ctsvc_stmt_step(stmt))) {
if (1 /*CTS_TRUE */ != ret) {
- CTS_ERR("DB : ctsvc_stmt_step fail(%d)", ret);
+ /* LCOV_EXCL_START */
+ ERR("DB : ctsvc_stmt_step() Fail(%d)", ret);
ctsvc_stmt_finalize(stmt);
contacts_list_destroy(list, true);
return ret;
+ /* LCOV_EXCL_STOP */
}
ctsvc_db_company_get_value_from_stmt(stmt, (contacts_record_h*)&company, 0);
ctsvc_list_prepend(list, (contacts_record_h)company);
}
static int __ctsvc_db_company_get_records_with_query(contacts_query_h query, int offset,
- int limit, contacts_list_h* out_list)
+ int limit, contacts_list_h *out_list)
{
int ret;
int i;
ctsvc_company_s *company;
RETV_IF(NULL == query, CONTACTS_ERROR_INVALID_PARAMETER);
- s_query = (ctsvc_query_s *)query;
+ s_query = (ctsvc_query_s*)query;
ret = ctsvc_db_make_get_records_query_stmt(s_query, offset, limit, &stmt);
RETVM_IF(CONTACTS_ERROR_NONE != ret, ret, "ctsvc_db_make_get_records_query_stmt fail(%d)", ret);
while ((ret = ctsvc_stmt_step(stmt))) {
contacts_record_h record;
if (1 /*CTS_TRUE */ != 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);
contacts_list_destroy(list, true);
return ret;
+ /* LCOV_EXCL_STOP */
}
contacts_record_create(_contacts_company._uri, &record);
company = (ctsvc_company_s*)record;
- if (0 == s_query->projection_count)
+ if (0 == s_query->projection_count) {
field_count = s_query->property_count;
- else {
+ } else {
field_count = s_query->projection_count;
ret = ctsvc_record_set_projection_flags(record, s_query->projection,
s_query->projection_count, s_query->property_count);
ASSERT_NOT_REACHED("To set projection is Fail.\n");
}
- for (i=0;i<field_count;i++) {
+ for (i = 0; i < field_count; i++) {
char *temp;
int property_id;
if (0 == s_query->projection_count)
else
property_id = s_query->projection[i];
- switch(property_id) {
+ switch (property_id) {
case CTSVC_PROPERTY_COMPANY_ID:
company->id = ctsvc_stmt_get_int(stmt, i);
break;
return CONTACTS_ERROR_NONE;
}
-//static int __ctsvc_db_company_insert_records(const contacts_list_h in_list, int **ids) { return CONTACTS_ERROR_NONE; }
-//static int __ctsvc_db_company_update_records(const contacts_list_h in_list) { return CONTACTS_ERROR_NONE; }
-//static int __ctsvc_db_company_delete_records(int ids[], int count) { return CONTACTS_ERROR_NONE; }
+ctsvc_db_plugin_info_s ctsvc_db_plugin_company = {
+ .is_query_only = false,
+ .insert_record = __ctsvc_db_company_insert_record,
+ .get_record = __ctsvc_db_company_get_record,
+ .update_record = __ctsvc_db_company_update_record,
+ .delete_record = __ctsvc_db_company_delete_record,
+ .get_all_records = __ctsvc_db_company_get_all_records,
+ .get_records_with_query = __ctsvc_db_company_get_records_with_query,
+ .insert_records = NULL,
+ .update_records = NULL,
+ .delete_records = NULL,
+ .get_count = NULL,
+ .get_count_with_query = NULL,
+ .replace_record = NULL,
+ .replace_records = NULL,
+};
+