Fix code for TDIS-5396
[framework/osp/social.git] / src / FScl_AddressbookUtil.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 /**
18  * @file                FScl_AddressbookUtil.cpp
19  * @brief               This is the implementation for _AddressbookUtil class.
20  *
21  * This file contains definitions of @e _AddressbookUtil class.
22  */
23
24 #include <stdlib.h>
25 #include <FBaseDateTime.h>
26 #include <FBaseColArrayList.h>
27 #include <FBaseColArrayListT.h>
28 #include <FSclTypes.h>
29 #include <FSclContact.h>
30 #include <FSclPerson.h>
31 #include <FSclCategory.h>
32 #include <FSclUserProfile.h>
33 #include <FSclUrl.h>
34 #include <FSclAddress.h>
35 #include <FSclImAddress.h>
36 #include <FSclContactEvent.h>
37 #include <FSclRelationship.h>
38 #include <FSclOrganization.h>
39 #include <FBaseSysLog.h>
40 #include <FBase_StringConverter.h>
41 #include <FSclContactChangeInfo.h>
42 #include <FScl_ContactChangeInfoImpl.h>
43 #include <FSclCategoryChangeInfo.h>
44 #include <FScl_CategoryChangeInfoImpl.h>
45 #include "FScl_AddressbookUtil.h"
46 #include "FScl_ContactImpl.h"
47 #include "FScl_CategoryImpl.h"
48 #include "FScl_RecordImpl.h"
49 #include <FSclPhoneNumberContact.h>
50 #include "FScl_PhoneNumberContactImpl.h"
51 #include <FSclEmailContact.h>
52 #include "FScl_EmailContactImpl.h"
53 #include "FScl_PersonImpl.h"
54 #include "FSclAddressbook.h"
55 #include "FScl_AddressbookImpl.h"
56 #include "FScl_UserProfileImpl.h"
57
58 using namespace Tizen::Base;
59 using namespace Tizen::Base::Collection;
60
61 namespace Tizen { namespace Social
62 {
63
64 template<>
65 Contact*
66 __ContactsContact::ConvertResultTo<Contact>(__SearchResult<__ContactsContact>& searchResult)
67 {
68         int intValue = 0;
69         contacts_record_h newRecord = null;
70
71         contacts_record_h currentRecord = searchResult.GetCurrentRecord();
72         SysTryReturn(NID_SCL, currentRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
73
74         std::unique_ptr<Contact> pContact(new (std::nothrow) Contact());
75         SysTryReturn(NID_SCL, pContact != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
76
77         contacts_record_clone(currentRecord, &newRecord);
78         SysTryReturn(NID_SCL, newRecord != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
79
80         _ContactImpl::GetInstance(*pContact)->SetContactRecordHandle(newRecord);
81
82         contacts_record_get_int(newRecord, _contacts_contact.id, &intValue);
83
84         _RecordImpl::GetInstance(*pContact)->SetRecordId(intValue);
85
86         return pContact.release();
87 }
88
89 template<>
90 Category*
91 __ContactsGroup::ConvertResultTo<Category>(__SearchResult<__ContactsGroup>& searchResult)
92 {
93         int intValue = 0;
94         contacts_record_h newRecord = null;
95
96         contacts_record_h currentRecord = searchResult.GetCurrentRecord();
97         SysTryReturn(NID_SCL, currentRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
98
99         std::unique_ptr<Category> pCategory(new (std::nothrow) Category());
100         SysTryReturn(NID_SCL, pCategory != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
101
102         contacts_record_clone(currentRecord, &newRecord);
103         SysTryReturn(NID_SCL, newRecord != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
104
105         _CategoryImpl::GetInstance(*pCategory)->SetRecordHandle(newRecord);
106
107         contacts_record_get_int(newRecord, _contacts_group.id, &intValue);
108
109         _RecordImpl::GetInstance(*pCategory)->SetRecordId(intValue);
110
111         __Filter<__ContactsGroupRelation> filter;
112         filter.Construct();
113         filter.AddInt(_contacts_group_relation.group_id, CONTACTS_MATCH_EQUAL, intValue);
114
115         __Query<__ContactsGroupRelation> query;
116         query.Construct();
117         query.SetFilter(filter);
118
119         int count = _AddressbookUtil::GetCountWithQuery(query);
120         SysTryReturn(NID_SCL, count >= 0, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
121
122         _CategoryImpl::GetInstance(*pCategory)->SetMemberCount(count);
123
124         return pCategory.release();
125 }
126
127 template<>
128 Category*
129 __ContactsGroupRelation::ConvertResultTo<Category>(__SearchResult<__ContactsGroupRelation>& searchResult)
130 {
131         SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
132
133         int intValue = 0;
134         contacts_record_h newRecord = null;
135
136         contacts_record_h currentRecord = searchResult.GetCurrentRecord();
137         SysTryReturn(NID_SCL, currentRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
138
139         std::unique_ptr<Category> pCategory(new (std::nothrow) Category());
140         SysTryReturn(NID_SCL, pCategory != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
141
142         contacts_record_get_int(currentRecord, _contacts_group_relation.group_id, &intValue);
143         SysTryReturn(NID_SCL, intValue > 0, null, E_OBJ_NOT_FOUND, "[%s] The category is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
144
145         int ret = contacts_db_get_record(_contacts_group._uri, intValue, &newRecord);
146         SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, null, E_OBJ_NOT_FOUND, "[%s] The category is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
147         SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
148         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
149
150         _CategoryImpl::GetInstance(*pCategory)->SetRecordHandle(newRecord);
151         _RecordImpl::GetInstance(*pCategory)->SetRecordId(intValue);
152
153         __Filter<__ContactsGroupRelation> filter;
154         filter.Construct();
155         filter.AddInt(_contacts_group_relation.group_id, CONTACTS_MATCH_EQUAL, intValue);
156
157         __Query<__ContactsGroupRelation> query;
158         query.Construct();
159         query.SetFilter(filter);
160
161         int count = _AddressbookUtil::GetCountWithQuery(query);
162         if (count < 0)
163         {
164                 SysTryReturn(NID_SCL, GetLastResult() != E_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
165                 SysTryReturn(NID_SCL, GetLastResult() != E_SYSTEM, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
166
167                 count = 0;
168         }
169
170         _CategoryImpl::GetInstance(*pCategory)->SetMemberCount(count);
171
172         return pCategory.release();
173 }
174
175 template<>
176 Category*
177 __ContactsContactGroupRel::ConvertResultTo<Category>(__SearchResult<__ContactsContactGroupRel>& searchResult)
178 {
179         SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
180
181         int intValue = 0;
182         contacts_record_h newRecord = null;
183
184         contacts_record_h currentRecord = searchResult.GetCurrentRecord();
185         SysTryReturn(NID_SCL, currentRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
186
187         std::unique_ptr<Category> pCategory(new (std::nothrow) Category());
188         SysTryReturn(NID_SCL, pCategory != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
189
190         contacts_record_get_int(currentRecord, _contacts_contact_grouprel.group_id, &intValue);
191         SysTryReturn(NID_SCL, intValue > 0, null, E_OBJ_NOT_FOUND, "[%s] The category is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
192
193         int ret = contacts_db_get_record(_contacts_group._uri, intValue, &newRecord);
194         SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, null, E_OBJ_NOT_FOUND, "[%s] The category is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
195         SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
196         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
197
198         _CategoryImpl::GetInstance(*pCategory)->SetRecordHandle(newRecord);
199         _RecordImpl::GetInstance(*pCategory)->SetRecordId(intValue);
200
201         __Filter<__ContactsGroupRelation> filter;
202         filter.Construct();
203         filter.AddInt(_contacts_group_relation.group_id, CONTACTS_MATCH_EQUAL, intValue);
204
205         __Query<__ContactsGroupRelation> query;
206         query.Construct();
207         query.SetFilter(filter);
208
209         int count = _AddressbookUtil::GetCountWithQuery(query);
210         if (count < 0)
211         {
212                 SysTryReturn(NID_SCL, GetLastResult() != E_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
213                 SysTryReturn(NID_SCL, GetLastResult() != E_SYSTEM, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
214
215                 count = 0;
216         }
217
218         _CategoryImpl::GetInstance(*pCategory)->SetMemberCount(count);
219
220         return pCategory.release();
221 }
222
223
224 template<>
225 Contact*
226 __ContactsContactGroupRel::ConvertResultTo<Contact>(__SearchResult<__ContactsContactGroupRel>& searchResult)
227 {
228         SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
229
230         int intValue = 0;
231         contacts_record_h newRecord = null;
232
233         contacts_record_h currentRecord = searchResult.GetCurrentRecord();
234         SysTryReturn(NID_SCL, currentRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
235
236         contacts_record_get_int(currentRecord, _contacts_contact_grouprel.contact_id, &intValue);
237         SysTryReturn(NID_SCL, intValue >= 0, null, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
238
239         std::unique_ptr<Contact> pContact(new (std::nothrow) Contact());
240         SysTryReturn(NID_SCL, pContact != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
241
242         int ret = contacts_db_get_record(_contacts_contact._uri, intValue, &newRecord);
243         SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, null, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
244         SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
245         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
246
247         _ContactImpl::GetInstance(*pContact)->SetContactRecordHandle(newRecord);
248         _RecordImpl::GetInstance(*pContact)->SetRecordId(intValue);
249
250         return pContact.release();
251 }
252
253 template<>
254 Contact*
255 __ContactsContactEmail::ConvertResultTo<Contact>(__SearchResult<__ContactsContactEmail>& searchResult)
256 {
257
258         SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
259
260         int intValue = 0;
261         contacts_record_h newRecord = null;
262
263         contacts_record_h currentRecord = searchResult.GetCurrentRecord();
264         SysTryReturn(NID_SCL, currentRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
265
266         contacts_record_get_int(currentRecord, _contacts_contact_email.contact_id, &intValue);
267         SysTryReturn(NID_SCL, intValue >= 0, null, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
268
269         std::unique_ptr<Contact> pContact(new (std::nothrow) Contact());
270         SysTryReturn(NID_SCL, pContact != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
271
272         int ret = contacts_db_get_record(_contacts_contact._uri, intValue, &newRecord);
273         SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, null, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
274         SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
275         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
276
277         _ContactImpl::GetInstance(*pContact)->SetContactRecordHandle(newRecord);
278         _RecordImpl::GetInstance(*pContact)->SetRecordId(intValue);
279
280         return pContact.release();
281 }
282
283 template<>
284 EmailContact*
285 __ContactsContactEmail::ConvertResultTo<EmailContact>(__SearchResult<__ContactsContactEmail>& queryResult)
286 {
287         int intValue = 0;
288         EmailType type = EMAIL_TYPE_PERSONAL;
289         char* pCharValue = null;
290         int emailRecordId = 0;
291         String label;
292         String email;
293
294         contacts_record_h recordHandle = queryResult.GetCurrentRecord();
295         SysTryReturn(NID_SCL, recordHandle != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
296
297         std::unique_ptr<EmailContact> pEmailContact(new (std::nothrow) EmailContact());
298         SysTryReturn(NID_SCL, pEmailContact != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
299
300         contacts_record_get_int(recordHandle, _contacts_contact_email.contact_id, &intValue);
301         _EmailContactImpl::GetInstance(*pEmailContact)->SetContactId(intValue);
302
303         contacts_record_get_int(recordHandle, _contacts_contact_email.person_id, &intValue);
304         _EmailContactImpl::GetInstance(*pEmailContact)->SetPersonId(intValue);
305
306         contacts_record_get_int(recordHandle, _contacts_contact_email.address_book_id, &intValue);
307         _EmailContactImpl::GetInstance(*pEmailContact)->SetAddressbookId(intValue);
308
309         contacts_record_get_str_p(recordHandle, _contacts_contact_email.display_name, &pCharValue);
310         _EmailContactImpl::GetInstance(*pEmailContact)->SetDisplayName(pCharValue);
311
312         contacts_record_get_str_p(recordHandle, _contacts_contact_email.image_thumbnail_path, &pCharValue);
313         _EmailContactImpl::GetInstance(*pEmailContact)->SetThumbnailPath(pCharValue);
314
315         contacts_record_get_str_p(recordHandle, _contacts_contact_email.ringtone_path, &pCharValue);
316         _EmailContactImpl::GetInstance(*pEmailContact)->SetRingtonePath(pCharValue);
317
318         // email id
319         contacts_record_get_int(recordHandle, _contacts_contact_email.email_id, &intValue);
320         emailRecordId = intValue;
321
322         // label
323         contacts_record_get_str_p(recordHandle, _contacts_contact_email.label, &pCharValue);
324         label = pCharValue;
325
326         // type
327         contacts_record_get_int(recordHandle, _contacts_contact_email.type, &intValue);
328         switch (intValue)
329         {
330         case CONTACTS_EMAIL_TYPE_HOME:
331                 type = EMAIL_TYPE_PERSONAL;
332                 break;
333         case CONTACTS_EMAIL_TYPE_WORK:
334                 type = EMAIL_TYPE_WORK;
335                 break;
336         case CONTACTS_EMAIL_TYPE_CUSTOM:
337                 type = EMAIL_TYPE_CUSTOM;
338                 break;
339         default:
340                 type = EMAIL_TYPE_OTHER;
341                 break;
342         }
343
344         // email
345         contacts_record_get_str_p(recordHandle, _contacts_contact_email.email, &pCharValue);
346         email = pCharValue;
347
348         _EmailContactImpl::GetInstance(*pEmailContact)->SetEmailData(emailRecordId, type, label, email);
349
350         return pEmailContact.release();
351 }
352
353 template<>
354 Contact*
355 __ContactsContactNumber::ConvertResultTo<Contact>(__SearchResult<__ContactsContactNumber>& searchResult)
356 {
357         SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
358
359         int intValue = 0;
360         contacts_record_h newRecord = null;
361
362         contacts_record_h currentRecord = searchResult.GetCurrentRecord();
363         SysTryReturn(NID_SCL, currentRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
364
365         contacts_record_get_int(currentRecord, _contacts_contact_number.contact_id, &intValue);
366         SysTryReturn(NID_SCL, intValue >= 0, null, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
367
368         std::unique_ptr<Contact> pContact(new (std::nothrow) Contact());
369         SysTryReturn(NID_SCL, pContact != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
370
371         int ret = contacts_db_get_record(_contacts_contact._uri, intValue, &newRecord);
372         SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, null, E_OBJ_NOT_FOUND, "[%s] The contact is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
373         SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
374         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
375
376         _ContactImpl::GetInstance(*pContact)->SetContactRecordHandle(newRecord);
377         _RecordImpl::GetInstance(*pContact)->SetRecordId(intValue);
378
379         return pContact.release();
380 }
381
382 template<>
383 PhoneNumberContact*
384 __ContactsContactNumber::ConvertResultTo<PhoneNumberContact>(__SearchResult<__ContactsContactNumber>& queryResult)
385 {
386         int intValue = 0;
387         PhoneNumberType type = PHONENUMBER_TYPE_HOME;
388         char* pCharValue = null;
389         int numberRecordId = 0;
390         String label;
391         String number;
392
393         contacts_record_h recordHandle = queryResult.GetCurrentRecord();
394         SysTryReturn(NID_SCL, recordHandle != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
395
396         std::unique_ptr<PhoneNumberContact> pPhoneNumberContact(new (std::nothrow) PhoneNumberContact());
397         SysTryReturn(NID_SCL, pPhoneNumberContact != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
398
399         contacts_record_get_int(recordHandle, _contacts_contact_number.contact_id, &intValue);
400         _PhoneNumberContactImpl::GetInstance(*pPhoneNumberContact)->SetContactId(intValue);
401
402         contacts_record_get_int(recordHandle, _contacts_contact_number.person_id, &intValue);
403         _PhoneNumberContactImpl::GetInstance(*pPhoneNumberContact)->SetPersonId(intValue);
404
405         contacts_record_get_int(recordHandle, _contacts_contact_number.address_book_id, &intValue);
406         _PhoneNumberContactImpl::GetInstance(*pPhoneNumberContact)->SetAddressbookId(intValue);
407
408         contacts_record_get_str_p(recordHandle, _contacts_contact_number.display_name, &pCharValue);
409         _PhoneNumberContactImpl::GetInstance(*pPhoneNumberContact)->SetDisplayName(pCharValue);
410
411         contacts_record_get_str_p(recordHandle, _contacts_contact_number.image_thumbnail_path, &pCharValue);
412         _PhoneNumberContactImpl::GetInstance(*pPhoneNumberContact)->SetThumbnailPath(pCharValue);
413
414         contacts_record_get_str_p(recordHandle, _contacts_contact_number.ringtone_path, &pCharValue);
415         _PhoneNumberContactImpl::GetInstance(*pPhoneNumberContact)->SetRingtonePath(pCharValue);
416
417         // number id
418         contacts_record_get_int(recordHandle, _contacts_contact_number.number_id, &intValue);
419         numberRecordId = intValue;
420
421         // label
422         contacts_record_get_str_p(recordHandle, _contacts_contact_number.label, &pCharValue);
423         label = pCharValue;
424
425         // type
426         contacts_record_get_int(recordHandle, _contacts_contact_number.type, &intValue);
427         switch (intValue)
428         {
429                 case CONTACTS_NUMBER_TYPE_HOME | CONTACTS_NUMBER_TYPE_VOICE:
430                         type = PHONENUMBER_TYPE_HOME;
431                         break;
432                 case CONTACTS_NUMBER_TYPE_WORK | CONTACTS_NUMBER_TYPE_VOICE:
433                         type = PHONENUMBER_TYPE_WORK;
434                         break;
435                 case CONTACTS_NUMBER_TYPE_CELL:
436                         type = PHONENUMBER_TYPE_MOBILE;
437                         break;
438                 case CONTACTS_NUMBER_TYPE_FAX | CONTACTS_NUMBER_TYPE_HOME:
439                         type = PHONENUMBER_TYPE_HOME_FAX;
440                         break;
441                 case CONTACTS_NUMBER_TYPE_FAX | CONTACTS_NUMBER_TYPE_WORK:
442                         type = PHONENUMBER_TYPE_WORK_FAX;
443                         break;
444                 case CONTACTS_NUMBER_TYPE_PAGER:
445                         type = PHONENUMBER_TYPE_PAGER;
446                         break;
447                 case CONTACTS_NUMBER_TYPE_CUSTOM:
448                         type = PHONENUMBER_TYPE_CUSTOM;
449                         break;
450                 default:
451                         type = PHONENUMBER_TYPE_OTHER;
452                         break;
453         }
454
455         // number
456         contacts_record_get_str_p(recordHandle, _contacts_contact_number.number, &pCharValue);
457         number = pCharValue;
458
459         _PhoneNumberContactImpl::GetInstance(*pPhoneNumberContact)->SetPhoneNumberData(numberRecordId, type, label, number);
460
461         return pPhoneNumberContact.release();
462 }
463
464 template<>
465 Addressbook*
466 __ContactsAddressbook::ConvertResultTo<Addressbook>(__SearchResult<__ContactsAddressbook>& queryResult)
467 {
468         int intValue = 0;
469         char* pCharValue = null;
470
471         contacts_record_h currentRecord = queryResult.GetCurrentRecord();
472         SysTryReturn(NID_SCL, currentRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
473
474         std::unique_ptr<Addressbook> pAddressbook(new (std::nothrow) Addressbook());
475         SysTryReturn(NID_SCL, pAddressbook != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
476
477         result r = pAddressbook->Construct();
478         SysTryReturn(NID_SCL, !IsFailed(r), null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
479
480         contacts_record_get_int(currentRecord, _contacts_address_book.id, &intValue);
481         _AddressbookImpl::GetInstance(*pAddressbook)->SetId(intValue);
482
483         contacts_record_get_str_p(currentRecord, _contacts_address_book.name, &pCharValue);
484         _AddressbookImpl::GetInstance(*pAddressbook)->SetName(pCharValue);
485
486         contacts_record_get_int(currentRecord, _contacts_address_book.account_id, &intValue);
487         _AddressbookImpl::GetInstance(*pAddressbook)->SetAccountId(intValue);
488
489         return pAddressbook.release();
490 }
491
492
493
494 template<>
495 Person*
496 __ContactsPerson::ConvertResultTo<Person>(__SearchResult<__ContactsPerson>& queryResult)
497 {
498         int intValue = 0;
499         char* pCharValue = null;
500         bool boolValue = false;
501
502         contacts_record_h currentRecord = queryResult.GetCurrentRecord();
503         SysTryReturn(NID_SCL, currentRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
504
505         std::unique_ptr<Person> pPerson(_AddressbookUtil::CreatePersonN());
506         SysTryReturn(NID_SCL, pPerson != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
507
508         contacts_record_get_int(currentRecord, _contacts_person.id, &intValue);
509         _PersonImpl::GetInstance(*pPerson)->SetId(intValue);
510
511         contacts_record_get_str_p(currentRecord, _contacts_person.addressbook_ids, &pCharValue);
512         _PersonImpl::GetInstance(*pPerson)->SetAddressbookIdString(pCharValue);
513
514         contacts_record_get_bool(currentRecord, _contacts_person.is_favorite, &boolValue);
515         _PersonImpl::GetInstance(*pPerson)->SetIsFavorite(boolValue);
516
517         contacts_record_get_bool(currentRecord, _contacts_person.has_phonenumber, &boolValue);
518         _PersonImpl::GetInstance(*pPerson)->SetHasPhoneNumber(boolValue);
519
520         contacts_record_get_bool(currentRecord, _contacts_person.has_email, &boolValue);
521         _PersonImpl::GetInstance(*pPerson)->SetHasEmail(boolValue);
522
523         contacts_record_get_str_p(currentRecord, _contacts_person.image_thumbnail_path, &pCharValue);
524         _PersonImpl::GetInstance(*pPerson)->SetThumbnailPath(pCharValue);
525
526         contacts_record_get_str_p(currentRecord, _contacts_person.ringtone_path, &pCharValue);
527         _PersonImpl::GetInstance(*pPerson)->SetRingtonePath(pCharValue);
528
529         contacts_record_get_str_p(currentRecord, _contacts_person.display_name, &pCharValue);
530         _PersonImpl::GetInstance(*pPerson)->SetDisplayName(pCharValue);
531         
532         return pPerson.release();
533
534 }
535
536 Person*
537 _AddressbookUtil::CreatePersonN(void)
538 {
539         Person* pPerson = new (std::nothrow) Person();
540         return pPerson;         
541 }
542
543 template<>
544 Person*
545 __ContactsPersonGroupRel::ConvertResultTo<Person>(__SearchResult<__ContactsPersonGroupRel>& searchResult)
546 {
547         int intValue = 0;
548         char* pCharValue = null;
549         bool boolValue = false;
550
551         contacts_record_h currentRecord = searchResult.GetCurrentRecord();
552         SysTryReturn(NID_SCL, currentRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
553
554         std::unique_ptr<Person> pPerson(_AddressbookUtil::CreatePersonN());
555         SysTryReturn(NID_SCL, pPerson != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
556
557         contacts_record_get_int(currentRecord, _contacts_person_grouprel.person_id, &intValue);
558         _PersonImpl::GetInstance(*pPerson)->SetId(intValue);
559
560         contacts_record_get_str_p(currentRecord, _contacts_person_grouprel.addressbook_ids, &pCharValue);
561         _PersonImpl::GetInstance(*pPerson)->SetAddressbookIdString(pCharValue);
562
563         contacts_record_get_bool(currentRecord, _contacts_person_grouprel.is_favorite, &boolValue);
564         _PersonImpl::GetInstance(*pPerson)->SetIsFavorite(boolValue);
565
566         contacts_record_get_bool(currentRecord, _contacts_person_grouprel.has_phonenumber, &boolValue);
567         _PersonImpl::GetInstance(*pPerson)->SetHasPhoneNumber(boolValue);
568
569         contacts_record_get_bool(currentRecord, _contacts_person_grouprel.has_email, &boolValue);
570         _PersonImpl::GetInstance(*pPerson)->SetHasEmail(boolValue);
571
572         contacts_record_get_str_p(currentRecord, _contacts_person_grouprel.image_thumbnail_path, &pCharValue);
573         _PersonImpl::GetInstance(*pPerson)->SetThumbnailPath(pCharValue);
574
575         contacts_record_get_str_p(currentRecord, _contacts_person_grouprel.ringtone_path, &pCharValue);
576         _PersonImpl::GetInstance(*pPerson)->SetRingtonePath(pCharValue);
577
578         contacts_record_get_str_p(currentRecord, _contacts_person_grouprel.display_name, &pCharValue);
579         _PersonImpl::GetInstance(*pPerson)->SetDisplayName(pCharValue);
580         
581         return pPerson.release();
582 }
583
584 template<>
585 Category*
586 __ContactsPersonGroupRel::ConvertResultTo<Category>(__SearchResult<__ContactsPersonGroupRel>& searchResult)
587 {
588         SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
589
590         int intValue = 0;
591         contacts_record_h newRecord = null;
592
593         contacts_record_h currentRecord = searchResult.GetCurrentRecord();
594         SysTryReturn(NID_SCL, currentRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
595
596         std::unique_ptr<Category> pCategory(new (std::nothrow) Category());
597         SysTryReturn(NID_SCL, pCategory != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
598
599         contacts_record_get_int(currentRecord, _contacts_person_grouprel.group_id, &intValue);
600         SysTryReturn(NID_SCL, intValue > 0, null, E_OBJ_NOT_FOUND, "[%s] The category is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
601
602         int ret = contacts_db_get_record(_contacts_group._uri, intValue, &newRecord);
603         SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_NO_DATA, null, E_OBJ_NOT_FOUND, "[%s] The category is not found.", GetErrorMessage(E_OBJ_NOT_FOUND));
604         SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
605         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
606
607         _CategoryImpl::GetInstance(*pCategory)->SetRecordHandle(newRecord);
608         _RecordImpl::GetInstance(*pCategory)->SetRecordId(intValue);
609
610         __Filter<__ContactsGroupRelation> filter;
611         filter.Construct();
612         filter.AddInt(_contacts_group_relation.group_id, CONTACTS_MATCH_EQUAL, intValue);
613
614         __Query<__ContactsGroupRelation> query;
615         query.Construct();
616         query.SetFilter(filter);
617
618         int count = _AddressbookUtil::GetCountWithQuery(query);
619         if (count < 0)
620         {
621                 SysTryReturn(NID_SCL, GetLastResult() != E_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
622                 SysTryReturn(NID_SCL, GetLastResult() != E_SYSTEM, null, E_SYSTEM, "[%s] A system error has been occurred.", GetErrorMessage(E_SYSTEM));
623
624                 count = 0;
625         }
626
627         _CategoryImpl::GetInstance(*pCategory)->SetMemberCount(count);
628
629         return pCategory.release();
630 }
631
632 template<>
633 Person*
634 __ContactsPerson::ConvertHandleTo<Person>(contacts_record_h recordHandle)
635 {
636         int intValue = 0;
637         char* pCharValue = null;
638         bool boolValue = false;
639
640         std::unique_ptr<Person> pPerson(_AddressbookUtil::CreatePersonN());
641         SysTryReturn(NID_SCL, pPerson != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
642
643         contacts_record_get_int(recordHandle, _contacts_person.id, &intValue);
644         _PersonImpl::GetInstance(*pPerson)->SetId(intValue);
645
646         contacts_record_get_str_p(recordHandle, _contacts_person.addressbook_ids, &pCharValue);
647         _PersonImpl::GetInstance(*pPerson)->SetAddressbookIdString(pCharValue);
648
649         contacts_record_get_bool(recordHandle, _contacts_person.is_favorite, &boolValue);
650         _PersonImpl::GetInstance(*pPerson)->SetIsFavorite(boolValue);
651
652         contacts_record_get_bool(recordHandle, _contacts_person.has_phonenumber, &boolValue);
653         _PersonImpl::GetInstance(*pPerson)->SetHasPhoneNumber(boolValue);
654
655         contacts_record_get_bool(recordHandle, _contacts_person.has_email, &boolValue);
656         _PersonImpl::GetInstance(*pPerson)->SetHasEmail(boolValue);
657
658         contacts_record_get_str_p(recordHandle, _contacts_person.image_thumbnail_path, &pCharValue);
659         _PersonImpl::GetInstance(*pPerson)->SetThumbnailPath(pCharValue);
660
661         contacts_record_get_str_p(recordHandle, _contacts_person.ringtone_path, &pCharValue);
662         _PersonImpl::GetInstance(*pPerson)->SetRingtonePath(pCharValue);
663
664         contacts_record_get_str_p(recordHandle, _contacts_person.display_name, &pCharValue);
665         _PersonImpl::GetInstance(*pPerson)->SetDisplayName(pCharValue);
666         
667         return pPerson.release();
668 }
669
670 template<>
671 Person*
672 __ContactsPersonGroupRel::ConvertHandleTo<Person>(contacts_record_h recordHandle)
673 {
674         int intValue = 0;
675         char* pCharValue = null;
676         bool boolValue = false;
677
678         std::unique_ptr<Person> pPerson(_AddressbookUtil::CreatePersonN());
679         SysTryReturn(NID_SCL, pPerson != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
680
681         contacts_record_get_int(recordHandle, _contacts_person_grouprel.person_id, &intValue);
682         _PersonImpl::GetInstance(*pPerson)->SetId(intValue);
683
684         contacts_record_get_str_p(recordHandle, _contacts_person_grouprel.addressbook_ids, &pCharValue);
685         _PersonImpl::GetInstance(*pPerson)->SetAddressbookIdString(pCharValue);
686
687         contacts_record_get_bool(recordHandle, _contacts_person_grouprel.is_favorite, &boolValue);
688         _PersonImpl::GetInstance(*pPerson)->SetIsFavorite(boolValue);
689
690         contacts_record_get_bool(recordHandle, _contacts_person_grouprel.has_phonenumber, &boolValue);
691         _PersonImpl::GetInstance(*pPerson)->SetHasPhoneNumber(boolValue);
692
693         contacts_record_get_bool(recordHandle, _contacts_person_grouprel.has_email, &boolValue);
694         _PersonImpl::GetInstance(*pPerson)->SetHasEmail(boolValue);
695
696         contacts_record_get_str_p(recordHandle, _contacts_person_grouprel.image_thumbnail_path, &pCharValue);
697         _PersonImpl::GetInstance(*pPerson)->SetThumbnailPath(pCharValue);
698
699         contacts_record_get_str_p(recordHandle, _contacts_person_grouprel.ringtone_path, &pCharValue);
700         _PersonImpl::GetInstance(*pPerson)->SetRingtonePath(pCharValue);
701
702         contacts_record_get_str_p(recordHandle, _contacts_person_grouprel.display_name, &pCharValue);
703         _PersonImpl::GetInstance(*pPerson)->SetDisplayName(pCharValue);
704         
705         return pPerson.release();
706 }
707
708 template<>
709 ContactChangeInfo*
710 __ContactsContactUpdatedInfo::ConvertResultTo(__SearchResult<__ContactsContactUpdatedInfo>& searchResult)
711 {
712         int intValue = 0;
713         bool boolValue = false;
714         RecordChangeType changeType = RECORD_CHANGE_TYPE_ADDED;
715
716         contacts_record_h currentRecord = searchResult.GetCurrentRecord();
717         SysTryReturn(NID_SCL, currentRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
718
719         std::unique_ptr<ContactChangeInfo> pContactChagneInfo(new (std::nothrow) ContactChangeInfo());
720         SysTryReturn(NID_SCL, pContactChagneInfo != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
721
722         contacts_record_get_int(currentRecord, _contacts_contact_updated_info.contact_id, &intValue);
723         _ContactChangeInfoImpl::GetInstance(*pContactChagneInfo)->SetContactId(intValue);
724
725         contacts_record_get_int(currentRecord, _contacts_contact_updated_info.address_book_id, &intValue);
726         _ContactChangeInfoImpl::GetInstance(*pContactChagneInfo)->SetAddressbookId(intValue);
727
728         contacts_record_get_int(currentRecord, _contacts_contact_updated_info.type, &intValue);
729
730         switch (intValue)
731         {
732                 case CONTACTS_CHANGE_INSERTED:
733                         changeType = RECORD_CHANGE_TYPE_ADDED;
734                         break;
735                 case CONTACTS_CHANGE_UPDATED:
736                         changeType = RECORD_CHANGE_TYPE_UPDATED;
737                         break;
738                 case CONTACTS_CHANGE_DELETED:
739                         // fall through
740                 default:
741                         changeType = RECORD_CHANGE_TYPE_REMOVED;
742                         break;
743         }
744
745         _ContactChangeInfoImpl::GetInstance(*pContactChagneInfo)->SetChangeType(changeType);
746
747         contacts_record_get_int(currentRecord, _contacts_contact_updated_info.version, &intValue);
748         _ContactChangeInfoImpl::GetInstance(*pContactChagneInfo)->SetVersion(intValue);
749
750         contacts_record_get_bool(currentRecord, _contacts_contact_updated_info.image_changed, &boolValue);
751         _ContactChangeInfoImpl::GetInstance(*pContactChagneInfo)->SetThumbnailChangeStatus(boolValue);
752
753         return pContactChagneInfo.release();
754 }
755
756 template<>
757 CategoryChangeInfo*
758 __ContactsGroupUpdatedInfo::ConvertResultTo(__SearchResult<__ContactsGroupUpdatedInfo>& searchResult)
759 {
760         int intValue = 0;
761         RecordChangeType changeType = RECORD_CHANGE_TYPE_ADDED;
762
763         contacts_record_h currentRecord = searchResult.GetCurrentRecord();
764         SysTryReturn(NID_SCL, currentRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
765
766         std::unique_ptr<CategoryChangeInfo> pCategoryChangeInfo(new (std::nothrow) CategoryChangeInfo());
767         SysTryReturn(NID_SCL, pCategoryChangeInfo != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
768
769         contacts_record_get_int(currentRecord, _contacts_group_updated_info.group_id, &intValue);
770         _CategoryChangeInfoImpl::GetInstance(*pCategoryChangeInfo)->SetCategoryId(intValue);
771
772         contacts_record_get_int(currentRecord, _contacts_group_updated_info.address_book_id, &intValue);
773         _CategoryChangeInfoImpl::GetInstance(*pCategoryChangeInfo)->SetAddressbookId(intValue);
774
775         contacts_record_get_int(currentRecord, _contacts_group_updated_info.type, &intValue);
776
777         switch (intValue)
778         {
779                 case CONTACTS_CHANGE_INSERTED:
780                         changeType = RECORD_CHANGE_TYPE_ADDED;
781                         break;
782                 case CONTACTS_CHANGE_UPDATED:
783                         changeType = RECORD_CHANGE_TYPE_UPDATED;
784                         break;
785                 case CONTACTS_CHANGE_DELETED:
786                         // fall through
787                 default:
788                         changeType = RECORD_CHANGE_TYPE_REMOVED;
789                         break;
790         }
791
792         _CategoryChangeInfoImpl::GetInstance(*pCategoryChangeInfo)->SetChangeType(changeType);
793
794         contacts_record_get_int(currentRecord, _contacts_group_updated_info.version, &intValue);
795         _CategoryChangeInfoImpl::GetInstance(*pCategoryChangeInfo)->SetVersion(intValue);
796
797         return pCategoryChangeInfo.release();
798 }
799
800 template<>
801 CategoryChangeInfo*
802 __ContactsGroupRelUpdatedInfo::ConvertResultTo(__SearchResult<__ContactsGroupRelUpdatedInfo>& searchResult)
803 {
804         int intValue = 0;
805
806         contacts_record_h currentRecord = searchResult.GetCurrentRecord();
807         SysTryReturn(NID_SCL, currentRecord != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
808
809         std::unique_ptr<CategoryChangeInfo> pCategoryChangeInfo(new (std::nothrow) CategoryChangeInfo());
810         SysTryReturn(NID_SCL, pCategoryChangeInfo != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
811
812         contacts_record_get_int(currentRecord, _contacts_grouprel_updated_info.group_id, &intValue);
813         _CategoryChangeInfoImpl::GetInstance(*pCategoryChangeInfo)->SetCategoryId(intValue);
814
815         contacts_record_get_int(currentRecord, _contacts_grouprel_updated_info.version, &intValue);
816         _CategoryChangeInfoImpl::GetInstance(*pCategoryChangeInfo)->SetVersion(intValue);
817
818         contacts_record_get_int(currentRecord, _contacts_grouprel_updated_info.address_book_id, &intValue);
819         _CategoryChangeInfoImpl::GetInstance(*pCategoryChangeInfo)->SetAddressbookId(intValue);
820
821         contacts_record_get_int(currentRecord, _contacts_grouprel_updated_info.type, &intValue);
822
823         _CategoryChangeInfoImpl::GetInstance(*pCategoryChangeInfo)->SetChangeType(RECORD_CHANGE_TYPE_UPDATED);
824
825         contacts_record_get_int(currentRecord, _contacts_grouprel_updated_info.version, &intValue);
826         _CategoryChangeInfoImpl::GetInstance(*pCategoryChangeInfo)->SetVersion(intValue);
827
828         return pCategoryChangeInfo.release();
829 }
830
831 template<>
832 UserProfile*
833 __ContactsUserProfile::ConvertResultTo<UserProfile>(__SearchResult<__ContactsUserProfile>& searchResult)
834 {
835         contacts_record_h newRecord = null;
836
837         contacts_record_h currentRecord = searchResult.GetCurrentRecord();
838         SysTryReturn(NID_SCL, currentRecord != null, null, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(E_SYSTEM));
839
840         std::unique_ptr<UserProfile> pProfile(new (std::nothrow) UserProfile());
841         SysTryReturn(NID_SCL, pProfile != null, null, E_OUT_OF_MEMORY, "[%s] Propagating.", GetErrorMessage(E_OUT_OF_MEMORY));
842
843         contacts_record_clone(currentRecord, &newRecord);
844         SysTryReturn(NID_SCL, newRecord != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
845
846         _UserProfileImpl::GetInstance(*pProfile)->SetUserProfileHandle(newRecord);
847
848         return pProfile.release();
849 }
850
851 template<>
852  __SearchResult<__ContactsPerson>*
853 _AddressbookUtil::Search(const Tizen::Base::String& keyword)
854 {
855         SysTryReturn(NID_SCL, _ContactDbConnector::EnsureDbConnection() == E_SUCCESS, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
856
857         __SearchResult<__ContactsPerson>* pQueryResult = null;
858
859         contacts_list_h list = null;
860         std::unique_ptr<char[]> pKeyword(_StringConverter::CopyToCharArrayN(keyword));
861
862         int ret = contacts_db_search_records(__ContactsPerson::GetUri(), pKeyword.get(), 0, 0, &list);
863         SysTryReturn(NID_SCL, ret != CONTACTS_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
864         SysTryReturn(NID_SCL, ret == CONTACTS_ERROR_NONE, null, E_SYSTEM, "[E_SYSTEM] A system error has occurred.");
865
866         pQueryResult = new (std::nothrow) __SearchResult<__ContactsPerson>(list);
867         SysTryReturn(NID_SCL, pQueryResult, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
868
869         return pQueryResult;
870 }
871
872 }}  // Tizen::Social