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