summaryrefslogtreecommitdiff
path: root/copy-mmssms-db.php
diff options
context:
space:
mode:
authorevgenyzinoviev <me@ch1p.com>2016-03-02 02:08:31 +0200
committerevgenyzinoviev <me@ch1p.com>2016-03-02 02:08:31 +0200
commitc788404cc9d08b23d9715396d37a5c2b2d147d7f (patch)
treeeb13d7e9d2123d709206239b4a940fcbe54c35bf /copy-mmssms-db.php
first commitHEADmaster
Diffstat (limited to 'copy-mmssms-db.php')
-rw-r--r--copy-mmssms-db.php69
1 files changed, 69 insertions, 0 deletions
diff --git a/copy-mmssms-db.php b/copy-mmssms-db.php
new file mode 100644
index 0000000..4bfeef8
--- /dev/null
+++ b/copy-mmssms-db.php
@@ -0,0 +1,69 @@
+<?php
+
+// place paths to your files here
+$src_path = '';
+$dst_path = '';
+
+$src = new SQLite3($src_path);
+$dst = new SQLite3($dst_path);
+
+function copy_canonical_addresses() {
+ global $src, $dst;
+ $q = $src->query("SELECT * FROM canonical_addresses");
+ while ($row = $q->fetchArray(SQLITE3_ASSOC)) {
+ $dst->query("INSERT INTO canonical_addresses (_id, address) VALUES (".$row['_id'].", '".SQLite3::escapeString($row['address'])."')");
+ }
+}
+
+function copy_sms() {
+ global $src, $dst;
+ $q = $src->query("SELECT * FROM sms");
+ while ($row = $q->fetchArray(SQLITE3_ASSOC)) {
+ $keys = [];
+ $values = [];
+ foreach ($row as $key => $value) {
+ $keys[] = "`".$key."`";
+ $values[] = "'".SQLite3::escapeString($value)."'";
+ }
+ $dst->query("INSERT INTO sms (".implode(', ', $keys).") VALUES (".implode(', ', $values).")");
+ }
+}
+
+function copy_threads() {
+ global $src, $dst;
+ $q = $src->query("SELECT * FROM threads");
+ while ($row = $q->fetchArray(SQLITE3_ASSOC)) {
+ $keys = [];
+ $values = [];
+ foreach ($row as $key => $value) {
+ if ($key == 'unread_message_count') {
+ continue;
+ }
+ $keys[] = "`".$key."`";
+ $values[] = "'".SQLite3::escapeString($value)."'";
+ }
+ $dst->query("INSERT INTO threads (".implode(', ', $keys).") VALUES (".implode(', ', $values).")");
+ }
+}
+
+function copy_words() {
+ global $src, $dst;
+ $tables = ['words', 'words_content', 'words_segments', 'words_segdir'];
+ foreach ($tables as $table) {
+ $q = $src->query("SELECT * FROM {$table}");
+ while ($row = $q->fetchArray(SQLITE3_ASSOC)) {
+ $keys = [];
+ $values = [];
+ foreach ($row as $key => $value) {
+ $keys[] = "`".$key."`";
+ $values[] = "'".SQLite3::escapeString($value)."'";
+ }
+ $dst->query("INSERT INTO {$table} (".implode(', ', $keys).") VALUES (".implode(', ', $values).")");
+ }
+ }
+}
+
+copy_threads();
+copy_words();
+copy_sms();
+copy_canonical_addresses();