[note] 2020-11-10 android shell 查看 .db 文件內(nèi)容

android shell 下查看 sqlite 數(shù)據(jù)庫(kù)

查看Android板子上的數(shù)據(jù)庫(kù)時(shí),常用的辦法

  1. 把 db 文件拉出來(lái),然后用 sqlite 工具查看,AS也有對(duì)應(yīng)的常見(jiàn)查看拉出來(lái)的文件,mac上,我常用的是 DB Browser for SQLite
  2. 使用調(diào)試時(shí),web sqlite,也就是開(kāi)源庫(kù) io.github.skyhacker2:sqliteonweb
  3. 還有就是 root 情況下,使用 shell 中的工具 sqlite3

連接數(shù)據(jù)庫(kù)

在 adb shell 里面使用 sqlite3 工具,指令格式為 sqlite3 xxx.db,完成數(shù)據(jù)庫(kù)連接

rk3399_JH:/sdcard # sqlite3 /data/data/com.xx.xx/databases/UserDatabase.db
SQLite version 3.9.2 2015-11-02 18:31:45
Enter ".help" for usage hints.
sqlite>

常常地,需要訪問(wèn) /data/data/com.xx.xx/databases/xxx.db 都是需要 root 的

查看數(shù)據(jù)庫(kù)信息

連接數(shù)據(jù)庫(kù)后,查看幫助指令

sqlite> .help
.backup ?DB? FILE      Backup DB (default "main") to FILE
.bail on|off           Stop after hitting an error.  Default OFF
.binary on|off         Turn binary output on or off.  Default OFF
.clone NEWDB           Clone data into NEWDB from the existing database
.databases             List names and files of attached databases
.dbinfo ?DB?           Show status information about the database
.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
.eqp on|off            Enable or disable automatic EXPLAIN QUERY PLAN
.exit                  Exit this program
.explain ?on|off?      Turn output mode suitable for EXPLAIN on or off.
                         With no args, it turns EXPLAIN on.
.fullschema            Show schema and the content of sqlite_stat tables
.headers on|off        Turn display of headers on or off
.help                  Show this message
.import FILE TABLE     Import data from FILE into TABLE
.indexes ?TABLE?       Show names of all indexes
                         If TABLE specified, only show indexes for tables
                         matching LIKE pattern TABLE.
.limit ?LIMIT? ?VAL?   Display or change the value of an SQLITE_LIMIT
.log FILE|off          Turn logging on or off.  FILE can be stderr/stdout
.mode MODE ?TABLE?     Set output mode where MODE is one of:
                         ascii    Columns/rows delimited by 0x1F and 0x1E
                         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 strings
                         tabs     Tab-separated values
                         tcl      TCL list elements
.nullvalue STRING      Use STRING in place of NULL values
.once FILENAME         Output for the next SQL command only to FILENAME
.open ?FILENAME?       Close existing database and reopen FILENAME
.output ?FILENAME?     Send output to FILENAME or stdout
.print STRING...       Print literal STRING
.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
.save FILE             Write in-memory database into FILE
.scanstats on|off      Turn sqlite3_stmt_scanstatus() metrics on or off
.schema ?TABLE?        Show the CREATE statements
                         If TABLE specified, only show tables matching
                         LIKE pattern TABLE.
.separator COL ?ROW?   Change the column separator and optionally the row
                         separator for both the output mode and .import
.shell CMD ARGS...     Run CMD ARGS... in a system shell
.show                  Show the current values for various settings
.stats on|off          Turn stats on or off
.system CMD ARGS...    Run CMD ARGS... in a system shell
.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
.timer on|off          Turn SQL timer on or off
.trace FILE|off        Output each SQL statement as it is run
.vfsname ?AUX?         Print the name of the VFS stack
.width NUM1 NUM2 ...   Set column widths for "column" mode
                         Negative values right-justify

可以使用對(duì)應(yīng)的指令,但常用的一般有

查看已連接數(shù)據(jù)庫(kù)

sqlite>.database 
seq  name             file
---  ---------------  ----------------------------------------------------------
0    main             /data/data/com.xx.xx/databases/UserDatabase.

表操作

查看當(dāng)前(或者制定name的數(shù)據(jù)庫(kù))的所有表

sqlite>.tables
User               android_metadata   room_master_table

指定輸出列表內(nèi)容的格式,column 講以列的方式展示

sqlite> .mode column
sqlite>

使用 sqlite 數(shù)據(jù)庫(kù)語(yǔ)句

sqlite> .mode line
select * from User;
   name = KK11161
