iPhone 数据库结构

一、AddressBook.sqlitedb 通讯录数据库

location: /private/var/root/Library/AddressBook/AddressBook.sqlitedb

1.ABGroup 联系人分组信息
ROWID:组ID,自增PK
Name:组名

2.ABGroupChanges 分组信息更新
record:
type:

3.ABGroupMembers 组联系人
UID: PK
group_id:组ID,对应ABGroup.ROWID
member_type: 组员类别
member_id: 组员(联系人)ID,对应ABPerson.ROWID
注意:UNIQUE(group_id, member_type, member_id)

4.ABMultiValue 存储联系人的各种联系方式
UID: PK
record_id: 联系人ID,对应ABPerson.ROWID
property: 属性值. 3.电话; 4.email; 待补充…
identifier: 标识符.0,1,2,3,4,目前所知用于排序
label: 标志值. 1.mobile;2.home;3.work;4.other;5.homepage(URL) 对应ABMultiValueLabel.value
value: 值. 例如一个手机号码13800138000,或一个email地址foo@bar.com

5.ABMultiValueEntry (未知)
parent_id: (未知)
key: (未知)
value: (未知)
注意:UNIQUE(parent_id, key)

6.ABMultiValueEntryKey (未知)
value: (未知)
注意:UNIQUE(value)

7.ABMultiValueLabel 联系方式标志值列表
value: 见ABMultiValue.label

8.ABPerson
ROWID 自增PK,也是联系人的唯一标识
First 名字
Last 姓
Middle (未定)
FirstPhonetic (未定,貌似留作语音拨号用的)
MiddlePhonetic (未定,貌似留作语音拨号用的)
LastPhonetic (未定,貌似留作语音拨号用的)
Organization 所在公司,组织
Department 所在部门
Note 注释
Kind 未定
Birthday 生日
JobTitle 头衔
Nickname 昵称
Prefix 前缀
Suffix 后缀
FirstSort 排序用(具体未知)
LastSort 排序用(具体未知)
CreationDate 创建时间
ModificationDate 最后修改时间
CompositeNameFallback (未知)

9.ABPersonChanges (未知)
record
type

10.ABPersonMultiValueDeletes (未知)
record_id
property_id
identifier

11.ABPhoneLastFour 电话号码后四位匹配表
multivalue_id 对应ABMultiValue.UID
value 电话号码后四位

12.ABRecent (未知)
date
name
property
value

13.sorting_first_section_list (未知)
character
number

14.sorting_last_section_list (未知)
character
number

15.sqlite_sequence (用于记录序列)
name:表命,如ABPerson
seq: 最新序列号

— ==========下面是建表语句==========

view plaincopy to clipboardprint?
<SPAN style="FONT-WEIGHT: bold; COLOR: #993333">CREATE</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">TABLE</SPAN> ABGroup <SPAN style="COLOR: #66cc66">(</SPAN>ROWID INTEGER <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">PRIMARY</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">KEY</SPAN> AUTOINCREMENT<SPAN style="COLOR: #66cc66">,</SPAN> Name TEXT<SPAN style="COLOR: #66cc66">)</SPAN>;  
<SPAN style="FONT-WEIGHT: bold; COLOR: #993333">CREATE</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">TABLE</SPAN> ABGroupChanges <SPAN style="COLOR: #66cc66">(</SPAN>record INTEGER<SPAN style="COLOR: #66cc66">,</SPAN> type INTEGER<SPAN style="COLOR: #66cc66">)</SPAN>;  
<SPAN style="FONT-WEIGHT: bold; COLOR: #993333">CREATE</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">TABLE</SPAN> ABGroupMembers <SPAN style="COLOR: #66cc66">(</SPAN>UID INTEGER <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">PRIMARY</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">KEY</SPAN><SPAN style="COLOR: #66cc66">,</SPAN> group_id INTEGER<SPAN style="COLOR: #66cc66">,</SPAN> member_type INTEGER<SPAN style="COLOR: #66cc66">,</SPAN> member_id INTEGER<SPAN style="COLOR: #66cc66">,</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">UNIQUE</SPAN><SPAN style="COLOR: #66cc66">(</SPAN>group_id<SPAN style="COLOR: #66cc66">,</SPAN> member_type<SPAN style="COLOR: #66cc66">,</SPAN> member_id<SPAN style="COLOR: #66cc66">)</SPAN><SPAN style="COLOR: #66cc66">)</SPAN>;  
<SPAN style="FONT-WEIGHT: bold; COLOR: #993333">CREATE</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">TABLE</SPAN> ABMultiValue <SPAN style="COLOR: #66cc66">(</SPAN>UID INTEGER <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">PRIMARY</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">KEY</SPAN><SPAN style="COLOR: #66cc66">,</SPAN> record_id INTEGER<SPAN style="COLOR: #66cc66">,</SPAN> property INTEGER<SPAN style="COLOR: #66cc66">,</SPAN> identifier INTEGER<SPAN style="COLOR: #66cc66">,</SPAN> label INTEGER<SPAN style="COLOR: #66cc66">,</SPAN> value TEXT<SPAN style="COLOR: #66cc66">)</SPAN>;  
<SPAN style="FONT-WEIGHT: bold; COLOR: #993333">CREATE</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">TABLE</SPAN> ABMultiValueEntry <SPAN style="COLOR: #66cc66">(</SPAN>parent_id INTEGER<SPAN style="COLOR: #66cc66">,</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">KEY</SPAN> INTEGER<SPAN style="COLOR: #66cc66">,</SPAN> value TEXT<SPAN style="COLOR: #66cc66">,</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">UNIQUE</SPAN><SPAN style="COLOR: #66cc66">(</SPAN>parent_id<SPAN style="COLOR: #66cc66">,</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">KEY</SPAN><SPAN style="COLOR: #66cc66">)</SPAN><SPAN style="COLOR: #66cc66">)</SPAN>;  
<SPAN style="FONT-WEIGHT: bold; COLOR: #993333">CREATE</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">TABLE</SPAN> ABMultiValueEntryKey <SPAN style="COLOR: #66cc66">(</SPAN>value TEXT<SPAN style="COLOR: #66cc66">,</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">UNIQUE</SPAN><SPAN style="COLOR: #66cc66">(</SPAN>value<SPAN style="COLOR: #66cc66">)</SPAN><SPAN style="COLOR: #66cc66">)</SPAN>;  
<SPAN style="FONT-WEIGHT: bold; COLOR: #993333">CREATE</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">TABLE</SPAN> ABMultiValueLabel <SPAN style="COLOR: #66cc66">(</SPAN>value TEXT<SPAN style="COLOR: #66cc66">,</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">UNIQUE</SPAN><SPAN style="COLOR: #66cc66">(</SPAN>value<SPAN style="COLOR: #66cc66">)</SPAN><SPAN style="COLOR: #66cc66">)</SPAN>;  
<SPAN style="FONT-WEIGHT: bold; COLOR: #993333">CREATE</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">TABLE</SPAN> ABPerson <SPAN style="COLOR: #66cc66">(</SPAN>ROWID INTEGER <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">PRIMARY</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">KEY</SPAN> AUTOINCREMENT<SPAN style="COLOR: #66cc66">,</SPAN> First TEXT<SPAN style="COLOR: #66cc66">,</SPAN> Last TEXT<SPAN style="COLOR: #66cc66">,</SPAN> Middle TEXT<SPAN style="COLOR: #66cc66">,</SPAN> FirstPhonetic TEXT<SPAN style="COLOR: #66cc66">,</SPAN> MiddlePhonetic TEXT<SPAN style="COLOR: #66cc66">,</SPAN> LastPhonetic TEXT<SPAN style="COLOR: #66cc66">,</SPAN> Organization TEXT<SPAN style="COLOR: #66cc66">,</SPAN> Department TEXT<SPAN style="COLOR: #66cc66">,</SPAN> Note TEXT<SPAN style="COLOR: #66cc66">,</SPAN> Kind INTEGER<SPAN style="COLOR: #66cc66">,</SPAN> Birthday TEXT<SPAN style="COLOR: #66cc66">,</SPAN> JobTitle TEXT<SPAN style="COLOR: #66cc66">,</SPAN> Nickname TEXT<SPAN style="COLOR: #66cc66">,</SPAN> Prefix TEXT<SPAN style="COLOR: #66cc66">,</SPAN> Suffix TEXT<SPAN style="COLOR: #66cc66">,</SPAN> FirstSort TEXT<SPAN style="COLOR: #66cc66">,</SPAN> LastSort TEXT<SPAN style="COLOR: #66cc66">,</SPAN> CreationDate INTEGER<SPAN style="COLOR: #66cc66">,</SPAN> ModificationDate INTEGER<SPAN style="COLOR: #66cc66">,</SPAN> CompositeNameFallback TEXT<SPAN style="COLOR: #66cc66">)</SPAN>;  
<SPAN style="FONT-WEIGHT: bold; COLOR: #993333">CREATE</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">TABLE</SPAN> ABPersonChanges <SPAN style="COLOR: #66cc66">(</SPAN>record INTEGER<SPAN style="COLOR: #66cc66">,</SPAN> type INTEGER<SPAN style="COLOR: #66cc66">)</SPAN>;  
<SPAN style="FONT-WEIGHT: bold; COLOR: #993333">CREATE</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">TABLE</SPAN> ABPersonMultiValueDeletes <SPAN style="COLOR: #66cc66">(</SPAN>record_id INTEGER<SPAN style="COLOR: #66cc66">,</SPAN> property_id INTEGER<SPAN style="COLOR: #66cc66">,</SPAN> identifier INTEGER<SPAN style="COLOR: #66cc66">)</SPAN>;  
<SPAN style="FONT-WEIGHT: bold; COLOR: #993333">CREATE</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">TABLE</SPAN> ABPhoneLastFour <SPAN style="COLOR: #66cc66">(</SPAN>multivalue_id INTEGER <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">PRIMARY</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">KEY</SPAN><SPAN style="COLOR: #66cc66">,</SPAN> value TEXT<SPAN style="COLOR: #66cc66">)</SPAN>;  
<SPAN style="FONT-WEIGHT: bold; COLOR: #993333">CREATE</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">TABLE</SPAN> ABRecent<SPAN style="COLOR: #66cc66">(</SPAN>date INTEGER<SPAN style="COLOR: #66cc66">,</SPAN> name<SPAN style="COLOR: #66cc66">,</SPAN> property INTEGER<SPAN style="COLOR: #66cc66">,</SPAN> value<SPAN style="COLOR: #66cc66">)</SPAN>;  
<SPAN style="FONT-WEIGHT: bold; COLOR: #993333">CREATE</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">TABLE</SPAN> sorting_first_section_list<SPAN style="COLOR: #66cc66">(</SPAN>character<SPAN style="COLOR: #66cc66">,</SPAN> number<SPAN style="COLOR: #66cc66">,</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">UNIQUE</SPAN><SPAN style="COLOR: #66cc66">(</SPAN>character<SPAN style="COLOR: #66cc66">)</SPAN><SPAN style="COLOR: #66cc66">)</SPAN>;  
<SPAN style="FONT-WEIGHT: bold; COLOR: #993333">CREATE</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">TABLE</SPAN> sorting_last_section_list<SPAN style="COLOR: #66cc66">(</SPAN>character<SPAN style="COLOR: #66cc66">,</SPAN> number<SPAN style="COLOR: #66cc66">,</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">UNIQUE</SPAN><SPAN style="COLOR: #66cc66">(</SPAN>character<SPAN style="COLOR: #66cc66">)</SPAN><SPAN style="COLOR: #66cc66">)</SPAN>;  
<SPAN style="FONT-WEIGHT: bold; COLOR: #993333">CREATE</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">TABLE</SPAN> sqlite_sequence<SPAN style="COLOR: #66cc66">(</SPAN>name TEXT<SPAN style="COLOR: #66cc66">,</SPAN> seq INTEGER<SPAN style="COLOR: #66cc66">)</SPAN>; 

CREATE TABLE ABGroup (ROWID INTEGER PRIMARY KEY AUTOINCREMENT, Name TEXT);
CREATE TABLE ABGroupChanges (record INTEGER, type INTEGER);
CREATE TABLE ABGroupMembers (UID INTEGER PRIMARY KEY, group_id INTEGER, member_type INTEGER, member_id INTEGER, UNIQUE(group_id, member_type, member_id));
CREATE TABLE ABMultiValue (UID INTEGER PRIMARY KEY, record_id INTEGER, property INTEGER, identifier INTEGER, label INTEGER, value TEXT);
CREATE TABLE ABMultiValueEntry (parent_id INTEGER, KEY INTEGER, value TEXT, UNIQUE(parent_id, KEY));
CREATE TABLE ABMultiValueEntryKey (value TEXT, UNIQUE(value));
CREATE TABLE ABMultiValueLabel (value TEXT, UNIQUE(value));
CREATE TABLE ABPerson (ROWID INTEGER PRIMARY KEY AUTOINCREMENT, First TEXT, Last TEXT, Middle TEXT, FirstPhonetic TEXT, MiddlePhonetic TEXT, LastPhonetic TEXT, Organization TEXT, Department TEXT, Note TEXT, Kind INTEGER, Birthday TEXT, JobTitle TEXT, Nickname TEXT, Prefix TEXT, Suffix TEXT, FirstSort TEXT, LastSort TEXT, CreationDate INTEGER, ModificationDate INTEGER, CompositeNameFallback TEXT);
CREATE TABLE ABPersonChanges (record INTEGER, type INTEGER);
CREATE TABLE ABPersonMultiValueDeletes (record_id INTEGER, property_id INTEGER, identifier INTEGER);
CREATE TABLE ABPhoneLastFour (multivalue_id INTEGER PRIMARY KEY, value TEXT);
CREATE TABLE ABRecent(date INTEGER, name, property INTEGER, value);
CREATE TABLE sorting_first_section_list(character, number, UNIQUE(character));
CREATE TABLE sorting_last_section_list(character, number, UNIQUE(character));
CREATE TABLE sqlite_sequence(name TEXT, seq INTEGER);— ==========下面是创建索引==========

