sqlite3可以让我们对机器中的数据库直接进行操作,对于调试机,可以直接通过adb shell进入机器后使用。
开启模拟器,执行adb shell后进入adb 环境就可以用sqlite3这个工具。
myron@myron-laptop:~$ adb shell
# sqlite3
SQLite version 3.7.4
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite3的命令分为SQL命令和非SQL命令
其中非SQL命令以"."开头,可以通过".help"来查看,通过".quit"退出sqlite3
sqlite> .help
.backup ?DB? FILE Backup DB (default "main") to FILE
.bail ON|OFF Stop after hitting an error. Default OFF
.databases List names and files of attached databases
.dump ?TABLE? ... Dump the database in an SQL text format
If TABLE specified, only dump tables matching
LIKE pattern TABLE.
.echo ON|OFF Turn command echo on or off
.exit Exit this program
.explain ?ON|OFF? Turn output mode suitable for EXPLAIN on or off.
With no args, it turns EXPLAIN on.
.header(s) ON|OFF Turn display of headers on or off
.help Show this message
.import FILE TABLE Import data from FILE into TABLE
.indices ?TABLE? Show names of all indices
If TABLE specified, only show indices for tables
matching LIKE pattern TABLE.
.load FILE ?ENTRY? Load an extension library
.log FILE|off Turn logging on or off. FILE can be stderr/stdout
.mode MODE ?TABLE? Set output mode where MODE is one of:
csv Comma-separated values
column Left-aligned columns. (See .width)
html HTML <table> code
insert SQL insert statements for TABLE
line One value per line
list Values delimited by .separator string
tabs Tab-separated values
tcl TCL list elements
.nullvalue STRING Print STRING in place of NULL values
.output FILENAME Send output to FILENAME
.output stdout Send output to the screen
.prompt MAIN CONTINUE Replace the standard prompts
.quit Exit this program
.read FILENAME Execute SQL in FILENAME
.restore ?DB? FILE Restore content of DB (default "main") from FILE
.schema ?TABLE? Show the CREATE statements
If TABLE specified, only show tables matching
LIKE pattern TABLE.
.separator STRING Change separator used by output mode and .import
.show Show the current values for various settings
.stats ON|OFF Turn stats on or off
.tables ?TABLE? List names of tables
If TABLE specified, only list tables matching
LIKE pattern TABLE.
.timeout MS Try opening locked tables for MS milliseconds
.width NUM1 NUM2 ... Set column widths for "column" mode
.timer ON|OFF Turn the CPU timer measurement on or off
sqlite> .quit
#
对于不以"."开头的语句sqlite3都当作SQL语句来执行,SQL语句以分号结束,下面目录中有应用自己的数据库
# pwd
/data/data/com.android.providers.settings/databases
# ls
settings.db
settings.db-shm
settings.db-wal
sqlite3后接数据库名可以打开已存在的数据库或者新建一个数据库,下面为打开目录中的settings.db
# sqlite3 settings.db
SQLite version 3.7.4
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite>
sqlite> .tables
android_metadata bookmarks system
bluetooth_devices secure
通过select 语句可以查看表的内容
sqlite> select * from secure;
_id|name|value
1|bluetooth_on|0
2|data_roaming|0
4|location_providers_allowed|gps
5|assisted_gps_enabled|1
6|network_preference|1
7|usb_mass_storage_enabled|1
8|wifi_on|0
9|wifi_networks_available_notification_on|1
10|preferred_network_mode|0
11|cdma_cell_broadcast_sms|1
12|preferred_cdma_subscription|1
13|mock_location|1
14|backup_enabled|1
15|backup_transport|android/com.android.internal.backup.LocalTransport
16|mount_play_not_snd|1
17|mount_ums_autostart|0
18|mount_ums_prompt|1
19|mount_ums_notify_enabled|1
20|accessibility_script_injection|0
21|accessibility_web_content_key_bindings|0x13=0x01000100; 0x14=0x01010100; 0x15=0x02000001; 0x16=0x02010001; 0x200000013=0x02000601; 0x200000014=0x02010601; 0x200000015=0x03020101; 0x200000016=0x03010201; 0x200000023=0x02000301; 0x200000024=0x02010301; 0x200000037=0x03070201; 0x200000038=0x03000701:0x03010701:0x03020701;
22|long_press_timeout|500
23|touch_exploration_enabled|0
24|android_id|702662e68643232c
27|enabled_input_methods|com.android.inputmethod.pinyin/.PinyinIME:jp.co.omronsoft.openwnn/.OpenWnnJAJP:com.android.inputmethod.latin/.LatinIME
28|input_methods_subtype_history|
29|selected_input_method_subtype|-1
30|default_input_method|com.android.inputmethod.latin/.LatinIME
31|selected_spell_checker|com.android.inputmethod.latin/.spellcheck.AndroidSpellCheckerService
32|selected_spell_checker_subtype|0
33|throttle_reset_day|10
34|device_provisioned|1
35|install_non_market_apps|1
36|backup_provisioned|1
37|wifi_country_code|us
如果第一行的header不显示,可以通过如下命令让其显示
sqlite> .header on
sqlite>