android sqlite3使用命令

sqlite3可以让我们对机器中的数据库直接进行操作,对于调试机,可以直接通过adb shell进入机器后使用。


开启模拟器,执行adb shell后进入adb 环境就可以用sqlite3这个工具。

[plain]  view plain copy
  1. myron@myron-laptop:~$ adb shell  
  2. # sqlite3  
  3. SQLite version 3.7.4  
  4. Enter ".help" for instructions  
  5. Enter SQL statements terminated with a ";"  

sqlite3的命令分为SQL命令和非SQL命令

其中非SQL命令以"."开头,可以通过".help"来查看,通过".quit"退出sqlite3

[plain]  view plain copy
  1. sqlite> .help  
  2. .backup ?DB? FILE      Backup DB (default "main") to FILE  
  3. .bail ON|OFF           Stop after hitting an error.  Default OFF  
  4. .databases             List names and files of attached databases  
  5. .dump ?TABLE? ...      Dump the database in an SQL text format  
  6.                          If TABLE specified, only dump tables matching  
  7.                          LIKE pattern TABLE.  
  8. .echo ON|OFF           Turn command echo on or off  
  9. .exit                  Exit this program  
  10. .explain ?ON|OFF?      Turn output mode suitable for EXPLAIN on or off.  
  11.                          With no args, it turns EXPLAIN on.  
  12. .header(s) ON|OFF      Turn display of headers on or off  
  13. .help                  Show this message  
  14. .import FILE TABLE     Import data from FILE into TABLE  
  15. .indices ?TABLE?       Show names of all indices  
  16.                          If TABLE specified, only show indices for tables  
  17.                          matching LIKE pattern TABLE.  
  18. .load FILE ?ENTRY?     Load an extension library  
  19. .log FILE|off          Turn logging on or off.  FILE can be stderr/stdout  
  20. .mode MODE ?TABLE?     Set output mode where MODE is one of:  
  21.                          csv      Comma-separated values  
  22.                          column   Left-aligned columns.  (See .width)  
  23.                          html     HTML <table> code  
  24.                          insert   SQL insert statements for TABLE  
  25.                          line     One value per line  
  26.                          list     Values delimited by .separator string  
  27.                          tabs     Tab-separated values  
  28.                          tcl      TCL list elements  
  29. .nullvalue STRING      Print STRING in place of NULL values  
  30. .output FILENAME       Send output to FILENAME  
  31. .output stdout         Send output to the screen  
  32. .prompt MAIN CONTINUE  Replace the standard prompts  
  33. .quit                  Exit this program  
  34. .read FILENAME         Execute SQL in FILENAME  
  35. .restore ?DB? FILE     Restore content of DB (default "main") from FILE  
  36. .schema ?TABLE?        Show the CREATE statements  
  37.                          If TABLE specified, only show tables matching  
  38.                          LIKE pattern TABLE.  
  39. .separator STRING      Change separator used by output mode and .import  
  40. .show                  Show the current values for various settings  
  41. .stats ON|OFF          Turn stats on or off  
  42. .tables ?TABLE?        List names of tables  
  43.                          If TABLE specified, only list tables matching  
  44.                          LIKE pattern TABLE.  
  45. .timeout MS            Try opening locked tables for MS milliseconds  
  46. .width NUM1 NUM2 ...   Set column widths for "column" mode  
  47. .timer ON|OFF          Turn the CPU timer measurement on or off  
  48. sqlite> .quit  
  49. #   

对于不以"."开头的语句sqlite3都当作SQL语句来执行,SQL语句以分号结束,下面目录中有应用自己的数据库

[plain]  view plain copy
  1. # pwd  
  2. /data/data/com.android.providers.settings/databases  
  3. # ls  
  4. settings.db  
  5. settings.db-shm  
  6. settings.db-wal  

sqlite3后接数据库名可以打开已存在的数据库或者新建一个数据库,下面为打开目录中的settings.db

[plain]  view plain copy
  1. # sqlite3 settings.db  
  2. SQLite version 3.7.4  
  3. Enter ".help" for instructions  
  4. Enter SQL statements terminated with a ";"  
  5. sqlite>   


sqlite3提供了多个命令查看数据库的schema,".tables"可以查看当前数据库的所有表

[plain]  view plain copy
  1. sqlite> .tables  
  2. android_metadata   bookmarks          system             
  3. bluetooth_devices  secure   

通过select 语句可以查看表的内容

[plain]  view plain copy
  1. sqlite> select * from secure;  
  2. _id|name|value  
  3. 1|bluetooth_on|0  
  4. 2|data_roaming|0  
  5. 4|location_providers_allowed|gps  
  6. 5|assisted_gps_enabled|1  
  7. 6|network_preference|1  
  8. 7|usb_mass_storage_enabled|1  
  9. 8|wifi_on|0  
  10. 9|wifi_networks_available_notification_on|1  
  11. 10|preferred_network_mode|0  
  12. 11|cdma_cell_broadcast_sms|1  
  13. 12|preferred_cdma_subscription|1  
  14. 13|mock_location|1  
  15. 14|backup_enabled|1  
  16. 15|backup_transport|android/com.android.internal.backup.LocalTransport  
  17. 16|mount_play_not_snd|1  
  18. 17|mount_ums_autostart|0  
  19. 18|mount_ums_prompt|1  
  20. 19|mount_ums_notify_enabled|1  
  21. 20|accessibility_script_injection|0  
  22. 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;  
  23. 22|long_press_timeout|500  
  24. 23|touch_exploration_enabled|0  
  25. 24|android_id|702662e68643232c  
  26. 27|enabled_input_methods|com.android.inputmethod.pinyin/.PinyinIME:jp.co.omronsoft.openwnn/.OpenWnnJAJP:com.android.inputmethod.latin/.LatinIME  
  27. 28|input_methods_subtype_history|  
  28. 29|selected_input_method_subtype|-1  
  29. 30|default_input_method|com.android.inputmethod.latin/.LatinIME  
  30. 31|selected_spell_checker|com.android.inputmethod.latin/.spellcheck.AndroidSpellCheckerService  
  31. 32|selected_spell_checker_subtype|0  
  32. 33|throttle_reset_day|10  
  33. 34|device_provisioned|1  
  34. 35|install_non_market_apps|1  
  35. 36|backup_provisioned|1  
  36. 37|wifi_country_code|us  

如果第一行的header不显示,可以通过如下命令让起显示

[plain]  view plain copy
  1. sqlite> .header on  
  2. sqlite>   
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值