#!/system/bin/tcsh -f
#get named contact from number

if ( x"$1" == x ) then
	echo not_found
	exit
endif

set db=/data/data/com.android.providers.contacts/databases/contacts2.db
set id=`echo 'select raw_contact_id from data where data1=="'"$1"'";'|sqlite3 $db|head -1`
if ( x"$id" == x ) then
	echo not_found
	exit
endif
set isnumber=`echo $1|awk '{if($1 ~ "^[+0-9][+0-9]*$") print 1; else print 0;}'`
if ( $isnumber == 0 ) then
	set type=5
else 
	set type=7
endif
echo 'select data1 from data where raw_contact_id=='$id' and mimetype_id == '$type';' |sqlite3 $db

