Skip to content

Instantly share code, notes, and snippets.

@aspiers
Last active August 29, 2015 14:11
Show Gist options
  • Save aspiers/3d726f02f9882f1d0657 to your computer and use it in GitHub Desktop.
Save aspiers/3d726f02f9882f1d0657 to your computer and use it in GitHub Desktop.
run SQL on MobileSheetsPro SQLite database
#!/bin/bash
#
# Handy script to allow surgery on MobileSheetsPro SQLite database
# from host computer via adb. This means you can use the full history
# and CLI features of a feature-complete modern shell, rather than
# the crippled crap which Android's "adb shell" gives you.
#
# Example:
#
# MSP-sqlite3.sh 'select * from Songs where Title like "%Foo%"'
#set -x
db=/data/data/com.zubersoft.mobilesheetsprobeta/databases/mobilesheets.db
#old=/storage/emulated/0/Android/data/com.zubersoft.mobilesheetsprobeta/
#new=/storage/emulated/0/Music/MobileSheets/
#sql="select Path from Files where Path like '%zubersoft%';"
#sql="select replace(Path, '$old', '$new') as path from Files;"
#sql="select replace(Path, '$old', '$new') as path from Files where Path like '%zubersoft%';"
#sql="update Files set Path = replace(Path, '$old', '$new') where Path like '%zubersoft%';"
#sql="select Path from Files where Path like '${new}files%';"
#sql="update Files set Path = replace(Path, '${new}files/', '$new') where Path like '${new}files%';"
sql="$*"
# This horrific nested quoting allows us to use single or double quotes in
# our SQL which is passed to the script via CLI arguments.
cmd="sqlite3 -line $db \\\"${sql//\"/\\\\\\\"}\\\""
adb shell su -c "$cmd"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment