How to use script to query sqlite database for Android

Android saved settings in the database file /data/data/com.android.providers.settings/databases/settings.db .

Android uses sqlite3 as a database. We can use adb to manage the database file. I want to know if there is a way to run all of these commands in a perl/python script to automate the entire request process?

 $adb shell $sqlite3 /data/data/com.android.providers.settings/databases/settings.db 

The above command will open the settings database. You will then enter the sqlite3 command prompt.

First check how many tables exist in the database. The results are listed here.

 sqlite> .tables android_metadata bookmarks gservices bluetooth_devices favorites system 

The settings (such as volume_alarm) that I want to get are in the "system" table, the .dump command will list all the elements in the table.

 sqlite> .dump system BEGIN TRANSACTION; CREATE TABLE system (_id INTEGER PRIMARY KEY AUTOINCREMENT,name TEXT UNIQUE ON CONFLICT REPLACE,value TEXT); INSERT INTO "system" VALUES(3,'volume_system','5′); INSERT INTO "system" VALUES(4,'volume_voice','4′); INSERT INTO "system" VALUES(5,'volume_alarm','6′); ..... $ select value from system where name ='volume_alarm'; select value from system where name ='volume_alarm' 6 $.quit; 
+6
source share
2 answers

To request a specific value:

 adb shell sqlite3 /data/data/com.android.providers.settings/databases/settings.db "select value from 'system' where name = 'volume_alarm';" 

Or pull out all the records from the table:

 adb shell sqlite3 /data/data/com.android.providers.settings/databases/settings.db "select name, value from 'system';" 
+12
source

this one works.

adb shell sqlite3 / data / data / com.android.providers.settings / databases / settings.db "\" select a name, value from 'system'; \ ""

0
source

Source: https://habr.com/ru/post/946241/


All Articles