view plaincopy to clipboardprint?
<SPAN style="FONT-WEIGHT: bold; COLOR: #993333">CREATE</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">INDEX</SPAN> ABMultiValueRecordIDIndex <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">ON</SPAN> ABMultiValue<SPAN style="COLOR: #66cc66">(</SPAN>record_id<SPAN style="COLOR: #66cc66">)</SPAN>;  
<SPAN style="FONT-WEIGHT: bold; COLOR: #993333">CREATE</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">INDEX</SPAN> ABMultiValueLabelIndex <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">ON</SPAN> ABMultiValue<SPAN style="COLOR: #66cc66">(</SPAN>label<SPAN style="COLOR: #66cc66">)</SPAN>;  
<SPAN style="FONT-WEIGHT: bold; COLOR: #993333">CREATE</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">INDEX</SPAN> ABMultiValueEntryKeyIndex <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">ON</SPAN> ABMultiValueEntry<SPAN style="COLOR: #66cc66">(</SPAN><SPAN style="FONT-WEIGHT: bold; COLOR: #993333">KEY</SPAN><SPAN style="COLOR: #66cc66">)</SPAN>;  
<SPAN style="FONT-WEIGHT: bold; COLOR: #993333">CREATE</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">INDEX</SPAN> ABFirstSortIndex <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">ON</SPAN> ABPerson<SPAN style="COLOR: #66cc66">(</SPAN>FirstSort<SPAN style="COLOR: #66cc66">)</SPAN>;  
<SPAN style="FONT-WEIGHT: bold; COLOR: #993333">CREATE</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">INDEX</SPAN> ABLastSortIndex <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">ON</SPAN> ABPerson<SPAN style="COLOR: #66cc66">(</SPAN>LastSort<SPAN style="COLOR: #66cc66">)</SPAN>;  
<SPAN style="FONT-WEIGHT: bold; COLOR: #993333">CREATE</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">INDEX</SPAN> ABPhoneLastFourIndex <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">ON</SPAN> ABPhoneLastFour<SPAN style="COLOR: #66cc66">(</SPAN>value<SPAN style="COLOR: #66cc66">)</SPAN>;  
<SPAN style="FONT-WEIGHT: bold; COLOR: #993333">CREATE</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">INDEX</SPAN> ABRecent_value_index <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">ON</SPAN> ABRecent<SPAN style="COLOR: #66cc66">(</SPAN>property<SPAN style="COLOR: #66cc66">,</SPAN> value<SPAN style="COLOR: #66cc66">)</SPAN>;  
<SPAN style="FONT-WEIGHT: bold; COLOR: #993333">CREATE</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">INDEX</SPAN> ABRecent_date_index <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">ON</SPAN> ABRecent<SPAN style="COLOR: #66cc66">(</SPAN>property<SPAN style="COLOR: #66cc66">,</SPAN> date<SPAN style="COLOR: #66cc66">)</SPAN>; 

CREATE INDEX ABMultiValueRecordIDIndex ON ABMultiValue(record_id);
CREATE INDEX ABMultiValueLabelIndex ON ABMultiValue(label);
CREATE INDEX ABMultiValueEntryKeyIndex ON ABMultiValueEntry(KEY);
CREATE INDEX ABFirstSortIndex ON ABPerson(FirstSort);
CREATE INDEX ABLastSortIndex ON ABPerson(LastSort);
CREATE INDEX ABPhoneLastFourIndex ON ABPhoneLastFour(value);
CREATE INDEX ABRecent_value_index ON ABRecent(property, value);
CREATE INDEX ABRecent_date_index ON ABRecent(property, date);— ==========下面是创建触发器==========

view plaincopy to clipboardprint?
<SPAN style="FONT-WEIGHT: bold; COLOR: #993333">CREATE</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">TRIGGER</SPAN> delete_phone_last_four AFTER <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">DELETE</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">ON</SPAN> ABMultiValue  
BEGIN 
<SPAN style="FONT-WEIGHT: bold; COLOR: #993333">DELETE</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">FROM</SPAN> ABPhoneLastFour <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">WHERE</SPAN> multivalue_id <SPAN style="COLOR: #66cc66">=</SPAN> OLD<SPAN style="COLOR: #66cc66">.</SPAN>UID;  
END;  
   
<SPAN style="FONT-WEIGHT: bold; COLOR: #993333">CREATE</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">TRIGGER</SPAN> sorting_first_prefix_trigger AFTER <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">INSERT</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">ON</SPAN> ABPerson  
BEGIN 
<SPAN style="FONT-WEIGHT: bold; COLOR: #993333">INSERT</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">OR</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">REPLACE</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">INTO</SPAN> sorting_first_section_list <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">VALUES</SPAN><SPAN style="COLOR: #66cc66">(</SPAN>substr<SPAN style="COLOR: #66cc66">(</SPAN>IFNULL<SPAN style="COLOR: #66cc66">(</SPAN>NEW<SPAN style="COLOR: #66cc66">.</SPAN>FirstSort<SPAN style="COLOR: #66cc66">,</SPAN> ‘~’<SPAN style="COLOR: #66cc66">)</SPAN><SPAN style="COLOR: #66cc66">,</SPAN> <SPAN style="COLOR: #cc66cc">1</SPAN><SPAN style="COLOR: #66cc66">,</SPAN> <SPAN style="COLOR: #cc66cc">1</SPAN><SPAN style="COLOR: #66cc66">)</SPAN><SPAN style="COLOR: #66cc66">,</SPAN> <SPAN style="COLOR: #cc66cc">1</SPAN> <SPAN style="COLOR: #66cc66">+</SPAN> IFNULL<SPAN style="COLOR: #66cc66">(</SPAN><SPAN style="COLOR: #66cc66">(</SPAN><SPAN style="FONT-WEIGHT: bold; COLOR: #993333">SELECT</SPAN> number <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">FROM</SPAN> sorting_first_section_list <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">WHERE</SPAN> character <SPAN style="COLOR: #66cc66">=</SPAN> substr<SPAN style="COLOR: #66cc66">(</SPAN>IFNULL<SPAN style="COLOR: #66cc66">(</SPAN>NEW<SPAN style="COLOR: #66cc66">.</SPAN>FirstSort<SPAN style="COLOR: #66cc66">,</SPAN> ‘~’<SPAN style="COLOR: #66cc66">)</SPAN><SPAN style="COLOR: #66cc66">,</SPAN> <SPAN style="COLOR: #cc66cc">1</SPAN><SPAN style="COLOR: #66cc66">,</SPAN> <SPAN style="COLOR: #cc66cc">1</SPAN><SPAN style="COLOR: #66cc66">)</SPAN><SPAN style="COLOR: #66cc66">)</SPAN><SPAN style="COLOR: #66cc66">,</SPAN> <SPAN style="COLOR: #cc66cc">0</SPAN><SPAN style="COLOR: #66cc66">)</SPAN><SPAN style="COLOR: #66cc66">)</SPAN>;  
END;  
   
