Languages

Menu
Sites
Language
How to filter contacts with phone number

I'm trying to query the contacts database with the help of filter, I'm using the following code to add filters

 

contacts_filter_h filter;
res = contacts_filter_create(_contacts_number._uri, &filter);
	if (res != CONTACTS_ERROR_NONE) {
		dlog_print(DLOG_DEBUG, "test", "contacts_filter_create-->Error-->%s",
				get_error_message(res));
	}
res = contacts_filter_add_str(filter, _contacts_number.number,
			CONTACTS_MATCH_FULLSTRING, "11111");
	if (res != CONTACTS_ERROR_NONE) {
		dlog_print(DLOG_DEBUG, "test", "contacts_filter_add_str-->Error-->%s",
				get_error_message(res));
	}

In the function catacts_filter_add_str I'm gettign "INVALID PARAMETER" error. I know that the type of the _contacts_number.number is not string but, I have no clue on how to query on the phone number. 

Responses

3 Replies
Alex Dem

Hi,
Maybe for int you should use contacts_filter_add_int with CONTACTS_MATCH_EQUAL, see also _get_filter_with_int_field in Native exampe ->Sample Contacts template application.
Alexey.

Vivek Chandra Amancha

But the property number is of type string?

Jean Yang

Hi, 

In contact sample contact-list-utils.c file, you can refer this:

static contacts_filter_h _get_filter_with_int_field(const char *table_uri, unsigned int filter_field, int int_val)
{
    RETVM_IF(NULL == table_uri, NULL, "table_uri is null");
    contacts_filter_h filter = NULL;

    if( !(sc_db_utils_is_success(contacts_filter_create(table_uri, &filter))
     && sc_db_utils_is_success(contacts_filter_add_int(filter, filter_field, CONTACTS_MATCH_EQUAL, int_val))))
    {
        contacts_filter_destroy(filter);
        filter = NULL;
    }
    return filter;
}