feature = i3UAgAAAAAAMBAAAAABJQwAAsUMAANdDAADJQwCAr0MAAOBAAICCQwAAyUMAAPhDAAC6QwAAtEIAAAAAAAD4QwAA10MAAIJDAICOQwCAh0MAAOdDAAAxQwAAnEIAAEFDAAAxQwAA+EMAAOJDAACEQgCA2UMAAHhCAAC6QgAAmEIAAPpDAAC0QgCAuEMAAC9DAAB0QwCAvUMAAJhCAICOQwCAvkMAACxCAAD4QwCAr0MAANdDAICPQwAA0kIAAOJDAACnQwCA70MAAIRCAABBQwAALEIAAIRCAAD0QwAA+kMAALxCAADnQwAAeEIAAIJDAAC+QgAAp0MAgL1DAICOQwAA4kMAALBBAADnQwAA50MAACNDAIDGQwAA10MAALpDAACYQgAARUMAAJhCAAB0QwAARUMAACpDAIC/QwAA+kMAANdDAADiQwAA4kMAgLVDAICIQwAA4kMAAJhCAIDbQwAAEEIAAEFDAAA4QwCAvUMAABBCAICPQwAAhEIAgL1DAAB4QgAA4kMAAGBDAADgQACAuUMAgMFDAAAQQgAAdEMAgJpDAACxQwCAoEMAAKdDAAARQwAA6UMAAAAAAACeQgAA50MAgL1DAAB4QgAA+EMAAOdDAIC9QwAAQEEAAKdDAICOQwAA+EEAgNlDAACQQQAAS0MAADpDAAAqQwAAtEIAAKdDAADXQwAAKEIAAJBBAAC+QgCAgkMAANJCAAAvQwAAhEIAAJxCAAAQQgAAKEIAADpDAAAQQgAAvkIAAMlDAAAyQwAAvkIAACNDAACYQgAAKEIAAJhCAICvQwAA10MAAOJDAICPQwAA4EAAgK9DAAB0QwAAhEIAACxCAADSQgAAukMAgI5DAADJQwAAKEIAAKdDAICIQwAA9EMAAJhCAAA4QwAALEIAgNVDAAD0QwCAj0MAADpDAADJQwAA10MAgMFDAACeQgCAmkMAAHRDAAAQQgAAukMAgL5DAICPQwAAJUMAANdDAAB4QgAAQUMAACxCAACgQAAAKkMAAJ5CAACYQgAAukIAAL5CAAAjQwCAoEMAAL5CAACYQgAAJUMAAHhCAACeQgAARUMAACxCAAAQQgAABEIAAEZDAAAyQwAAhEIAAGBDAAC0QgAA+EMAgNlDAIDbQwAAvkIAAPpDAICgQwAAp0MAAMlDAAB4QgAAhEIAgIVDAAAjQwAA50MAAJ5CAICgQwAAhEIAgJpDAAD0QwAAkEEAAL5CAAAsQgCAiEMAAIJDAACEQgAA4EAAANJCAAC+QgAALEIAAHhCAAARQwAA9EMAANdDAICPQwCA70MAACVDAICPQwCAmkMAAKdDAACwQQAAyUMAAIJDAACEQgCAmkMAALFDAABBQwCAvkMAANdDAABBQw==
quality = 9.99787902832031

   name = C00020
feature =
quality = 9.97407150268555

   name = C00021
feature =
quality = 9.97407150268555
sqlite>

退出 sqlite3

退出 sqlite3 的三種方式,.quit, .exit, 3次 ctrl + c

rk3399_JH:/sdcard # sqlite3 /data/data/com.xx.xx/databases/UserDatabase.db
SQLite version 3.9.2 2015-11-02 18:31:45
Enter ".help" for usage hints.
sqlite> .quit
rk3399_JH:/sdcard # sqlite3 /data/data/com.xx.xx/databases/UserDatabase.db
SQLite version 3.9.2 2015-11-02 18:31:45
Enter ".help" for usage hints.
sqlite> .exit
rk3399_JH:/sdcard # sqlite3 /data/data/com.xx.xx/databases/UserDatabase.db
SQLite version 3.9.2 2015-11-02 18:31:45
Enter ".help" for usage hints.
1|rk3399_JH:/sdcard # sqlite3 /data/data/com.xx.xx/databases/UserDatabase.db
SQLite version 3.9.2 2015-11-02 18:31:45
Enter ".help" for usage hints.
sqlite> ^[[C^[[C
   ...> ^C^C^C1|rk3399_JH:/sdcard #
1|rk3399_JH:/sdcard #
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容