<SPAN style="FONT-WEIGHT: bold; COLOR: #993333">CREATE</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">TRIGGER</SPAN> update_first_prefix_trigger AFTER <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">UPDATE</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">ON</SPAN> ABPerson  
BEGIN 
<SPAN style="FONT-WEIGHT: bold; COLOR: #993333">INSERT</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">OR</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">REPLACE</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">INTO</SPAN> sorting_first_section_list <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">VALUES</SPAN><SPAN style="COLOR: #66cc66">(</SPAN>substr<SPAN style="COLOR: #66cc66">(</SPAN>IFNULL<SPAN style="COLOR: #66cc66">(</SPAN>OLD<SPAN style="COLOR: #66cc66">.</SPAN>FirstSort<SPAN style="COLOR: #66cc66">,</SPAN> ‘~’<SPAN style="COLOR: #66cc66">)</SPAN><SPAN style="COLOR: #66cc66">,</SPAN> <SPAN style="COLOR: #cc66cc">1</SPAN><SPAN style="COLOR: #66cc66">,</SPAN> <SPAN style="COLOR: #cc66cc">1</SPAN><SPAN style="COLOR: #66cc66">)</SPAN><SPAN style="COLOR: #66cc66">,</SPAN> <SPAN style="COLOR: #66cc66">(</SPAN><SPAN style="FONT-WEIGHT: bold; COLOR: #993333">SELECT</SPAN> number <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">FROM</SPAN> sorting_first_section_list <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">WHERE</SPAN> character <SPAN style="COLOR: #66cc66">=</SPAN> substr<SPAN style="COLOR: #66cc66">(</SPAN>IFNULL<SPAN style="COLOR: #66cc66">(</SPAN>OLD<SPAN style="COLOR: #66cc66">.</SPAN>FirstSort<SPAN style="COLOR: #66cc66">,</SPAN> ‘~’<SPAN style="COLOR: #66cc66">)</SPAN><SPAN style="COLOR: #66cc66">,</SPAN> <SPAN style="COLOR: #cc66cc">1</SPAN><SPAN style="COLOR: #66cc66">,</SPAN> <SPAN style="COLOR: #cc66cc">1</SPAN><SPAN style="COLOR: #66cc66">)</SPAN><SPAN style="COLOR: #66cc66">)</SPAN> <SPAN style="COLOR: #66cc66">-</SPAN> <SPAN style="COLOR: #cc66cc">1</SPAN><SPAN style="COLOR: #66cc66">)</SPAN>;  
<SPAN style="FONT-WEIGHT: bold; COLOR: #993333">INSERT</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">OR</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">REPLACE</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">INTO</SPAN> sorting_first_section_list <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">VALUES</SPAN><SPAN style="COLOR: #66cc66">(</SPAN>substr<SPAN style="COLOR: #66cc66">(</SPAN>IFNULL<SPAN style="COLOR: #66cc66">(</SPAN>NEW<SPAN style="COLOR: #66cc66">.</SPAN>FirstSort<SPAN style="COLOR: #66cc66">,</SPAN> ‘~’<SPAN style="COLOR: #66cc66">)</SPAN><SPAN style="COLOR: #66cc66">,</SPAN> <SPAN style="COLOR: #cc66cc">1</SPAN><SPAN style="COLOR: #66cc66">,</SPAN> <SPAN style="COLOR: #cc66cc">1</SPAN><SPAN style="COLOR: #66cc66">)</SPAN><SPAN style="COLOR: #66cc66">,</SPAN> <SPAN style="COLOR: #cc66cc">1</SPAN> <SPAN style="COLOR: #66cc66">+</SPAN> IFNULL<SPAN style="COLOR: #66cc66">(</SPAN><SPAN style="COLOR: #66cc66">(</SPAN><SPAN style="FONT-WEIGHT: bold; COLOR: #993333">SELECT</SPAN> number <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">FROM</SPAN> sorting_first_section_list <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">WHERE</SPAN> character <SPAN style="COLOR: #66cc66">=</SPAN> substr<SPAN style="COLOR: #66cc66">(</SPAN>IFNULL<SPAN style="COLOR: #66cc66">(</SPAN>NEW<SPAN style="COLOR: #66cc66">.</SPAN>FirstSort<SPAN style="COLOR: #66cc66">,</SPAN> ‘~’<SPAN style="COLOR: #66cc66">)</SPAN><SPAN style="COLOR: #66cc66">,</SPAN> <SPAN style="COLOR: #cc66cc">1</SPAN><SPAN style="COLOR: #66cc66">,</SPAN> <SPAN style="COLOR: #cc66cc">1</SPAN><SPAN style="COLOR: #66cc66">)</SPAN><SPAN style="COLOR: #66cc66">)</SPAN><SPAN style="COLOR: #66cc66">,</SPAN> <SPAN style="COLOR: #cc66cc">0</SPAN><SPAN style="COLOR: #66cc66">)</SPAN><SPAN style="COLOR: #66cc66">)</SPAN>;  
END;  
   
<SPAN style="FONT-WEIGHT: bold; COLOR: #993333">CREATE</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">TRIGGER</SPAN> delete_first_prefix_trigger AFTER <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">DELETE</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">ON</SPAN> ABPerson  
BEGIN 
<SPAN style="FONT-WEIGHT: bold; COLOR: #993333">INSERT</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">OR</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">REPLACE</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">INTO</SPAN> sorting_first_section_list <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">VALUES</SPAN><SPAN style="COLOR: #66cc66">(</SPAN>substr<SPAN style="COLOR: #66cc66">(</SPAN>IFNULL<SPAN style="COLOR: #66cc66">(</SPAN>OLD<SPAN style="COLOR: #66cc66">.</SPAN>FirstSort<SPAN style="COLOR: #66cc66">,</SPAN> ‘~’<SPAN style="COLOR: #66cc66">)</SPAN><SPAN style="COLOR: #66cc66">,</SPAN> <SPAN style="COLOR: #cc66cc">1</SPAN><SPAN style="COLOR: #66cc66">,</SPAN> <SPAN style="COLOR: #cc66cc">1</SPAN><SPAN style="COLOR: #66cc66">)</SPAN><SPAN style="COLOR: #66cc66">,</SPAN> <SPAN style="COLOR: #66cc66">(</SPAN><SPAN style="FONT-WEIGHT: bold; COLOR: #993333">SELECT</SPAN> number <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">FROM</SPAN> sorting_first_section_list <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">WHERE</SPAN> character <SPAN style="COLOR: #66cc66">=</SPAN> substr<SPAN style="COLOR: #66cc66">(</SPAN>IFNULL<SPAN style="COLOR: #66cc66">(</SPAN>OLD<SPAN style="COLOR: #66cc66">.</SPAN>FirstSort<SPAN style="COLOR: #66cc66">,</SPAN> ‘~’<SPAN style="COLOR: #66cc66">)</SPAN><SPAN style="COLOR: #66cc66">,</SPAN> <SPAN style="COLOR: #cc66cc">1</SPAN><SPAN style="COLOR: #66cc66">,</SPAN> <SPAN style="COLOR: #cc66cc">1</SPAN><SPAN style="COLOR: #66cc66">)</SPAN><SPAN style="COLOR: #66cc66">)</SPAN> <SPAN style="COLOR: #66cc66">-</SPAN> <SPAN style="COLOR: #cc66cc">1</SPAN><SPAN style="COLOR: #66cc66">)</SPAN>;  
END;  
   
<SPAN style="FONT-WEIGHT: bold; COLOR: #993333">CREATE</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">TRIGGER</SPAN> sorting_last_prefix_trigger AFTER <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">INSERT</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">ON</SPAN> ABPerson  
BEGIN 
<SPAN style="FONT-WEIGHT: bold; COLOR: #993333">INSERT</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">OR</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">REPLACE</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">INTO</SPAN> sorting_last_section_list <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">VALUES</SPAN><SPAN style="COLOR: #66cc66">(</SPAN>substr<SPAN style="COLOR: #66cc66">(</SPAN>IFNULL<SPAN style="COLOR: #66cc66">(</SPAN>NEW<SPAN style="COLOR: #66cc66">.</SPAN>LastSort<SPAN style="COLOR: #66cc66">,</SPAN> ‘~’<SPAN style="COLOR: #66cc66">)</SPAN><SPAN style="COLOR: #66cc66">,</SPAN> <SPAN style="COLOR: #cc66cc">1</SPAN><SPAN style="COLOR: #66cc66">,</SPAN> <SPAN style="COLOR: #cc66cc">1</SPAN><SPAN style="COLOR: #66cc66">)</SPAN><SPAN style="COLOR: #66cc66">,</SPAN> <SPAN style="COLOR: #cc66cc">1</SPAN> <SPAN style="COLOR: #66cc66">+</SPAN> IFNULL<SPAN style="COLOR: #66cc66">(</SPAN><SPAN style="COLOR: #66cc66">(</SPAN><SPAN style="FONT-WEIGHT: bold; COLOR: #993333">SELECT</SPAN> number <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">FROM</SPAN> sorting_last_section_list <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">WHERE</SPAN> character <SPAN style="COLOR: #66cc66">=</SPAN> substr<SPAN style="COLOR: #66cc66">(</SPAN>IFNULL<SPAN style="COLOR: #66cc66">(</SPAN>NEW<SPAN style="COLOR: #66cc66">.</SPAN>LastSort<SPAN style="COLOR: #66cc66">,</SPAN> ‘~’<SPAN style="COLOR: #66cc66">)</SPAN><SPAN style="COLOR: #66cc66">,</SPAN> <SPAN style="COLOR: #cc66cc">1</SPAN><SPAN style="COLOR: #66cc66">,</SPAN> <SPAN style="COLOR: #cc66cc">1</SPAN><SPAN style="COLOR: #66cc66">)</SPAN><SPAN style="COLOR: #66cc66">)</SPAN><SPAN style="COLOR: #66cc66">,</SPAN> <SPAN style="COLOR: #cc66cc">0</SPAN><SPAN style="COLOR: #66cc66">)</SPAN><SPAN style="COLOR: #66cc66">)</SPAN>;  
END;  
   
