aboutsummaryrefslogtreecommitdiff
path: root/qc
diff options
context:
space:
mode:
Diffstat (limited to 'qc')
-rwxr-xr-xqc/qc28
-rwxr-xr-xqc/qdb100
2 files changed, 128 insertions, 0 deletions
diff --git a/qc/qc b/qc/qc
new file mode 100755
index 00000000..876ee762
--- /dev/null
+++ b/qc/qc
@@ -0,0 +1,28 @@
+#!/bin/bash
+
+set -e
+
+user_path=data
+file=contacts2.db
+pass=""
+
+adb root && adb wait-for-device
+
+while getopts "theqvpu:" opt; do
+ case "$opt" in
+ t|h|e|q|v)
+ pass="$pass -$opt"
+ ;;
+ p) # Open profile DB instead.
+ file=profile.db
+ ;;
+ u) # Open for a secondary user
+ user_path="user/$OPTARG"
+ ;;
+ *)
+ exit 1
+ esac
+done
+shift $(($OPTIND - 1))
+
+$(dirname "$0")/qdb $pass /data/$user_path/com.android.providers.contacts/databases/$file "$*"
diff --git a/qc/qdb b/qc/qdb
new file mode 100755
index 00000000..4277bafe
--- /dev/null
+++ b/qc/qdb
@@ -0,0 +1,100 @@
+#!/bin/bash
+
+set -e
+
+html=0
+output=""
+prefix=""
+time=""
+local=0
+
+verbose=0
+
+filter="cat"
+pager="${QDB_PAGER:-${PAGER:-cat}}"
+
+# Table output mode by default
+sep="〠"
+output="-list -separator $sep"
+filter="column -t -s $sep"
+
+while getopts "lcheqtv" opt; do
+ case "$opt" in
+ l)
+ local=1
+ ;;
+ h)
+ html=1
+ output="-html"
+ filter="cat"
+ pager="${HTML_VIEWER:-$pager}"
+ ;;
+ e)
+ prefix="EXPLAIN "
+ ;;
+ q)
+ prefix="EXPLAIN QUERY PLAN "
+ ;;
+ t) # Run with the time command.
+ time="time"
+ ;;
+ v)
+ verbose=1
+ ;;
+ *)
+ exit 1
+ esac
+done
+shift $(($OPTIND - 1))
+
+db="$1"
+shift
+
+if ! [[ -t 1 ]] ; then
+ pager="cat"
+fi
+
+if (( $verbose )) ; then
+ echo "DB: $db" 1>&2
+fi
+
+query="$*"
+
+run_query() {
+ if (( $local )) ; then
+ test -f "$db" && $time sqlite3 $output -nullvalue "[NULL]" -header "$db" "$prefix$query"
+ else
+ query=$(sed -e "s!'!\'\\\'\'!g" <<<"$query") # Escape for shell
+ adb shell -T "(" test -f "$db" "&&" $time sqlite3 $output -nullvalue "[NULL]" -header "$db" \'"$prefix$query"\' ")" "2>&1"
+ fi
+}
+
+{
+ if (( $html )) ; then
+ cat <<EOF
+<head>
+<style>
+body {
+ font:8pt monospace;
+}
+
+table {
+ border: 1px solid black;
+ border-collapse: collapse;
+}
+</style>
+</head>
+<body>
+<table border="1">
+EOF
+
+ run_query
+
+ cat <<EOF
+</table>
+<body>
+EOF
+ else
+ run_query
+ fi
+} | $filter | $pager