android sqlite3使用命令

來源:互聯網
上載者:User

sqlite3可以讓我們對機器中的資料庫直接進行操作,對於調試機,可以直接通過adb shell進入機器後使用。

開啟模擬器,執行adb shell後進入adb 環境就可以用sqlite3這個工具。

myron@myron-laptop:~$ adb shell# sqlite3SQLite version 3.7.4Enter ".help" for instructionsEnter 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 offsqlite> .quit# 

對於不以"."開頭的語句sqlite3都當作SQL語句來執行,SQL語句以分號結束,下面目錄中有應用自己的資料庫

# pwd/data/data/com.android.providers.settings/databases# lssettings.dbsettings.db-shmsettings.db-wal

sqlite3後接資料庫名可以開啟已存在的資料庫或者建立一個資料庫,下面為開啟目錄中的settings.db

# sqlite3 settings.dbSQLite version 3.7.4Enter ".help" for instructionsEnter SQL statements terminated with a ";"sqlite> 

sqlite3提供了多個命令查看資料庫的schema,".tables"可以查看當前資料庫的所有表

sqlite> .tablesandroid_metadata   bookmarks          system           bluetooth_devices  secure 

通過select 語句可以查看錶的內容

sqlite> select * from secure;_id|name|value1|bluetooth_on|02|data_roaming|04|location_providers_allowed|gps5|assisted_gps_enabled|16|network_preference|17|usb_mass_storage_enabled|18|wifi_on|09|wifi_networks_available_notification_on|110|preferred_network_mode|011|cdma_cell_broadcast_sms|112|preferred_cdma_subscription|113|mock_location|114|backup_enabled|115|backup_transport|android/com.android.internal.backup.LocalTransport16|mount_play_not_snd|117|mount_ums_autostart|018|mount_ums_prompt|119|mount_ums_notify_enabled|120|accessibility_script_injection|021|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|50023|touch_exploration_enabled|024|android_id|702662e68643232c27|enabled_input_methods|com.android.inputmethod.pinyin/.PinyinIME:jp.co.omronsoft.openwnn/.OpenWnnJAJP:com.android.inputmethod.latin/.LatinIME28|input_methods_subtype_history|29|selected_input_method_subtype|-130|default_input_method|com.android.inputmethod.latin/.LatinIME31|selected_spell_checker|com.android.inputmethod.latin/.spellcheck.AndroidSpellCheckerService32|selected_spell_checker_subtype|033|throttle_reset_day|1034|device_provisioned|135|install_non_market_apps|136|backup_provisioned|137|wifi_country_code|us

如果第一行的header不顯示,可以通過如下命令讓起顯示

sqlite> .header onsqlite> 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.