<SPAN style="FONT-WEIGHT: bold; COLOR: #993333">CREATE</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">TRIGGER</SPAN> update_last_prefix_trigger AFTER <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">UPDATE</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">ON</SPAN> ABPerson  
BEGIN 
<SPAN style="FONT-WEIGHT: bold; COLOR: #993333">INSERT</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">OR</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">REPLACE</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">INTO</SPAN> sorting_last_section_list <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">VALUES</SPAN><SPAN style="COLOR: #66cc66">(</SPAN>substr<SPAN style="COLOR: #66cc66">(</SPAN>IFNULL<SPAN style="COLOR: #66cc66">(</SPAN>OLD<SPAN style="COLOR: #66cc66">.</SPAN>LastSort<SPAN style="COLOR: #66cc66">,</SPAN> ‘~’<SPAN style="COLOR: #66cc66">)</SPAN><SPAN style="COLOR: #66cc66">,</SPAN> <SPAN style="COLOR: #cc66cc">1</SPAN><SPAN style="COLOR: #66cc66">,</SPAN> <SPAN style="COLOR: #cc66cc">1</SPAN><SPAN style="COLOR: #66cc66">)</SPAN><SPAN style="COLOR: #66cc66">,</SPAN> <SPAN style="COLOR: #66cc66">(</SPAN><SPAN style="FONT-WEIGHT: bold; COLOR: #993333">SELECT</SPAN> number <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">FROM</SPAN> sorting_last_section_list <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">WHERE</SPAN> character <SPAN style="COLOR: #66cc66">=</SPAN> substr<SPAN style="COLOR: #66cc66">(</SPAN>IFNULL<SPAN style="COLOR: #66cc66">(</SPAN>OLD<SPAN style="COLOR: #66cc66">.</SPAN>LastSort<SPAN style="COLOR: #66cc66">,</SPAN> ‘~’<SPAN style="COLOR: #66cc66">)</SPAN><SPAN style="COLOR: #66cc66">,</SPAN> <SPAN style="COLOR: #cc66cc">1</SPAN><SPAN style="COLOR: #66cc66">,</SPAN> <SPAN style="COLOR: #cc66cc">1</SPAN><SPAN style="COLOR: #66cc66">)</SPAN><SPAN style="COLOR: #66cc66">)</SPAN> <SPAN style="COLOR: #66cc66">-</SPAN> <SPAN style="COLOR: #cc66cc">1</SPAN><SPAN style="COLOR: #66cc66">)</SPAN>;  
<SPAN style="FONT-WEIGHT: bold; COLOR: #993333">INSERT</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">OR</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">REPLACE</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">INTO</SPAN> sorting_last_section_list <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">VALUES</SPAN><SPAN style="COLOR: #66cc66">(</SPAN>substr<SPAN style="COLOR: #66cc66">(</SPAN>IFNULL<SPAN style="COLOR: #66cc66">(</SPAN>NEW<SPAN style="COLOR: #66cc66">.</SPAN>LastSort<SPAN style="COLOR: #66cc66">,</SPAN> ‘~’<SPAN style="COLOR: #66cc66">)</SPAN><SPAN style="COLOR: #66cc66">,</SPAN> <SPAN style="COLOR: #cc66cc">1</SPAN><SPAN style="COLOR: #66cc66">,</SPAN> <SPAN style="COLOR: #cc66cc">1</SPAN><SPAN style="COLOR: #66cc66">)</SPAN><SPAN style="COLOR: #66cc66">,</SPAN> <SPAN style="COLOR: #cc66cc">1</SPAN> <SPAN style="COLOR: #66cc66">+</SPAN> IFNULL<SPAN style="COLOR: #66cc66">(</SPAN><SPAN style="COLOR: #66cc66">(</SPAN><SPAN style="FONT-WEIGHT: bold; COLOR: #993333">SELECT</SPAN> number <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">FROM</SPAN> sorting_last_section_list <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">WHERE</SPAN> character <SPAN style="COLOR: #66cc66">=</SPAN> substr<SPAN style="COLOR: #66cc66">(</SPAN>IFNULL<SPAN style="COLOR: #66cc66">(</SPAN>NEW<SPAN style="COLOR: #66cc66">.</SPAN>LastSort<SPAN style="COLOR: #66cc66">,</SPAN> ‘~’<SPAN style="COLOR: #66cc66">)</SPAN><SPAN style="COLOR: #66cc66">,</SPAN> <SPAN style="COLOR: #cc66cc">1</SPAN><SPAN style="COLOR: #66cc66">,</SPAN> <SPAN style="COLOR: #cc66cc">1</SPAN><SPAN style="COLOR: #66cc66">)</SPAN><SPAN style="COLOR: #66cc66">)</SPAN><SPAN style="COLOR: #66cc66">,</SPAN> <SPAN style="COLOR: #cc66cc">0</SPAN><SPAN style="COLOR: #66cc66">)</SPAN><SPAN style="COLOR: #66cc66">)</SPAN>;  
END;  
   
<SPAN style="FONT-WEIGHT: bold; COLOR: #993333">CREATE</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">TRIGGER</SPAN> delete_last_prefix_trigger AFTER <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">DELETE</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">ON</SPAN> ABPerson  
BEGIN 
<SPAN style="FONT-WEIGHT: bold; COLOR: #993333">INSERT</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">OR</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">REPLACE</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">INTO</SPAN> sorting_last_section_list <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">VALUES</SPAN><SPAN style="COLOR: #66cc66">(</SPAN>substr<SPAN style="COLOR: #66cc66">(</SPAN>IFNULL<SPAN style="COLOR: #66cc66">(</SPAN>Old<SPAN style="COLOR: #66cc66">.</SPAN>LastSort<SPAN style="COLOR: #66cc66">,</SPAN> ‘~’<SPAN style="COLOR: #66cc66">)</SPAN><SPAN style="COLOR: #66cc66">,</SPAN> <SPAN style="COLOR: #cc66cc">1</SPAN><SPAN style="COLOR: #66cc66">,</SPAN> <SPAN style="COLOR: #cc66cc">1</SPAN><SPAN style="COLOR: #66cc66">)</SPAN><SPAN style="COLOR: #66cc66">,</SPAN> <SPAN style="COLOR: #66cc66">(</SPAN><SPAN style="FONT-WEIGHT: bold; COLOR: #993333">SELECT</SPAN> number <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">FROM</SPAN> sorting_last_section_list <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">WHERE</SPAN> character <SPAN style="COLOR: #66cc66">=</SPAN> substr<SPAN style="COLOR: #66cc66">(</SPAN>IFNULL<SPAN style="COLOR: #66cc66">(</SPAN>Old<SPAN style="COLOR: #66cc66">.</SPAN>LastSort<SPAN style="COLOR: #66cc66">,</SPAN> ‘~’<SPAN style="COLOR: #66cc66">)</SPAN><SPAN style="COLOR: #66cc66">,</SPAN> <SPAN style="COLOR: #cc66cc">1</SPAN><SPAN style="COLOR: #66cc66">,</SPAN> <SPAN style="COLOR: #cc66cc">1</SPAN><SPAN style="COLOR: #66cc66">)</SPAN><SPAN style="COLOR: #66cc66">)</SPAN> <SPAN style="COLOR: #66cc66">-</SPAN> <SPAN style="COLOR: #cc66cc">1</SPAN><SPAN style="COLOR: #66cc66">)</SPAN>;  
END; 

