Skip to content

Instantly share code, notes, and snippets.

@EspadaV8
Created November 20, 2012 10:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EspadaV8/4117116 to your computer and use it in GitHub Desktop.
Save EspadaV8/4117116 to your computer and use it in GitHub Desktop.
iOS6 SQLite to CSV
SELECT [0],
h.id,
m.date + 978307020000,
CASE m.is_from_me
WHEN 0 THEN 1
WHEN 1 THEN 2
END AS type,
NULL,
m.text,
NULL,
NULL,
m.service_center,
1,
-1
FROM message m,
handle h
WHERE h.rowid = m.handle_id;
<?php
$count = 0;
$messages = "";
if (($handle = fopen('sms.csv', 'r')) !== false) {
while(($data = fgetcsv($handle)) !== false) {
$count++;
$messages .= '<sms protocol="' . $data[0] . '" ' .
'address="' . $data[1] . '" '.
'date="' . $data[2] . '" '.
'type="' . $data[3] . '" '.
'subject="null" ' . // $data[4] . '" '.
'body="' . $data[5] . '" '.
'toa="null" ' . // $data[6] . '" '.
'sc_toa="null" ' . // $data[7] . '" '.
'service_center="' . $data[8] . '" '.
'read="' . $data[9] . '" '.
'status="' . $data[10] . '" '.
' />' . PHP_EOL;
}
}
$output = "<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>" . PHP_EOL;
$output .= '<smses count="' . $count . '">' . PHP_EOL;
$output .= $messages;
$output .= "</smses>" . PHP_EOL;
file_put_contents('sms.xml', $output);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment