-
Notifications
You must be signed in to change notification settings - Fork 1
/
sqlite3.sh
89 lines (73 loc) · 2.31 KB
/
sqlite3.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# sudo apt-get install rlwrap to have a more fully featured sqlite CLI
set -x
function sqlite3-pull () {
adb root
if [ -z "$1" ]
then
dir=$(pwd)
else
dir=$1
fi
package=$(get-package)
rm $dir/external.db
rm $dir/external.db-wal
adb pull /data/user/0/$package/databases/external.db $dir/external.db
adb pull /data/user/0/$package/databases/external.db-wal "$dir/external.db-wal"
sqlite3 $dir/external.db "drop trigger files_insert"
sqlite3 $dir/external.db "drop trigger files_update"
sqlite3 $dir/external.db "drop trigger files_delete"
rlwrap sqlite3 $dir/external.db
}
function sqlite3-push () {
adb root
if [ -z "$1" ]
then
dir=$(pwd)
else
dir=$1
fi
package=$(get-package)
adb push $dir/external.db /data/user/0/$package/databases/external.db
adb push $dir/external.db-wal /data/user/0/$package/databases/external.db-wal
sqlite3-trigger-upgrade
}
function sqlite3-trigger-upgrade () {
package=$(get-package)
# Doesn't actually upgrade the db because db version is hardcoded in code
# It however triggers upgrade path
check_string="/data/user/0/$package/databases/external.db \"pragma user_version\""
version=$(adb shell sqlite3 $check_string)
echo "Old version: $version"
version=$((version+1))
upgrade_string="/data/user/0/$package/databases/external.db \"pragma user_version=$version\""
adb shell sqlite3 $upgrade_string
version=$(adb shell sqlite3 $check_string)
echo "New version: $version"
adb shell am force-stop $package
}
function get-id-from-data () {
adb root
path="$1"
package=$(get-package)
dir="/data/user/0/$package/databases/external.db"
clause="\"select _id from files where _data='$path';\""
echo $clause
adb shell sqlite3 $dir $clause
}
function get-data-from-id () {
adb root
_id="$1"
package=$(get-package)
dir="/data/user/0/$package/databases/external.db"
clause="\"select _data from files where _id='$_id';\""
echo $clause
adb shell sqlite3 $dir $clause
}
function get-package() {
if [ -z "$(adb shell pm list package com.android.providers.media.module)" ]
then
echo "com.google.android.providers.media.module"
else
echo "com.android.providers.media.module"
fi
}