CREATE TRIGGER delete_phone_last_four AFTER DELETE ON ABMultiValue
BEGIN
DELETE FROM ABPhoneLastFour WHERE multivalue_id = OLD.UID;
END;
 
CREATE TRIGGER sorting_first_prefix_trigger AFTER INSERT ON ABPerson
BEGIN
INSERT OR REPLACE INTO sorting_first_section_list VALUES(substr(IFNULL(NEW.FirstSort, ‘~’), 1, 1), 1 + IFNULL((SELECT number FROM sorting_first_section_list WHERE character = substr(IFNULL(NEW.FirstSort, ‘~’), 1, 1)), 0));
END;
 
CREATE TRIGGER update_first_prefix_trigger AFTER UPDATE ON ABPerson
BEGIN
INSERT OR REPLACE INTO sorting_first_section_list VALUES(substr(IFNULL(OLD.FirstSort, ‘~’), 1, 1), (SELECT number FROM sorting_first_section_list WHERE character = substr(IFNULL(OLD.FirstSort, ‘~’), 1, 1)) - 1);
INSERT OR REPLACE INTO sorting_first_section_list VALUES(substr(IFNULL(NEW.FirstSort, ‘~’), 1, 1), 1 + IFNULL((SELECT number FROM sorting_first_section_list WHERE character = substr(IFNULL(NEW.FirstSort, ‘~’), 1, 1)), 0));
END;
 
CREATE TRIGGER delete_first_prefix_trigger AFTER DELETE ON ABPerson
BEGIN
INSERT OR REPLACE INTO sorting_first_section_list VALUES(substr(IFNULL(OLD.FirstSort, ‘~’), 1, 1), (SELECT number FROM sorting_first_section_list WHERE character = substr(IFNULL(OLD.FirstSort, ‘~’), 1, 1)) - 1);
END;
 
CREATE TRIGGER sorting_last_prefix_trigger AFTER INSERT ON ABPerson
BEGIN
INSERT OR REPLACE INTO sorting_last_section_list VALUES(substr(IFNULL(NEW.LastSort, ‘~’), 1, 1), 1 + IFNULL((SELECT number FROM sorting_last_section_list WHERE character = substr(IFNULL(NEW.LastSort, ‘~’), 1, 1)), 0));
END;
 
CREATE TRIGGER update_last_prefix_trigger AFTER UPDATE ON ABPerson
BEGIN
INSERT OR REPLACE INTO sorting_last_section_list VALUES(substr(IFNULL(OLD.LastSort, ‘~’), 1, 1), (SELECT number FROM sorting_last_section_list WHERE character = substr(IFNULL(OLD.LastSort, ‘~’), 1, 1)) - 1);
INSERT OR REPLACE INTO sorting_last_section_list VALUES(substr(IFNULL(NEW.LastSort, ‘~’), 1, 1), 1 + IFNULL((SELECT number FROM sorting_last_section_list WHERE character = substr(IFNULL(NEW.LastSort, ‘~’), 1, 1)), 0));
END;
 
CREATE TRIGGER delete_last_prefix_trigger AFTER DELETE ON ABPerson
BEGIN
INSERT OR REPLACE INTO sorting_last_section_list VALUES(substr(IFNULL(Old.LastSort, ‘~’), 1, 1), (SELECT number FROM sorting_last_section_list WHERE character = substr(IFNULL(Old.LastSort, ‘~’), 1, 1)) - 1);
END;二、notes.db 记事本数据库

location: /private/var/root/Library/Notes/notes.db

1.Note 摘要信息记录表
creation_date: 创建时间
title: 标题
summary: 摘要

2.note_bodies 详细信息
note_id: note ID
data: 记事内容,包含标题

– ==========下面是建表语句==========

view plaincopy to clipboardprint?
<SPAN style="FONT-WEIGHT: bold; COLOR: #993333">CREATE</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">TABLE</SPAN> Note <SPAN style="COLOR: #66cc66">(</SPAN>creation_date INTEGER<SPAN style="COLOR: #66cc66">,</SPAN> title TEXT<SPAN style="COLOR: #66cc66">,</SPAN> summary TEXT<SPAN style="COLOR: #66cc66">)</SPAN>;  
<SPAN style="FONT-WEIGHT: bold; COLOR: #993333">CREATE</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">TABLE</SPAN> note_bodies <SPAN style="COLOR: #66cc66">(</SPAN>note_id INTEGER<SPAN style="COLOR: #66cc66">,</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">DATA</SPAN><SPAN style="COLOR: #66cc66">,</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">UNIQUE</SPAN><SPAN style="COLOR: #66cc66">(</SPAN>note_id<SPAN style="COLOR: #66cc66">)</SPAN><SPAN style="COLOR: #66cc66">)</SPAN>; 

CREATE TABLE Note (creation_date INTEGER, title TEXT, summary TEXT);
CREATE TABLE note_bodies (note_id INTEGER, DATA, UNIQUE(note_id));– ==========下面是创建触发器==========

view plaincopy to clipboardprint?
<SPAN style="FONT-WEIGHT: bold; COLOR: #993333">CREATE</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">TRIGGER</SPAN> delete_note_bodies AFTER <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">DELETE</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">ON</SPAN> Note  
BEGIN 
<SPAN style="FONT-WEIGHT: bold; COLOR: #993333">DELETE</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">FROM</SPAN> note_bodies <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">WHERE</SPAN> note_id <SPAN style="COLOR: #66cc66">=</SPAN> OLD<SPAN style="COLOR: #66cc66">.</SPAN>ROWID;  
END; 

CREATE TRIGGER delete_note_bodies AFTER DELETE ON Note
BEGIN
DELETE FROM note_bodies WHERE note_id = OLD.ROWID;
END;三、sms.db 短信数据库

location: /private/var/root/Library/SMS/sms.db

1.message 短信表
ROWID: 自增PK
address: 对方手机号码(+86)
date: 时间
text: 内容
flags: 标记. 2.收到的;3.自己发送的
replace: (未知)
svc_center: (未知)

– ==========下面是建表语句==========

view plaincopy to clipboardprint?
<SPAN style="FONT-WEIGHT: bold; COLOR: #993333">CREATE</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">TABLE</SPAN> message <SPAN style="COLOR: #66cc66">(</SPAN>ROWID INTEGER <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">PRIMARY</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">KEY</SPAN> AUTOINCREMENT<SPAN style="COLOR: #66cc66">,</SPAN> address TEXT<SPAN style="COLOR: #66cc66">,</SPAN> date INTEGER<SPAN style="COLOR: #66cc66">,</SPAN> text TEXT<SPAN style="COLOR: #66cc66">,</SPAN> flags INTEGER<SPAN style="COLOR: #66cc66">,</SPAN> <SPAN style="FONT-WEIGHT: bold; COLOR: #993333">REPLACE</SPAN> INTEGER<SPAN style="COLOR: #66cc66">,</SPAN> svc_center TEXT<SPAN style="COLOR: #66cc66">)</SPAN>; 

