sqlite3

您可以使用 sqlite3 指令列程式,透過遠端殼層管理裝置上由 Android 應用程式建立的 SQLite 資料庫,也可以透過主體機器進行管理。sqlite3 工具包含許多實用的指令,例如 .dump 可輸出資料表的內容,.schema 則可輸出現有資料表的 SQL CREATE 陳述式。這項工具還可讓您即時執行 SQLite 指令。

詳情請參閱 SQLite 說明文件。如需其他說明文件,請前往 sqlite3 和 SQLite 支援的 SQL 語言規格

如何透過遠端殼層使用 sqlite3

  1. 輸入下列指令,進入遠端殼層:
    adb [-d|-e|-s {<serialNumber>}] shell
  2. 在遠端殼層中輸入下列指令,啟動 sqlite3 工具:
    sqlite3

    您也可以選擇指定要探索的資料庫完整路徑。模擬器/裝置執行個體會將 SQLite 資料庫儲存在 /data/data/<package_name>/databases/ 目錄中。

  3. 叫用 sqlite3 後,即可在殼層下達指令。如要離開並返回 ADB 遠端殼層,請輸入 exit 或按下 Control + D 鍵。

例如:

$ adb -s emulator-5554 shell
# sqlite3 /data/data/com.example.google.rss.rssexample/databases/rssitems.db
SQLite version 3.3.12
Enter ".help" for instructions
.... enter commands, then quit...
# sqlite> .exit

注意:您必須具備檔案系統的根層級存取權,才能查看 /data/data 目錄階層中的檔案。

如要在裝置本機使用 sqlite3 (而非殼層內),請從裝置提取資料庫檔案,然後啟動 sqlite3

  1. 將裝置上的資料庫檔案複製到主體機器:
    adb pull <database-file-on-device>
    
  2. 啟動 sqlite3 工具,並指定資料庫檔案:
    sqlite3 <database-file-on-host>