[Nexus One General] soneedu:
by replace the libsqlite.so libcudata.so can display sorted chinese contact .

below is the way to add function search by name, but it is for android 1.6. I found the contacts.db is different from Android 2.1.

no "pepole persons contact_methods" tables

only "contacts name_lookup phone_lookup"

i did not understand the co-relation beside these tables, some guy can help to change below scripts on Android 2.1 ??

Thanks very much.

Android 2.1 contacts2.db

sqlite> .tables
.tables
_sync_state status_updates
_sync_state_metadata v1_settings
activities view_contacts
agg_exceptions view_contacts_restricted
android_metadata view_data
calls view_data_restricted
contact_entities_view view_groups
contact_entities_view_restricted view_raw_contacts
contacts view_raw_contacts_restricted
data view_v1_contact_methods
groups view_v1_extensions
mimetypes view_v1_group_membership
name_lookup view_v1_groups
nickname_lookup view_v1_organizations
packages view_v1_people
phone_lookup view_v1_phones
raw_contacts view_v1_photos
settings

sqlite> .schema contacts
.schema contacts
CREATE TABLE contacts (_id INTEGER PRIMARY KEY AUTOINCREMENT,display_name TEXT,p
hoto_id INTEGER REFERENCES data(_id),custom_ringtone TEXT,send_to_voicemail INTE
GER NOT NULL DEFAULT 0,times_contacted INTEGER NOT NULL DEFAULT 0,last_time_cont
acted INTEGER,starred INTEGER NOT NULL DEFAULT 0,in_visible_group INTEGER NOT NU
LL DEFAULT 1,has_phone_number INTEGER NOT NULL DEFAULT 0,lookup TEXT,status_upda
te_id INTEGER REFERENCES data(_id),single_is_restricted INTEGER NOT NULL DEFAULT
0);
CREATE INDEX contacts_has_phone_index ON contacts (has_phone_number);
CREATE INDEX contacts_restricted_index ON contacts (single_is_restricted);
CREATE INDEX contacts_visible_index ON contacts (in_visible_group,display_name C
OLLATE LOCALIZED);
CREATE TRIGGER contacts_times_contacted UPDATE OF last_time_contacted ON contact
s BEGIN UPDATE contacts SET times_contacted = (new.times_contacted + 1) WHERE _i
d = new._id;END;

sqlite> .schema name_lookup
.schema name_lookup
CREATE TABLE name_lookup (data_id INTEGER REFERENCES data(_id) NOT NULL,raw_cont
act_id INTEGER REFERENCES raw_contacts(_id) NOT NULL,normalized_name TEXT NOT NU
LL,name_type INTEGER NOT NULL,PRIMARY KEY (data_id, normalized_name, name_type))
;
CREATE INDEX name_lookup_index ON name_lookup (normalized_name,name_type, raw_co
ntact_id);
CREATE INDEX name_lookup_raw_contact_id_index ON name_lookup (raw_contact_id);

sqlite> .schema phone_lookup
.schema phone_lookup
CREATE TABLE phone_lookup (data_id INTEGER PRIMARY KEY REFERENCES data(_id) NOT
NULL,raw_contact_id INTEGER REFERENCES raw_contacts(_id) NOT NULL,normalized_num
ber TEXT NOT NULL);
CREATE INDEX phone_lookup_index ON phone_lookup (normalized_number,raw_contact_i
d,data_id);

echo 'Phase 1: Creating triggers...'
#Replace the offical trigger to index email address
sqlite3 contacts.db "DROP TRIGGER IF EXISTS peopleLookup_update;"
sqlite3 contacts.db \
"CREATE TRIGGER peopleLookup_update \
UPDATE OF name ON people \
BEGIN\
DELETE FROM peopleLookup WHERE source = new._id;\
SELECT _TOKENIZE('peopleLookup', new._id, new.name, ' ');\
SELECT _TOKENIZE('peopleLookup', new._id, data, '')\
FROM contact_methods\
WHERE person=new._id AND kind=1; \
END"

# Trig the peopleLookup_updats trigger
sqlite3 contacts.db "DROP TRIGGER IF EXISTS sunner_email_update;"
sqlite3 contacts.db \
"CREATE TRIGGER IF NOT EXISTS sunner_email_update \
AFTER UPDATE OF data ON contact_methods \
WHEN new.kind=1 \
BEGIN \
UPDATE people SET name=\`name\` WHERE _id=new.person; \
END"

sqlite3 contacts.db \
"CREATE TRIGGER IF NOT EXISTS sunner_email_insert \
AFTER INSERT ON contact_methods \
WHEN new.kind=1 \
BEGIN \
SELECT _TOKENIZE('peopleLookup', new.person, new.data, ''); \
END"