CREATE TABLE message (ROWID INTEGER PRIMARY KEY AUTOINCREMENT, address TEXT, date INTEGER, text TEXT, flags INTEGER, REPLACE INTEGER, svc_center TEXT);CallData DB
/System/Library/Frameworks/AppSupport.framework/calldata.db

TABLE _SqliteDatabaseProperties
TABLE citycode
code (INTEGER)
Not sure what the significance of these entries are, I’m wondering if they have something to do with the geocoding of calls not made from your phonebook?
(3888)
city (TEXT)
Not sure what the significance of these entries are, I’m wondering if they have something to do with the geocoding of calls not made from your phonebook?
(RED CLOUD)
INDEX citycode_codeIndex
citycode (code)
TABLE npa
npa (TEXT)
Numbering Plan Area, aka Area Code
(415)
location (TEXT)
State/Province Assigned to the NPA
(CA)
country (TEXT)
Country Assigned to the NPA, may be null if “location” is specific enough
(USA)
TABLE npalocation
npa (TEXT)
Numbering Plan Area, aka Area Code
(415)
location (TEXT)
Descriptive location info
(San Francisco/North Bay Area)
TABLE npanxx
npa (INTEGER)
Numbering Plan Area, aka Area Code
(907)
nxx (INTEGER)
Unknown
(200)
rate_center (INTEGER)
Unknown
(1)
INDEX npanxx_npanxxIndex
npanxx (npa,nxx)
CallHistory DB
/private/var/root/Library/CallHistory/call_history.db

TABLE _SqliteDatabaseProperties
your values will certainly be different here…when you “restore” your iPhone from iTunes the counters all reset
key (TEXT) value (TEXT)
call_history_limit 100
timer_last 60
timer_outgoing 900
timer_incoming 540
timer_all 1440
timer_lifetime 1440
timer_last_reset
data_up_last 2.5439454125
data_down_last 20.86328125
data_up_all 719.9228515625
data_down_all 8677.8427734375
data_up_lifetime 719.9228515625
data_down_lifetime 8677.8427734375
data_last_reset
_ClientVersion 3
_UniqueIdentifier GUID
TABLE call
ROWID (INTEGER PRIMARY KEY AUTOINCREMENT)
Auto-incrementing field/counter
address (TEXT)
International-formatted foreign address
(18005551212)
date (INTEGER)
OSX-epoch based datetime, convertable via date -r
(1187200801)
duration (INTEGER)
Length of call in seconds rounded to next minute, 0 = missed call
(60)
flags (INTEGER)
Flags controlling the type of record
5 - Outgoing call
4 - Incoming call
id (INTEGER)
AddressBook ID for outgoing calls selected from AddressBook, otherwise -1
(67)
INDEX date_index
call (date)
KeyChain DB
/private/var/root/Library/Keychains/keychain-2.db
Encrypted, I don’t know how to parse this yet

Voicemail DB
/private/var/root/Library/Voicemail/voicemail.db

