Skip to content

Instantly share code, notes, and snippets.

@laacz
Created August 30, 2011 12:16
Show Gist options
  • Star 19 You must be signed in to star a gist
  • Fork 8 You must be signed in to fork a gist
  • Save laacz/1180765 to your computer and use it in GitHub Desktop.
Save laacz/1180765 to your computer and use it in GitHub Desktop.
SQL query to extract essential info from addressbook in iOS backup
--
-- This is SQL query to extract AddressBook info from respective sqlite3 file from iOS backup.
-- It has been tested only on my own backup, so, if anything is wrong, fork, edit, and stuff.
--
-- # parse-manifest.py from http://stackoverflow.com/questions/3085153/how-to-parse-the-manifest-mbdb-file-in-an-ios-4-0-itunes-backup
--
-- $ python ../parse-manifest.py | grep AddressBook.sqlitedb
-- -rw-r--r-- 000001f5 000001f5 1654784 1312812502 1312812502 1287387943 (31bb7ba8914766d4ba40d6dfb6113c8b614be442)HomeDomain::Library/AddressBook/AddressBook.sqlitedb
--
-- $ sqlite3 31bb7ba8914766d4ba40d6dfb6113c8b614be442
--
select ABPerson.ROWID
, ABPerson.first
, ABPerson.last
, ABPerson.Organization as organization
, ABPerson.Department as department
, ABPerson.Birthday as birthday
, ABPerson.JobTitle as jobtitle
, (select value from ABMultiValue where property = 3 and record_id = ABPerson.ROWID and label = (select ROWID from ABMultiValueLabel where value = '_$!<Work>!$_')) as phone_work
, (select value from ABMultiValue where property = 3 and record_id = ABPerson.ROWID and label = (select ROWID from ABMultiValueLabel where value = '_$!<Mobile>!$_')) as phone_mobile
, (select value from ABMultiValue where property = 3 and record_id = ABPerson.ROWID and label = (select ROWID from ABMultiValueLabel where value = '_$!<Home>!$_')) as phone_home
, (select value from ABMultiValue where property = 4 and record_id = ABPerson.ROWID and label is null) as email
, (select value from ABMultiValueEntry where parent_id in (select ROWID from ABMultiValue where record_id = ABPerson.ROWID) and key = (select ROWID from ABMultiValueEntryKey where lower(value) = 'street')) as address
, (select value from ABMultiValueEntry where parent_id in (select ROWID from ABMultiValue where record_id = ABPerson.ROWID) and key = (select ROWID from ABMultiValueEntryKey where lower(value) = 'city')) as city
from ABPerson
order by ABPerson.ROWID
;
@mappec
Copy link

mappec commented Aug 30, 2013

Excellent !! Merci ...

@DrewWeth
Copy link

Awesome! Thanks!

@deyouwu
Copy link

deyouwu commented Mar 30, 2016

Thanks

@furicle
Copy link

furicle commented May 4, 2016

Thank you very much - saved me a lot time figuring that out :-) Buy yourself a beer!

@eegzapp
Copy link

eegzapp commented Jun 3, 2017

This was excellent.

I used it on an end-to-end post about recovering contacts from an iPhone backup file.
https://discussions.apple.com/message/31823429#message31823429

For some reason I had to get rid of the 'label is null' part for email, but otherwise it worked beautifully.

Thanks!

@johnfoxii
Copy link

And the thanks go on and on - thank you

@radupantiru
Copy link

Thank you. It saved me quite a lot of time.

@minesweeper106
Copy link

You're my hero!

@Tobias4git
Copy link

Thank you very much!

@johnfoxii
Copy link

johnfoxii commented Feb 1, 2023

The Note field possibly having 'CR' and 'LF' imbedded try using:
Replace (Replace(ABPerson.Note, x'0A', ' '),x'0D',' ')as Note

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment