diff options
Diffstat (limited to 'qc')
-rwxr-xr-x | qc/qc | 28 | ||||
-rwxr-xr-x | qc/qdb | 100 |
2 files changed, 128 insertions, 0 deletions
@@ -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 "$*" @@ -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 |