TABLE _SqliteDatabaseProperties
key (TEXT) value (TEXT)
VMVersion 4
_UniqueIdentifier GUID
token string containing various values, including your phone number
uid_validity 1183172695
mailboxusage 57
TABLE voicemail
ROWID (INTEGER PRIMARY KEY AUTOINCREMENT)
Auto-incrementing field/counter
remote_uid (INTEGER)
International-formatted foreign address
(18005551212)
date (INTEGER)
OSX-epoch based datetime, convertable via date -r
(1187200801)
token (TEXT)
Always reads “Complete” from what I can tell
sender (TEXT)
CallerID from the calling party leaving the voicemail message
(8885551212)
callback_num (TEXT)
Callback number left by calling party, usually caller ID
(8885551212)
duration (INTEGER)
Duration in seconds
(5)
expiration (INTEGER)
OSX-epoch based datetime, convertable via date -r
(1189431482)
trashed_date (INTEGER)
definitely based in seconds, haven’t figured out the epoch yet or why it isn’t the same as the other dates based on OSX’s epoch
flags (INTEGER)
Voicemail flags
0 - Not downloaded yet
1 - Partially downloaded
2 - New, unlistened or only partially listened to
3 - Listened completely
11 - Pending delete, in “Deleted Items”
15 - Deleted from iPhone, pending delete from voicemail hq
INDEX date_index
voicemail (date)
INDEX remote_uid_index
voicemail (remote_uid)
Other, more complicated DBs, involved in syncing
AddressBook DB
/private/var/root/Library/AddressBook/AddressBook.sqlitedb
AddressBook Images DB
/private/var/root/Library/AddressBook/AddressBookImages.sqlitedb
Maptiles DB
/private/var/root/Library/Caches/MapTiles/MapTiles.sqlitedb
Calendar DB
/private/var/root/Library/Calendar/Calendar.sqlitedb

 

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/dadalan/archive/2009/03/03/3951847.aspx

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
iPhone开发秘籍 The iPhone Developer's Cookbook Building Applications with the iPhone SDK 本电子书共295页 Amazon超级畅销书 大量未公开的绝技,带你深入iPhone开发秘境 任务驱动,丰富的实战代码,让你触类旁通 目录 第1章 iphone sdk简介. 1 1.1 苹果公司的iphone sdk 1 1.2 组建iphone项目 2 1.3 iphone应用程序组件 3 1.3.1 应用程序文件夹层次结构 3 1.3.2 可执行文件 3 1.3.3 info.plist文件 4 1.3.4 图标和默认图像 5 1.3.5 xib(nib)文件 5 1.3.6 应用程序束中不存在的文件 5 1.3.7 沙盒 6 1.4 平台限制 6 1.4.1 存储限制 6 1.4.2 数据访问限制 7 1.4.3 内存限制 7 1.4.4 交互限制 7 1.4.5 电量限制 7 1.4.6 应用程序限制 8 1.4.7 用户行为限制 8 1.5 sdk限制 8 .1.6 编程范型 9 1.6.1 面向对象编程 9 1.6.2 模型—视图—控制器 9 1.7 构建iphone应用程序主干 15 1.8 hello world应用程序 15 1.8.1 类 17 1.8.2 代码 18 1.8.3 关于示例代码和内存管理的 注意事项 18 1.9 构建hello world应用程序 19 1.9.1 创建iphone项目 19 1.9.2 运行主干 20 1.9.3 定制iphone项目 20 1.9.4 编辑标识信息 21 1.9.5 使用调试器 21 1.10 苹果公司的iphone开发人员计划 23 1.10.1 开发电话 23 1.10.2 应用程序标识符 23 1.11 从xcode到iphone:organizer界面 24 1.11.1 projects & sources列表 25 1.11.2 devices列表 25 1.11.3 summary选项卡 25 1.11.4 console选项卡 25 1.11.5 crash logs选项卡 25 1.11.6 screenshot选项卡 25 1.11.7 关于限制(tethering) 26 1.11.8 在iphone上测试应用程序 26 1.11.9 编译以分发 27 1.12 使用文档中未记录的api调用 28 1.13 ad hoc分发 28 1.14 小结 29 第2章 视图 30 2.1 uiview和uiwindow 30 2.1.1 层次结构 30 2.1.2 几何特征 31 2.1.3 手势 34 2.2 秘诀:添加递进式子视图 34 2.3 秘诀:拖动视图 36 2.3.1 uitouch 37 2.3.2 添加持久性 39 2.4 秘诀:剪辑视图 42 2.4.1 通过剪辑平衡触摸 43 2.4.2 访问逐个像素值 43 2.5 秘诀:检查多点触摸 45 2.6 uiview动画 48 2.7 秘诀:淡入和淡出视图 49 2.8 秘诀:交换视图 50 2.9 秘诀:翻转视图 52 2.10 秘诀:将catransition应用于层 54 2.10.1 文档中未记录的动画类型 54 2.10.2 通用core animation调用 56 2.11 秘诀:滑动视图 57 2.12 秘诀:转换视图 59 2.13 小结 61 第3章 视图控制器 63 3.1 视图管理 63 3.1.1 核心类 63 3.1.2 专用类 64 3.1.3 创建uiviewcontroller 64 3.2 使用interface builder为uiview-controller构建视图 66 3.2.1 温度转换器示例 66 3.2.2 直接加载xib文件 73 3.3 导航控制器 73 3.3.1 设置导航控制器 74 3.3.2 推入和弹出视图控制器 74 3.3.3 导航项类 75 3.4 秘诀:构建简单的双项菜单 75 3.5 秘诀:添加分段控件 77 3.6 秘诀:在导航栏中添加uitoolbar 79 3.7 秘诀:在视图控制器之间导航 81 3.7.1 返回根 83 3.7.2 加载视图控制器数组 83 3.8 选项卡栏 83 3.9 小结 86 第4章 警告用户 87 4.1 通过警告直接与用户对话 87 4.1.1 记录结果 88 4.1.2 构建警告 88 4.1.3 显示警告 89 4.2 秘诀:创建多行按钮显示 90 4.3 秘诀:自动计时的无按钮警告 91 4.4 秘诀:请求用户的文本输入 92 4.5 秘诀:显示简单菜单 94 4.6 “请稍候”:向用户显示进度 95 4.7 秘诀:调用基本的文档中未记录的uiprogresshud 95 4.8 秘诀:使用uiactivity- indicatorview 97 4.9 秘诀:构建uiprogressview 98 4.10 秘诀:添加自定义、可轻击的覆盖层 101 4.11 秘诀:构建下滑式警告 104 4.12 秘诀:添加状态栏图像 107 4.13 添加应用程序标记 108 4.14 秘诀:简单的音频警告 110 4.15 小结 112 第5章 基本表格 113 5.1 uitableview和uitableview-controller简介 113 5.1.1 创建表格 113 5.1.2 uitableviewcontroller的作用 115 5.2 秘诀:创建简单的列表表格 115 5.2.1 数据源函数 116 5.2.2 重用单元格 116 5.2.3 字体表格示例 116 5.3 秘诀:创建基于表格的选择表 118 5.4 秘诀:将图像加载到表格单元中 122 5.5 秘诀:设置单元格的文本特性 123 5.6 秘诀:删除单元格选择 124 5.7 秘诀:创建复杂的单元格 125 5.8 秘诀:创建选中的选择 127 5.9 秘诀:删除单元格 128 5.9.1 创建和显示删除控件 130 5.9.2 关闭删除控件 ..131 5.9.3 处理删除请求 131 5.9.4 滑动单元格 131 5.9.5 添加单元格 131 5.10 秘诀:对单元格重新排序 131 5.11 秘诀:使用公开 132 5.12 小结 134 第6章 高级表格 135 6.1 秘诀:对表格选择进行分组 135 6.1.1 构建基于部分的数据源 139 6.1.2 添加部分标题 139 6.2 秘诀:构建带索引的部分表格 140 6.3 秘诀:定制单元格背景 141 6.4 秘诀:创建蓝白交替的单元格 145 6.5 秘诀:设置表格边框 146 6.6 秘诀:添加耦合的单元格控件 148 6.7 秘诀:构建多滚轮表格 150 6.8 秘诀:使用uidatepicker 153 6.9 秘诀:创建完全自定义的分组表格 155 6.10 小结 160 第7章 媒体 161 7.1 秘诀:按照文件类型浏览documents文件夹 161 7.2 加载和查看图像 163 7.3 秘诀:显示小图像 164 7.4 秘诀:使用uiwebveiw显示图像 167 7.5 秘诀:浏览图像库 169 7.6 秘诀:选择和定制相册中的图像 171 7.7 秘诀:使用iphone照相机拍照 174 7.8 处理iphone音频 175 7.9 秘诀:使用celestial播放音频 176 7.10 秘诀:使用媒体播放器实现音频和视频重放 178 7.11 秘诀:录制音频 179 7.12 读入文本数据 187 7.13 从备份文件还原媒体 187 7.14 小结 189 第8章 控件 190 8.1 秘诀:构建简单的按钮 190 8.1.1 uibutton类 191 8.1.2 构建自定义按钮 192 8.1.3 玻璃按钮(glass button) 194 8.2 秘诀:向按钮添加动画元素 194 8.3 秘诀:为按钮响应制作动画效果 196 8.4 秘诀:定制开关 197 8.5 秘诀:添加自定义滑块缩略图 200 8.6 秘诀:关闭uitextfield键盘 204 8.7 秘诀:关闭uitextview键盘 205 8.8 秘诀:向文本视图添加一个撤销(undo)按钮 207 8.9 秘诀:创建一个基于文本视图的html编辑器 209 8.10 秘诀:构建一个交互搜索栏 211 8.11 秘诀:添加标注(callout)视图 213 8.12 添加一个页面指示器控件 216 8.13 秘诀:定制工具栏 218 8.14 小结 221 第9章 人物、地点和事件 223 9.1 地址簿框架 223 9.1.1 address book ui 223 9.1.2 address book 224 9.2 秘诀:访问地址簿图像数据 225 9.3 秘诀:显示地址簿信息 227 9.4 秘诀:浏览地址簿 228 9.4.1 (只)浏览电子邮件地址 230 9.4.2 添加新的联系人 230 9.5 core location 231 9.6 秘诀:core location简介 232 9.7 秘诀:将地理编码转化为地址 235 9.8 秘诀:使用core location数据访问地图 238 9.9 秘诀:访问核心设备信息 240 9.10 秘诀:启用和禁用近程传感器 241 9.11 秘诀:使用加速度将方向定位到“向上” 241 9.12 秘诀:使用加速度移动屏幕上的对象 243 9.13 小结 246 第10章 连接服务 247 10.1 秘诀:添加自定义设置束 247 10.2 秘诀:使应用程序支持自定义url模式 251 10.3 秘诀:检查网络状态 253 10.3.1 测试网络状态 253 10.3.2 恢复本地ip地址 254 10.3.3 查询站点的ip地址 255 10.3.4 检查站点可用性 255 10.4 秘诀:与iphone数据库交互 257 10.5 秘诀:将xml转换为树 259 10.6 秘诀:存储和检索密钥链项 261 10.6.1 存储多个密钥链值 265 10.6.2 密钥链持久化 267 10.7 发送和接收文件 267 10.8 秘诀:构建一个简单的基于web的服务器 268 10.9 即时消息传送 272 10.10 小结 272 第11章 cover flow编程 274 11.1 uicoverflowlayer类 274 11.2 构建cover flow视图 276 11.3 构建cover flow视图控制器 278 11.3.1 cover flow数据源方法 279 11.3.2 cover flow委托方法 279 11.4 小结... 282

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值