一、Android開發(fā)怎么查看和管理sqlite數(shù)據(jù)庫
原始查看sqlite數(shù)據(jù)方法
Android Studio中菜單 — Tools — Android — Android Device Moniter然后進(jìn)入DDMS視圖。在File Explorer View里面依次展開路徑data/data/package_name/databases/,然后將里面的db文件pull from device保存到電腦上面,再用navicat、SQLiteSpy等其他軟件打開查看。而且數(shù)據(jù)變動之后又需要重新操作一次。有一定局限性。
實時查看sqlite數(shù)據(jù)
程序員果然還是喜歡用命令行O(∩_∩)O哈哈~只需要啪啪啪打一些命令行就完成操作了
其實查看手機(jī)中的數(shù)據(jù)庫文件很簡單。
adb shell sqlite3 /data/data/package_name/databases/hahahaha.db
此句表示進(jìn)入shell模式,然后執(zhí)行某個APP中的數(shù)據(jù)庫文件hahahaha.db。
如果你不太清楚這個 databases 文件中有哪些文件你可以先 cd 進(jìn)入此文件夾中用 ls 命令看一下有什么數(shù)據(jù)庫文件,然后再使用剛剛的命令打開。
cd /data/data/package_name/databases
ls
進(jìn)入數(shù)據(jù)庫之后使用的常用命令
在此已經(jīng)進(jìn)入數(shù)據(jù)庫了。然后你就可以使用一些sqlite3的命令來操作了。
.tables //顯示所有表
.schema //顯示數(shù)據(jù)庫的schema
.schema table_name //顯示表的schema
.headers on //顯示標(biāo)題欄,即字段名欄,如在查看數(shù)據(jù)中數(shù)據(jù)時,默認(rèn)select * from table_name 不顯示字段名。
alter table //修改表。改變表名 – ALTER TABLE 舊表名 RENAME TO 新表名;增加一列 – ALTER TABLE 表名 ADD COLUMN 列名 數(shù)據(jù)類型 限定符
select * from sqlite_master where type=”table”; //顯示所有表的結(jié)構(gòu)
select * from sqlite_master where type=”table” and name=”table_name”; //顯示某個表的結(jié)構(gòu)
drop table table_name //刪除表
.quit //退出
.read FileName //執(zhí)行FileName中的sql
同樣的你也可以使用標(biāo)準(zhǔn)的SQL語句,牢記使用分號結(jié)束~
select語句;
delete語句;
update語句;
insert語句。